feat(hook): write marked profile blocks and register zsh completion
`netssh hook install` and the setup wizard now write the same marked `# >>> netssh >>>` block as install.sh and replace unmarked entries of older versions instead of appending duplicates. Uninstall shares the legacy patterns with the installer (eval/alias/source variants). For zsh the block adds ~/.zfunc to fpath and calls compdef, so completion also works when compinit already ran earlier in .zshrc, e.g. with oh-my-zsh. The installer reports which completion it set up per shell and how to reset ~/.zcompdump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8fb7633783
commit
129a7201bc
6 files changed
+221
-55
No files matched your search
+21
-1
@@ -168,6 +168,11 @@ plan_profile() {
|
||||
printf '%s shell-init\n' "$(quote_sh "$INSTALL_DIR/$BINARY")"
|
||||
printf '[ ! -f %s ] || . %s\n' "$(quote_sh "$CACHE_DIR/netssh/aliases.sh")" "$(quote_sh "$CACHE_DIR/netssh/aliases.sh")"
|
||||
fi
|
||||
if [[ "$kind" == zsh ]]; then
|
||||
# Register completion also when compinit already ran (e.g. oh-my-zsh).
|
||||
printf 'fpath=(%s $fpath)\n' "$(quote_sh "$HOME/.zfunc")"
|
||||
printf 'if (( $+functions[compdef] )); then autoload -Uz _netssh && compdef _netssh netssh; fi\n'
|
||||
fi
|
||||
printf '# <<< netssh <<<\n'
|
||||
} >> "$data"
|
||||
fi
|
||||
@@ -231,10 +236,25 @@ for ((index=0; index<${#PROFILE_PATHS[@]}; index++)); do
|
||||
mv -f "$staged" "$target"
|
||||
info "updated : ${PROFILE_PATHS[$index]}"
|
||||
done
|
||||
COMPLETIONS=()
|
||||
for kind in "${SHELLS[@]}"; do
|
||||
if ! "$INSTALL_DIR/$BINARY" completion install --shell "$kind"; then
|
||||
if "$INSTALL_DIR/$BINARY" completion install --shell "$kind" >/dev/null; then
|
||||
COMPLETIONS+=("$kind")
|
||||
else
|
||||
info "warning: could not update $kind completion"
|
||||
fi
|
||||
done
|
||||
printf '\nnetssh %s installed / updated at %s/%s\n' "$TAG" "$INSTALL_DIR" "$BINARY"
|
||||
for kind in "${COMPLETIONS[@]}"; do
|
||||
case "$kind" in
|
||||
bash) info "completion: bash -> $HOME/.local/share/bash-completion/completions/netssh" ;;
|
||||
zsh) info "completion: zsh -> $HOME/.zfunc/_netssh (registered in ${ZSH_DIR}/.zshrc)" ;;
|
||||
fish) info "completion: fish -> $CONFIG_DIR/fish/completions/netssh.fish" ;;
|
||||
esac
|
||||
done
|
||||
info "Open a new terminal to load the current hooks and aliases."
|
||||
for kind in "${COMPLETIONS[@]}"; do
|
||||
if [[ "$kind" == zsh ]]; then
|
||||
info "zsh: if <Tab> still shows files, run: rm -f $(quote_sh "$ZSH_DIR")/.zcompdump* && exec zsh"
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user