From d9e3cb0d8e6dd317eb52e15b593e97d016f14976 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 30 Mar 2023 09:47:34 +0200 Subject: [PATCH] ssh completions --- .config/zsh/.zshrc | 3 ++- .config/zsh/completions/ssh | 34 ++++++++++++++++++++++++++++++++++ TODO | 3 +-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 .config/zsh/completions/ssh diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 42a72d1a..44302dfc 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,3 +1,4 @@ +# vim:set ft=zsh source $ZDOTDIR/configs/vars source $ZDOTDIR/configs/setup source $ZDOTDIR/configs/widgets @@ -16,4 +17,4 @@ source $ZDOTDIR/plugins/fzf/bindings.zsh source $ZDOTDIR/plugins/autopyenv/autopyenv.zsh source $ZDOTDIR/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh -source $ZDOTDIR/completions/zsh-ssh/zsh-ssh.zsh +source $ZDOTDIR/completions/ssh diff --git a/.config/zsh/completions/ssh b/.config/zsh/completions/ssh new file mode 100644 index 00000000..77b8370e --- /dev/null +++ b/.config/zsh/completions/ssh @@ -0,0 +1,34 @@ +# vim:set ft=zsh + +ZSH_CACHE_DIR="${ZSH_CACHE_DIR:-${TMPDIR:-/tmp}/zsh-${UID:-user}}" +CACHE_FILE="${ZSH_CACHE_DIR}/ssh-hosts.zsh" + +hosts=() +if [[ -f ~/.ssh/config ]]; then + if [[ "$CACHE_FILE" -nt "$HOME/.ssh/config" ]]; then + source "$CACHE_FILE" + else + mkdir -p "${CACHE_FILE:h}" + hosts=( $(grep '^Host ' ~/.ssh/config | awk '{first = $1; $1 = ""; print $0; }' | xargs) ) + typeset -p hosts >! "$CACHE_FILE" 2> /dev/null + zcompile "$CACHE_FILE" + fi +fi + +zstyle ':completion:*:hosts' hosts $hosts + +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*' sort false +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*' format ' %F{yellow}-- %d --%f' + +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*' group-name '' +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*' verbose yes + +zstyle ':completion:*:(scp|rsync|sshfs):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:(scp|rsync|sshfs):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr + +zstyle ':completion:*:(ssh|mosh):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:(ssh|mosh):*' group-order users hosts-domain hosts-host users hosts-ipaddr + +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*:hosts-host' ignored-patterns '*(.|:)*' loopback localhost broadcasthost 'ip6-*' +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' +zstyle ':completion:*:(ssh|scp|sshfs|mosh):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.*' '255.255.255.255' '::1' 'fe80::*' 'ff02::*' diff --git a/TODO b/TODO index 8fbe4ffc..190083e4 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,7 @@ -- TODO -- Create a better bitwarden integration -Validate directory structure: https://wiki.archlinux.org/title/XDG_Base_Directory https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard Generate .ssh/config frome netbox using a playbook +Remove username from ssh completion -- FIX -- sb-playerctl trailing dash when no artist -