Skip to content

Instantly share code, notes, and snippets.

@unhammer
Created October 4, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unhammer/2c60a9089ec9cc1c6e7d7660bd7d5734 to your computer and use it in GitHub Desktop.
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
#!/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