python/semanage: fall back to filename completion for fcontext paths
Stephen Smalley
maintainerPATCH 1/1 python/semanage: fall back to filename completion for fcontext paths
semanage fcontext -a -t TYPE /some/pathprefix<TAB> does not auto-complete currently; the fcontext arm of _semanage() unconditionally offers the option word list for any word that isn't the argument to -t/-f/-S/..., and the completion is registered without -o default, so an empty match stays empty.
Register the completion with '-o default -o bashdefault' so an empty COMPREPLY falls through to readline filename completion, and only offer the fcontext option list when the current word is empty or starts with '-'. The path/regex positional and the -e/--equal argument then get ordinary filename completion.
While here, the __get_*_opts helpers echo '$ALL_OPTS $MANAGED_OPTS ...' in single quotes, so the common option variables are never expanded and only the per-subcommand-specific flags have ever been offered. Switch to double quotes so -l/--list, -a/--add, -h/--help, etc are completed under every subcommand.
--- python/semanage/semanage-bash-completion.sh | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-)
python/semanage/semanage-bash-completion.sh +16 -14
@@ -57,18 +57,18 @@ __get_all_stores () { __get_all_modules () { semodule -l } -__get_import_opts () { echo '$ALL_OPTS --f --input_file' ; } -__get_export_opts () { echo '$ALL_OPTS --f --output_file' ; } -__get_boolean_opts () { echo '$ALL_OPTS --on -off -1 -0' ; } -__get_user_opts () { echo '$ALL_OPTS $MANAGED_OPTS -L --level -r --range -R --role '; } -__get_login_opts () { echo '$ALL_OPTS $MANAGED_OPTS -s --seuser -r --range'; } -__get_port_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -r --range -p --proto'; } -__get_interface_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type '; } -__get_node_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -M --mask -p --proto'; } -__get_fcontext_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -e --equal -f --ftype '; } -__get_module_opts () { echo '$ALL_OPTS $MANAGED_OPTS --enable --disable '; } -__get_dontaudit_opts () { echo '-S on off' ; } -__get_permissive_opts () { echo '$ALL_OPTS -a --add -d --delete' ; } +__get_import_opts () { echo "$ALL_OPTS --f --input_file" ; } +__get_export_opts () { echo "$ALL_OPTS --f --output_file" ; } +__get_boolean_opts () { echo "$ALL_OPTS --on -off -1 -0" ; } +__get_user_opts () { echo "$ALL_OPTS $MANAGED_OPTS -L --level -r --range -R --role "; } +__get_login_opts () { echo "$ALL_OPTS $MANAGED_OPTS -s --seuser -r --range"; } +__get_port_opts () { echo "$ALL_OPTS $MANAGED_OPTS -t --type -r --range -p --proto"; } +__get_interface_opts () { echo "$ALL_OPTS $MANAGED_OPTS -t --type "; } +__get_node_opts () { echo "$ALL_OPTS $MANAGED_OPTS -t --type -M --mask -p --proto"; } +__get_fcontext_opts () { echo "$ALL_OPTS $MANAGED_OPTS -t --type -e --equal -f --ftype "; } +__get_module_opts () { echo "$ALL_OPTS $MANAGED_OPTS --enable --disable "; } +__get_dontaudit_opts () { echo "-S on off" ; } +__get_permissive_opts () { echo "$ALL_OPTS -a --add -d --delete" ; } _semanage () { local command=${COMP_WORDS[1]}
@@ -150,7 +150,9 @@ _semanage () { COMPREPLY=( $(compgen -W "$( __get_node_opts ) " -- "$cur") ) return 0 elif __contains_word "$command" ${VERBS[FCONTEXT]} ; then - COMPREPLY=( $(compgen -W "$( __get_fcontext_opts ) " -- "$cur") ) + if [[ -z "$cur" || "$cur" == -* ]] ; then + COMPREPLY=( $(compgen -W "$( __get_fcontext_opts ) " -- "$cur") ) + fi return 0 elif __contains_word "$command" ${VERBS[BOOLEAN]} ; then COMPREPLY=( $(compgen -W "$( __get_boolean_opts ) " -- "$cur") )
@@ -171,4 +173,4 @@ _semanage () { COMPREPLY=( $(compgen -W "$comps" -- "$cur") ) return 0 } -complete -F _semanage semanage +complete -o default -o bashdefault -F _semanage semanage
Signature · 1 line
2.55.0
Stephen Smalley
maintainerQuoted 19 lines · Stephen Smalley
semanage fcontext -a -t TYPE /some/pathprefix<TAB> does not auto-complete currently; the fcontext arm of
_semanage()unconditionally offers the option word list for any word that isn't the argument to -t/-f/-S/..., and the completion is registered without -o default, so an empty match stays empty.Register the completion with '-o default -o bashdefault' so an empty COMPREPLY falls through to readline filename completion, and only offer the fcontext option list when the current word is empty or starts with '-'. The path/regex positional and the -e/--equal argument then get ordinary filename completion.
While here, the __get_*_opts helpers echo '$ALL_OPTS $MANAGED_OPTS ...' in single quotes, so the common option variables are never expanded and only the per-subcommand-specific flags have ever been offered. Switch to double quotes so -l/--list, -a/--add, -h/--help, etc are completed under every subcommand.
Quoted 3 lines
Reported-by Germano Massullo (@Germano0)Signed-off-by Stephen Smalley <[email protected]>
This has been merged.