Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
### 補完関数。
_desktop_change(){
curr="${COMP_WORDS[$COMP_CWORD-1]}"
cmd=${COMP_WORDS[0]}
case $COMP_CWORD in
1)
if [[ $cmd == $curr ]] ; then
opts=$( $cmd --help | $(which grep) -Po '(?<=\s\s)\-[a-z]' | sort | uniq )
COMPREPLY=( $(compgen -W "$opts" -- ${COMP_WORDS[COMP_CWORD]} ) )
return 0;
fi
;;
2)
case ${COMP_WORDS[1]} in
-c|-r)
COMPREPLY=( $(compgen -W "$( $cmd -l | xargs -I@ echo "'@'")" ${COMP_WORDS[COMP_CWORD]} ) )
return 0
;;
*)
;;
esac
;;
esac
}
complete -F _desktop_change desktop-change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment