1
0
Fork 0

ssh completions

This commit is contained in:
Luca Bilke 2023-03-30 09:47:34 +02:00
parent 6f9b31d253
commit d9e3cb0d8e
3 changed files with 37 additions and 3 deletions

View File

@ -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

View File

@ -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::*'

3
TODO
View File

@ -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