diff --git a/dot_Brewfile b/dot_Brewfile index 5cce78c..5eac900 100644 --- a/dot_Brewfile +++ b/dot_Brewfile @@ -14,6 +14,7 @@ brew "bat" brew "berkeley-db" brew "betterleaks" brew "bottom" +brew "carapace" brew "chezmoi" brew "clang-format" brew "cloc" diff --git a/dot_zsh/custom.zsh b/dot_zsh/custom.zsh index 5ea3995..8fa5679 100644 --- a/dot_zsh/custom.zsh +++ b/dot_zsh/custom.zsh @@ -61,69 +61,8 @@ setopt transient_rprompt # # compinit は dot_zshrc で sheldon 読み込み前に実行済み zstyle ':completion:*:default' menu select=1 -# npm completion - -###-begin-npm-completion-### -# shellcheck disable=SC2207,SC2046,SC2034,SC2162,SC2219 -# -# npm command completion script -# -# Installation: npm completion >> ~/.bashrc (or ~/.zshrc) -# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm -# - -if type complete &>/dev/null; then - _npm_completion() { - local words cword - if type _get_comp_words_by_ref &>/dev/null; then - _get_comp_words_by_ref -n = -n @ -n : -w words -i cword - else - cword="$COMP_CWORD" - words=("${COMP_WORDS[@]}") - fi - - local si="$IFS" - IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \ - COMP_LINE="$COMP_LINE" \ - COMP_POINT="$COMP_POINT" \ - npm completion -- "${words[@]}" \ - 2>/dev/null)) || return $? - IFS="$si" - if type __ltrim_colon_completions &>/dev/null; then - __ltrim_colon_completions "${words[cword]}" - fi - } - complete -o default -F _npm_completion npm -elif type compdef &>/dev/null; then - _npm_completion() { - local si=$IFS - compadd -- $(COMP_CWORD=$((CURRENT - 1)) \ - COMP_LINE=$BUFFER \ - COMP_POINT=0 \ - npm completion -- "${words[@]}" \ - 2>/dev/null) - IFS=$si - } - compdef _npm_completion npm -elif type compctl &>/dev/null; then - _npm_completion() { - local cword line point words si - read -Ac words - read -cn cword - let cword-=1 - read -l line - read -ln point - si="$IFS" - IFS=$'\n' reply=($(COMP_CWORD="$cword" \ - COMP_LINE="$line" \ - COMP_POINT="$point" \ - npm completion -- "${words[@]}" \ - 2>/dev/null)) || return $? - IFS="$si" - } - compctl -K _npm_completion npm -fi -###-end-npm-completion-### +# npm / yarn / pnpm の補完は carapace が担当する +# (sheldon の plugins.carapace で読み込み。旧 `npm completion` 生成コードは削除済み) # AWS CLI # shellcheck disable=SC1091 diff --git a/dot_zshrc b/dot_zshrc index 989130b..6f9ef27 100644 --- a/dot_zshrc +++ b/dot_zshrc @@ -5,7 +5,7 @@ promptinit typeset -U fpath # compinit を sheldon 読み込み前に走らせる -# (zsh-better-npm-completion 等が source 中に compdef を呼ぶため) +# (carapace / gibo-completion 等が source 中に compdef を呼ぶため) # .zcompdump が24時間以内に更新されていればセキュリティ監査(compaudit)をスキップして高速化 autoload -Uz compinit zcompdump="${ZDOTDIR:-$HOME}/.zcompdump" diff --git a/private_dot_config/sheldon/plugins.toml b/private_dot_config/sheldon/plugins.toml index 1d8f8bc..634e291 100644 --- a/private_dot_config/sheldon/plugins.toml +++ b/private_dot_config/sheldon/plugins.toml @@ -18,15 +18,23 @@ github = "zsh-users/zsh-autosuggestions" [plugins.zsh-history-substring-search] github = "zsh-users/zsh-history-substring-search" -[plugins.zsh-better-npm-completion] -github = "lukechilds/zsh-better-npm-completion" - [plugins.zsh-ssh] github = "zpm-zsh/ssh" [plugins.git-open] github = "paulirish/git-open" +# carapace はマルチシェル対応の補完エンジン(約1000コマンドの spec を内蔵) +# 他の補完プラグインより後に読み込み、compdef を上書きさせる +# 特定コマンドを zsh 標準の補完に戻したい場合は CARAPACE_EXCLUDES='git,npm' のように指定する +[plugins.carapace] +inline = ''' +if command -v carapace &>/dev/null; then + zstyle ':completion:*' format $'\e[2;37mCompleting %d\e[m' + source <(carapace _carapace) +fi +''' + # zsh-syntax-highlighting は最後に読み込む # (他プラグインで定義された関数・コマンドもハイライト対象にするため) [plugins.zsh-syntax-highlighting]