Skip to content

Instantly share code, notes, and snippets.

@cphyc
Last active February 14, 2018 18:16
Show Gist options
  • Save cphyc/87a53a6fedd28914280f05c24eb7506b to your computer and use it in GitHub Desktop.
Save cphyc/87a53a6fedd28914280f05c24eb7506b to your computer and use it in GitHub Desktop.
yt autocompletion
# yt command line autocompletion
#
# This requires https://github.com/scop/bash-completion as well as http://github.com/yt-project/yt.
#
# To use, save it somewhere and source it (e.g. from your .bashrc). For example in your .bashrc add
# source ~/.yt-autocompletion
_yt()
{
local cur prev words cword split
local selected_command
_init_completion || return
# Possible commands
cmd="help bugreport hub instinfo version load mapserver pastebin pastebin_grab upload_notebook plot rpdb notebook stats update delete_image upload_image upload config search download"
selected_command=${words[1]}
case $selected_command in
load|upload|upload_image)
_filedir
;;
plot)
if [[ $prev == '-o' || $prev == '--output' ]]; then
_filedir -d
else
_filedir
COMPREPLY+=(
$( compgen -W "--help --width --unit --basename --projection --center --zlim --axis --field --weight --skip --colormap --output --show-grids --time --max --log --linear -fu --show-scale-bar" -- "$cur" ) )
fi
;;
pastebin)
_filedir
COMPREPLY+=(
$( compgen "--help --language --languages --encoding --open-browser --private --clipboard" -- "$cur" ) )
;;
mapserver)
_filedir
COMPREPLY+=(
$( compgen -W "--help --projection --field --weight --linear --center --width --colormap --axis --host" -- "$cur" ) )
;;
search)
if [[ $prev == '-o' || $prev == '--output' ]]; then
_filedir
else
_filedir
COMPREPLY+=(
$( compgen -W "--help --output --check-all --full" -- "$cur" ) )
fi
;;
instinfo|version)
if [ $prev == '--output-version' ]; then
_filedir
else
COMPREPLY=(
$( compgen -W "--help --update-source --output-version" -- "$cur" ) )
fi
;;
stats)
if [ $prev == '--output' || $prev == '-o' ]; then
_filedir
else
_filedir
COMPREPLY+=(
$( compgen -W "--help --output --basename --skip --field --max --min" -- "$cur") )
fi
;;
update)
_filedir
COMPREPLY+=(
$( compgen -W "--help --all" -- "$cur") )
;;
upload_notebook)
_filedir '@(ipynb|py)'
;;
*)
COMPREPLY=( $( compgen -W "$cmd" -- "$cur") )
;;
esac
return
} && complete -F _yt yt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment