Skip to content

Instantly share code, notes, and snippets.

@caljess599
Last active August 10, 2017 19:47
Show Gist options
  • Save caljess599/ddc973d1628f0dfbad5e9c40c76a006c to your computer and use it in GitHub Desktop.
Save caljess599/ddc973d1628f0dfbad5e9c40c76a006c to your computer and use it in GitHub Desktop.
completion file for lctl (Lustre Control)
# file: lctl-2
# lctl parameter-completion
# The main menu is created by hand; I excluded deprecated/"dangerous" functions and some only relevant to interactive mode
# The submenu for the get_param and set_param is auto-generated and replaces the actual device numbers (e.g., OST0030)
# with * so that the list becomes manageable.
LIST_PARAM=$(lctl list_param -R | grep -v '[0-9]$' | sed s/OST[0-f][0-f][0-f][0-f]/OST*/g)
CONTROL_PARAM="--net network net list_nids which_nid replace_nids interface_list peer_list conn_list active_tx route_list show_route ping help lustre_build_version device
device_list dl activate deactivate abort_recovery set_timeout conf_param local_param get_param set_param list_param debug_daemon debug_kernel dk debug_file df clear mark filter show debug_list modules blockdev_attach blockdev_detach blockdev_info pool_new pool_add pool_remove pool_destroy pool_list changelog_register changelog_deregister lfsck_start lfsck_stop set_route"
_lctl-2() # By convention, the function name starts with an underscore
{
local cur prev
COMPREPLY=() # Array variable storing the possible completions.
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "`echo $CONTROL_PARAM`" -- $cur) )
elif [ $COMP_CWORD -eq 2 ]; then
case "$prev" in
"get_param"|"set_param")
COMPREPLY=( $(compgen -W "$LIST_PARAM" -- $cur) )
;;
*)
;;
esac
fi
return 0
} &&
complete -F _lctl-2 lctl #Invokes the function _lctl-2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment