Skip to content

Instantly share code, notes, and snippets.

@takuya
Created February 16, 2016 06:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuya/73d7fe2737536feb028b to your computer and use it in GitHub Desktop.
Save takuya/73d7fe2737536feb028b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
### 補完関数。
_tmutil(){
list=$( tmutil | /usr/bin/grep -v ^$ | /usr/bin/grep ^Usage | awk '{print $3}' )
COMPREPLY=( $(compgen -W "$list" ${COMP_WORDS[COMP_CWORD]} ) )
}
complete -F _tmutil tmutil
@unknownzerx
Copy link

Slightly modified

_tmutil(){
    list=$( tmutil | /usr/bin/grep -v ^$ | /usr/bin/grep ^Usage | awk '{print $3}' )

    case $COMP_CWORD in
        1)
            COMPREPLY=( $(compgen -W "$list" ${COMP_WORDS[COMP_CWORD]}) )
            ;;
        *)
            COMPREPLY=()
            # http://stackoverflow.com/questions/12933362/getting-compgen-to-include-slashes-on-directories-when-looking-for-files
        ;;
    esac
}
complete -o default -F _tmutil tmutil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment