This commit is contained in:
darkclip 2026-01-18 11:34:20 +08:00
parent 2005155244
commit d0eb1a042e
Signed by: hl
GPG Key ID: A948B2AA5A5D3BDB

View File

@ -53,7 +53,7 @@ compinit
autoload -Uz promptinit
promptinit
compdef pyssh=ssh
compdef exssh=ssh
export FZF_COMPLETION_TRIGGER="''"
export FZF_COMPLETION_DIR_COMMANDS='cd pushd rmdir ls ll'
@ -72,32 +72,36 @@ __fzf_compgen_file(){
fdfind --type f --hidden . "$1"
}
# For **<TAB>
# For ''<TAB> (**<TAB>)
_fzf_comprun() {
local command=$1
shift
case "$command" in
ssh|mosh|pyssh) fzf --preview 'ssh -tt -G {} | head -n 4' "$@" ;;
cd|ls|ll) fzf --preview 'tree -C -L1 {} | head -200' "$@" ;;
cat|nano) fzf --preview 'cat -s {} | head -200' "$@" ;;
*) fzf "$@" ;;
ssh|mosh|exssh) fzf --preview 'ssh -tt -G {} | head -n 4' "$@" ;;
cd|ls|ll) fzf --preview 'tree -C -L1 {} | head -200' "$@" ;;
cat|nano|micro|vi|vim|nvim) fzf --preview 'cat -s {} | head -200' "$@" ;;
*) fzf "$@" ;;
esac
}
_fzf_complete_pyssh() {
_fzf_complete_exssh() {
_fzf_complete +m -- "$@" < <(
setopt localoptions nonomatch
command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* 2> /dev/null | command grep -i '^\s*host ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') |
awk '{if (length($2) > 0) {print $2}}' | sort -u
)
}
alias _fzf_complete_mosh=_fzf_complete_pyssh
alias _fzf_complete_ssh=_fzf_complete_pyssh
alias _fzf_complete_mosh=_fzf_complete_exssh
alias _fzf_complete_ssh=_fzf_complete_exssh
_fzf_complete_cat(){
__fzf_generic_path_completion "$prefix" "$1" __fzf_compgen_file \
"-m" "" " "
}
alias _fzf_complete_nano=_fzf_complete_cat
alias _fzf_complete_micro=_fzf_complete_cat
alias _fzf_complete_vi=_fzf_complete_cat
alias _fzf_complete_vim=_fzf_complete_cat
alias _fzf_complete_nvim=_fzf_complete_cat
source /usr/share/doc/fzf/examples/completion.zsh
source /usr/share/doc/fzf/examples/key-bindings.zsh