Created
October 4, 2018 12:56
-
-
Save unhammer/2c60a9089ec9cc1c6e7d7660bd7d5734 to your computer and use it in GitHub Desktop.
~/.bash_completion.d/xsv.bash bash completion for xsv https://github.com/BurntSushi/xsv
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
#!/bin/bash | |
_xsv() | |
{ | |
cur=${COMP_WORDS[COMP_CWORD]} | |
prev=${COMP_WORDS[COMP_CWORD-1]} | |
cmds=$(xsv --list|awk '/Installed/{next}/./{print $1}') | |
while read -r cmd; do | |
if [[ "${prev}" = "${cmd}" ]]; then | |
case "${cur}" in | |
-*) | |
opts=$(xsv "$prev" --help|grep -oe "-[^., ')\`]\+") # hacky, but seems to work well[1] | |
COMPREPLY=( $( compgen -W "${opts}" -- "$cur" ) ) | |
return | |
;; | |
*) | |
_filedir | |
return | |
;; | |
esac | |
fi | |
done <<<"${cmds}" | |
case "$cur" in | |
-*) | |
help_parsed=$( _parse_help "$1" ) | |
COMPREPLY=( $( compgen -W "${help_parsed}" -- "$cur" ) ) | |
;; | |
*) | |
COMPREPLY=( $( compgen -W "${cmds}" -- "$cur" ) ) | |
;; | |
esac | |
} && | |
complete -o filenames -o bashdefault -F _xsv xsv | |
# [1] To see the full list we get with this regex, run: | |
# xsv --list|awk '/Installed/{next}/./{print $1}' | while read -r cmd; do | |
# echo "$cmd" | |
# xsv "$cmd" --help|grep -oe "-[^., ')\`]\+" | |
# done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment