Mercurial > hg > zsh-env
annotate completion/_ssh-add @ 99:a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 18 Oct 2016 04:25:48 +0200 |
parents | |
children |
rev | line source |
---|---|
99
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 #compdef ssh-add |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 _ssh-add() { |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
4 local -a keys |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 for key in $HOME/.ssh/*; do |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 # only accept files that do not end in .pub |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 if [[ ${key#*.pub} == "$key" ]]; then |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 # exclude files that are not ssh keys |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 if [[ ${key#*/config} == "$key" && ${key#*/known_hosts} == "$key" ]]; then |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 keys+=($key) |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 fi |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 fi |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 done |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 compadd "$@" $keys |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 } |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 |
a081e7a3977d
Add support for custom completions to zshrc. Add a completion function to match all ssh keys in ~/.ssh when using ssh-add.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 _ssh-add "$@" |