diff options
author | dana <dana@dana.is> | 2018-01-05 14:26:17 -0600 |
---|---|---|
committer | Oliver Kiddle <opk@zsh.org> | 2018-01-06 00:13:51 +0100 |
commit | 0f0b602415961aa9ca069c9719a0fbb4bbb9941f (patch) | |
tree | 03001cfaf7ed12c26a354a996f52c4920d08cb76 /Completion/Darwin/Command/_scselect | |
parent | 0c5f851021b3aacea96d9ca446282b8dab9f260d (diff) | |
download | zsh-0f0b602415961aa9ca069c9719a0fbb4bbb9941f.tar.gz zsh-0f0b602415961aa9ca069c9719a0fbb4bbb9941f.tar.xz zsh-0f0b602415961aa9ca069c9719a0fbb4bbb9941f.zip |
42231: new completion functions for simple utilities belonging to the 'Darwin' and 'Linux' groups.
Diffstat (limited to 'Completion/Darwin/Command/_scselect')
-rw-r--r-- | Completion/Darwin/Command/_scselect | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Completion/Darwin/Command/_scselect b/Completion/Darwin/Command/_scselect new file mode 100644 index 000000000..79df2f981 --- /dev/null +++ b/Completion/Darwin/Command/_scselect @@ -0,0 +1,39 @@ +#compdef scselect + +local ret=1 u l +local -a context line state state_descr tmp loc1 loc2 +local -A opt_args + +_arguments -s -S : \ + '-n[delay changing until next boot]' \ + '1: :->locations' \ +&& ret=0 + +[[ $state == locations ]] && { + # For some reason scselect expects location names to be encoded in Mac OS + # Roman; in order to prevent completed arguments from breaking the tool, we'll + # insert the UUID instead if the name would contain incompatible characters + tmp=( ${(f)"$( command $service 2> /dev/null )"} ) + tmp=( ${tmp[2,-1]} ) + tmp=( ${tmp##[*[:space:]]##} ) + tmp=( ${tmp//:/\\:} ) + tmp=( ${tmp/[[:space:]]##\(/$'\0'} ) + tmp=( ${tmp%\)} ) + + for u l in "${(@0)tmp}"; do + loc1+=( "${l}:${u}" ) + if [[ $l == [[:ascii:]]## ]]; then + loc2+=( $l ) + else + loc2+=( $u ) + fi + done + + if (( $#loc1 )); then + _describe location loc1 loc2 && ret=0 + else + _message location && ret=0 + fi +} + +return ret |