Browse Source

completion files or command insensitive

main
pvincent 3 weeks ago
parent
commit
34ae45705b
  1. 43
      lib/miaou.completion
  2. 9
      tools/miaou-exec

43
lib/miaou.completion

@ -61,13 +61,17 @@ function _miaou_exec() {
if ((COMP_CWORD == 3)); then if ((COMP_CWORD == 3)); then
# command or file from inside container # command or file from inside container
# echo -e "\nCOMMAND or FILE from CONTAINER\n" >&2
COMPREPLY=($( COMPREPLY=($(
incus exec "$container" -- bash << EOF incus exec "$container" -- bash << EOF
source /etc/bash_completion
compgen -c -- "$cur"
bind -f /etc/inputrc 2>/dev/null
source /etc/bash_completion
compgen -c -- "$cur"
compgen -f -- "$cur"
EOF EOF
)) ))
compopt -o filenames
compopt -o nospace
return return
fi fi
@ -94,19 +98,20 @@ EOF
# echo -e "\ncompletion_command $completion_command \nprev=$prev \ncur=$cur \nCOMP_WORDS=(${COMP_WORDS[@]}) \nCOMP_CWORD=$COMP_CWORD \nCOMP_LINE=$COMP_LINE \nCOMP_POINT=$COMP_POINT" >&2 # echo -e "\ncompletion_command $completion_command \nprev=$prev \ncur=$cur \nCOMP_WORDS=(${COMP_WORDS[@]}) \nCOMP_CWORD=$COMP_CWORD \nCOMP_LINE=$COMP_LINE \nCOMP_POINT=$COMP_POINT" >&2
COMPREPLY=($( COMPREPLY=($(
incus exec "$container" -- bash << EOF incus exec "$container" -- bash << EOF
source /etc/bash_completion
for i in /etc/bash_completion.d/*; do source \$i; done
source /usr/share/bash-completion/bash_completion
[[ -f /usr/share/bash-completion/completions/$command ]] && source /usr/share/bash-completion/completions/$command
COMP_WORDS=(${COMP_WORDS[@]})
COMP_CWORD=$COMP_CWORD
COMP_LINE="$COMP_LINE"
COMP_POINT=$COMP_POINT
COMP_TYPE=9
COMP_KEY=9
export COMP_WORDS COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY
$completion_command 2>/dev/null
echo \${COMPREPLY[@]}
bind -f /etc/inputrc 2>/dev/null
source /etc/bash_completion
for i in /etc/bash_completion.d/*; do source \$i; done
source /usr/share/bash-completion/bash_completion
[[ -f /usr/share/bash-completion/completions/$command ]] && source /usr/share/bash-completion/completions/$command
COMP_WORDS=(${COMP_WORDS[@]})
COMP_CWORD=$COMP_CWORD
COMP_LINE="$COMP_LINE"
COMP_POINT=$COMP_POINT
COMP_TYPE=9
COMP_KEY=9
export COMP_WORDS COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY
$completion_command 2>/dev/null
echo \${COMPREPLY[@]}
EOF EOF
)) ))
if [[ $completion_command == '_comp_complete_longopt' ]]; then if [[ $completion_command == '_comp_complete_longopt' ]]; then
@ -115,12 +120,14 @@ EOF
fi fi
else else
echo -e "\nNO completion_command JUST plain files and firs" >&2
compopt -o filenames compopt -o filenames
compopt -o nospace compopt -o nospace
COMPREPLY=($( COMPREPLY=($(
incus exec "$container" -- bash << EOF incus exec "$container" -- bash << EOF
source /etc/bash_completion
compgen -f "$cur" 2>/dev/null
bind -f /etc/inputrc 2>/dev/null
source /etc/bash_completion
compgen -f "$cur" 2>/dev/null
EOF EOF
)) ))
fi fi

9
tools/miaou-exec

@ -9,8 +9,13 @@ COMMAND=''
# FUNCTIONS # FUNCTIONS
function usage { function usage {
echo "$(basename "$0") <CONTAINER_NAME> -- <COMMAND>"
echo -e "$(basename "$0") <CONTAINER_NAME> -- bash <<EOF\nls -l\nuptime\nEOF"
echo Usage:
echo -e "\t$(basename "$0") <CONTAINER_NAME> [--] <COMMAND>"
echo
echo "Examples:"
echo -e "\t$(basename "$0") container1 uptime"
echo -e "\t$(basename "$0") container1 -- ls -la"
echo -e "\t$(basename "$0") container1 -- bash <<EOF\n\t\tls -l\n\t\tuptime\n\tEOF"
} }
function parse_options { function parse_options {

Loading…
Cancel
Save