-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathssh.plugin.zsh
55 lines (42 loc) · 1.73 KB
/
ssh.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env 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/config1" ]]; then
source "$CACHE_FILE"
else
mkdir -p "${CACHE_FILE:h}"
hosts=( $(grep '^Host ' ~/.ssh/config | grep -v 'Ignore' | awk '{first = $1; $1 = ""; print $0; }' | tr " " "\n" | grep -v '*' | sort -u | uniq | xargs ) )
# pre_hosts=()
# post_hosts=()
# for host in $raw_hosts; do
# if [[ "$host" == '*' ]]; then
# continue
# elif [[ "$host" == '*'* ]]; then
# post_hosts+=( "${host#?}" )
# elif [[ "$host" == *'*' ]]; then
# pre_hosts+=( "${host%?}" )
# hosts+=( "${host%?}" )
# else
# hosts+=( "${host}" )
# fi
# done
# for pre in $pre_hosts; do
# for post in $post_hosts; do
# hosts+=( "${pre}${post}" )
# done
# done
# ignore=( $(grep '^#Ignore' ~/.ssh/config | awk '{first = $1; $1 = ""; print $0; }' | tr " " "\n" | grep -v '*' | sort -u | uniq | xargs ) )
# hosts=("${(@)hosts:|ignore}")
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|rsync|sshfs|mosh):*' group-name ''
zstyle ':completion:*:(ssh|scp|rsync|sshfs|mosh):*' verbose yes
zstyle ':completion:*:(ssh|mosh):*' group-order users hosts-host users
zstyle ':completion:*:(scp|rsync|sshfs):*' group-order files all-files hosts-domain hosts-host hosts-ipaddr users