Last active
December 25, 2017 11:19
-
-
Save takuya/6ec7829263fae7d20055f728040af1bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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