From 692f35c07aa7bfce7521c2ae17c34acca00751ac Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Tue, 7 Jun 2022 11:36:08 +0100 Subject: move bashcomp --- .bash_completion | 9 - .bash_completion.d/dmount.bashcomp | 7 - .bash_completion.d/mupdf.bashcomp | 25 -- .bash_completion.d/pd.bashcomp | 2 - .bash_completion.d/website.bashcomp | 1 - .local/share/bash-completion/completions/dmount | 7 + .local/share/bash-completion/completions/go2 | 449 ++++++++++++++++++++++++ .local/share/bash-completion/completions/mupdf | 25 ++ .local/share/bash-completion/completions/pd | 2 + 9 files changed, 483 insertions(+), 44 deletions(-) delete mode 100644 .bash_completion delete mode 100644 .bash_completion.d/dmount.bashcomp delete mode 100644 .bash_completion.d/mupdf.bashcomp delete mode 100644 .bash_completion.d/pd.bashcomp delete mode 120000 .bash_completion.d/website.bashcomp create mode 100644 .local/share/bash-completion/completions/dmount create mode 100644 .local/share/bash-completion/completions/go2 create mode 100644 .local/share/bash-completion/completions/mupdf create mode 100644 .local/share/bash-completion/completions/pd diff --git a/.bash_completion b/.bash_completion deleted file mode 100644 index 0dd54ff..0000000 --- a/.bash_completion +++ /dev/null @@ -1,9 +0,0 @@ -# -*- mode: sh -*- - -bcdir="$HOME/.bash_completion.d" -if [[ -d "$bcdir" && -r "$bcdir" && -x "$bcdir" ]]; then - for i in "$bcdir"/*.bashcomp; do - [[ -f $i && -r $i ]] && . "$i" - done -fi - diff --git a/.bash_completion.d/dmount.bashcomp b/.bash_completion.d/dmount.bashcomp deleted file mode 100644 index 7299a9b..0000000 --- a/.bash_completion.d/dmount.bashcomp +++ /dev/null @@ -1,7 +0,0 @@ -# -*- mode: sh -*- - -_dmount_list() { - COMPREPLY=( $( compgen -W '$(dmount --list)' -- "$2" ) ) -} - -complete -F _dmount_list dmount diff --git a/.bash_completion.d/mupdf.bashcomp b/.bash_completion.d/mupdf.bashcomp deleted file mode 100644 index dd02b65..0000000 --- a/.bash_completion.d/mupdf.bashcomp +++ /dev/null @@ -1,25 +0,0 @@ -# mupdf(1) completion -*- shell-script -*- - -_mupdf() -{ - local cur prev words cword split - _init_completion -s || return - - case $prev in - --help*|-h|-p|-r|-W|-H|-S|-U|-x) - return - ;; - esac - - $split && return - - if [[ $cur == -* ]]; then - COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help )' \ - -- "$cur" ) ) - [[ $COMPREPLY == *= ]] && compopt -o nospace - return - fi - - _filedir '@(@(?(e)ps|?(E)PS|[pf]df|[PF]DF|dvi|DVI)?(.gz|.GZ|.bz2|.BZ2|.xz|.XZ)|cb[rz]|djv?(u)|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|epub)' -} && -complete -F _mupdf mupdf diff --git a/.bash_completion.d/pd.bashcomp b/.bash_completion.d/pd.bashcomp deleted file mode 100644 index 4eb8044..0000000 --- a/.bash_completion.d/pd.bashcomp +++ /dev/null @@ -1,2 +0,0 @@ -_xfunc perl _perldoc -complete -F _perldoc -o bashdefault pm pd diff --git a/.bash_completion.d/website.bashcomp b/.bash_completion.d/website.bashcomp deleted file mode 120000 index cd8d05a..0000000 --- a/.bash_completion.d/website.bashcomp +++ /dev/null @@ -1 +0,0 @@ -/home/dakkar/website/thenautilus/website.bashcomp \ No newline at end of file diff --git a/.local/share/bash-completion/completions/dmount b/.local/share/bash-completion/completions/dmount new file mode 100644 index 0000000..7299a9b --- /dev/null +++ b/.local/share/bash-completion/completions/dmount @@ -0,0 +1,7 @@ +# -*- mode: sh -*- + +_dmount_list() { + COMPREPLY=( $( compgen -W '$(dmount --list)' -- "$2" ) ) +} + +complete -F _dmount_list dmount diff --git a/.local/share/bash-completion/completions/go2 b/.local/share/bash-completion/completions/go2 new file mode 100644 index 0000000..45406b9 --- /dev/null +++ b/.local/share/bash-completion/completions/go2 @@ -0,0 +1,449 @@ +#!bash + +# Generated with perl module App::Spec v0.013 + +_go2() { + + COMPREPLY=() + local program=go2 + local cur prev words cword + _init_completion -n : || return + declare -a FLAGS + declare -a OPTIONS + declare -a MYWORDS + + local INDEX=`expr $cword - 1` + MYWORDS=("${words[@]:1:$cword}") + + FLAGS=('--help' 'Show command help' '-h' 'Show command help') + OPTIONS=('--config-file' 'load configuration from this file' '-C' 'load configuration from this file') + __go2_handle_options_flags + + case $INDEX in + + 0) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'connect'$'\t''connect to the hosts'$'\n''cp'$'\t''copy files from/to hosts'$'\n''cssh'$'\t''connect to the hosts via ClusterSSH'$'\n''help'$'\t''Show command help'$'\n''list'$'\t''list the hosts'$'\n''wipe-cache'$'\t''removes all cached machine information' + + ;; + *) + # subcmds + case ${MYWORDS[0]} in + _meta) + __go2_handle_options_flags + case $INDEX in + + 1) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'completion'$'\t''Shell completion functions'$'\n''pod'$'\t''Pod documentation' + + ;; + *) + # subcmds + case ${MYWORDS[1]} in + completion) + __go2_handle_options_flags + case $INDEX in + + 2) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'generate'$'\t''Generate self completion' + + ;; + *) + # subcmds + case ${MYWORDS[2]} in + generate) + FLAGS+=('--zsh' 'for zsh' '--bash' 'for bash') + OPTIONS+=('--name' 'name of the program (optional, override name in spec)') + __go2_handle_options_flags + case ${MYWORDS[$INDEX-1]} in + --config-file|-C) + ;; + --name) + ;; + + esac + case $INDEX in + + *) + __comp_current_options || return + ;; + esac + ;; + esac + + ;; + esac + ;; + pod) + __go2_handle_options_flags + case $INDEX in + + 2) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'generate'$'\t''Generate self pod' + + ;; + *) + # subcmds + case ${MYWORDS[2]} in + generate) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + esac + + ;; + esac + ;; + esac + + ;; + esac + ;; + connect) + FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '--dry-run' 'don'"\\'"'t run the ssh command, just print it' '-d' 'don'"\\'"'t run the ssh command, just print it') + __go2_handle_options_flags + case ${MYWORDS[$INDEX-1]} in + --config-file|-C) + ;; + + esac + case $INDEX in + 1) + __comp_current_options || return + _go2_connect_param_regex_completion + ;; + + + *) + __comp_current_options || return + ;; + esac + ;; + cp) + FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '--dry-run' 'don'"\\'"'t run the ssh command, just print it' '-d' 'don'"\\'"'t run the ssh command, just print it' '--recursive' 'recursively copy entire directories' '-r' 'recursively copy entire directories') + __go2_handle_options_flags + case ${MYWORDS[$INDEX-1]} in + --config-file|-C) + ;; + + esac + case $INDEX in + 1) + __comp_current_options || return + _go2_cp_param_path_completion + ;; + + + *) + __comp_current_options || return + ;; + esac + ;; + cssh) + FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN') + __go2_handle_options_flags + case ${MYWORDS[$INDEX-1]} in + --config-file|-C) + ;; + + esac + case $INDEX in + 1) + __comp_current_options || return + _go2_cssh_param_regex_completion + ;; + + + *) + __comp_current_options || return + ;; + esac + ;; + help) + FLAGS+=('--all' '') + __go2_handle_options_flags + case $INDEX in + + 1) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'connect'$'\n''cp'$'\n''cssh'$'\n''list'$'\n''wipe-cache' + + ;; + *) + # subcmds + case ${MYWORDS[1]} in + _meta) + __go2_handle_options_flags + case $INDEX in + + 2) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'completion'$'\n''pod' + + ;; + *) + # subcmds + case ${MYWORDS[2]} in + completion) + __go2_handle_options_flags + case $INDEX in + + 3) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'generate' + + ;; + *) + # subcmds + case ${MYWORDS[3]} in + generate) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + esac + + ;; + esac + ;; + pod) + __go2_handle_options_flags + case $INDEX in + + 3) + __comp_current_options || return + __go2_dynamic_comp 'commands' 'generate' + + ;; + *) + # subcmds + case ${MYWORDS[3]} in + generate) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + esac + + ;; + esac + ;; + esac + + ;; + esac + ;; + connect) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + cp) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + cssh) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + list) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + wipe-cache) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + esac + + ;; + esac + ;; + list) + FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN') + __go2_handle_options_flags + case ${MYWORDS[$INDEX-1]} in + --config-file|-C) + ;; + + esac + case $INDEX in + 1) + __comp_current_options || return + _go2_list_param_regex_completion + ;; + + + *) + __comp_current_options || return + ;; + esac + ;; + wipe-cache) + __go2_handle_options_flags + __comp_current_options true || return # no subcmds, no params/opts + ;; + esac + + ;; + esac + +} + +_go2_compreply() { + local prefix="" + cur="$(printf '%q' "$cur")" + IFS=$'\n' COMPREPLY=($(compgen -P "$prefix" -W "$*" -- "$cur")) + __ltrim_colon_completions "$prefix$cur" + + # http://stackoverflow.com/questions/7267185/bash-autocompletion-add-description-for-possible-completions + if [[ ${#COMPREPLY[*]} -eq 1 ]]; then # Only one completion + COMPREPLY=( "${COMPREPLY[0]%% -- *}" ) # Remove ' -- ' and everything after + COMPREPLY=( "${COMPREPLY[0]%%+( )}" ) # Remove trailing spaces + fi +} + +_go2_connect_param_regex_completion() { + local __dynamic_completion + __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='regex' ${words[@]}) + __go2_dynamic_comp 'regex' "$__dynamic_completion" +} +_go2_cp_param_path_completion() { + local __dynamic_completion + __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='path' ${words[@]}) + __go2_dynamic_comp 'path' "$__dynamic_completion" +} +_go2_cssh_param_regex_completion() { + local __dynamic_completion + __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='regex' ${words[@]}) + __go2_dynamic_comp 'regex' "$__dynamic_completion" +} +_go2_list_param_regex_completion() { + local __dynamic_completion + __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='regex' ${words[@]}) + __go2_dynamic_comp 'regex' "$__dynamic_completion" +} + +__go2_dynamic_comp() { + local argname="$1" + local arg="$2" + local name desc cols desclength formatted + local comp=() + local max=0 + + while read -r line; do + name="$line" + desc="$line" + name="${name%$'\t'*}" + if [[ "${#name}" -gt "$max" ]]; then + max="${#name}" + fi + done <<< "$arg" + + while read -r line; do + name="$line" + desc="$line" + name="${name%$'\t'*}" + desc="${desc/*$'\t'}" + if [[ -n "$desc" && "$desc" != "$name" ]]; then + # TODO portable? + cols=`tput cols` + [[ -z $cols ]] && cols=80 + desclength=`expr $cols - 4 - $max` + formatted=`printf "%-*s -- %-*s" "$max" "$name" "$desclength" "$desc"` + comp+=("$formatted") + else + comp+=("'$name'") + fi + done <<< "$arg" + _go2_compreply ${comp[@]} +} + +function __go2_handle_options() { + local i j + declare -a copy + local last="${MYWORDS[$INDEX]}" + local max=`expr ${#MYWORDS[@]} - 1` + for ((i=0; i<$max; i++)) + do + local word="${MYWORDS[$i]}" + local found= + for ((j=0; j<${#OPTIONS[@]}; j+=2)) + do + local option="${OPTIONS[$j]}" + if [[ "$word" == "$option" ]]; then + found=1 + i=`expr $i + 1` + break + fi + done + if [[ -n $found && $i -lt $max ]]; then + INDEX=`expr $INDEX - 2` + else + copy+=("$word") + fi + done + MYWORDS=("${copy[@]}" "$last") +} + +function __go2_handle_flags() { + local i j + declare -a copy + local last="${MYWORDS[$INDEX]}" + local max=`expr ${#MYWORDS[@]} - 1` + for ((i=0; i<$max; i++)) + do + local word="${MYWORDS[$i]}" + local found= + for ((j=0; j<${#FLAGS[@]}; j+=2)) + do + local flag="${FLAGS[$j]}" + if [[ "$word" == "$flag" ]]; then + found=1 + break + fi + done + if [[ -n $found ]]; then + INDEX=`expr $INDEX - 1` + else + copy+=("$word") + fi + done + MYWORDS=("${copy[@]}" "$last") +} + +__go2_handle_options_flags() { + __go2_handle_options + __go2_handle_flags +} + +__comp_current_options() { + local always="$1" + if [[ -n $always || ${MYWORDS[$INDEX]} =~ ^- ]]; then + + local options_spec='' + local j= + + for ((j=0; j<${#FLAGS[@]}; j+=2)) + do + local name="${FLAGS[$j]}" + local desc="${FLAGS[$j+1]}" + options_spec+="$name"$'\t'"$desc"$'\n' + done + + for ((j=0; j<${#OPTIONS[@]}; j+=2)) + do + local name="${OPTIONS[$j]}" + local desc="${OPTIONS[$j+1]}" + options_spec+="$name"$'\t'"$desc"$'\n' + done + __go2_dynamic_comp 'options' "$options_spec" + + return 1 + else + return 0 + fi +} + + +complete -o default -F _go2 go2 diff --git a/.local/share/bash-completion/completions/mupdf b/.local/share/bash-completion/completions/mupdf new file mode 100644 index 0000000..dd02b65 --- /dev/null +++ b/.local/share/bash-completion/completions/mupdf @@ -0,0 +1,25 @@ +# mupdf(1) completion -*- shell-script -*- + +_mupdf() +{ + local cur prev words cword split + _init_completion -s || return + + case $prev in + --help*|-h|-p|-r|-W|-H|-S|-U|-x) + return + ;; + esac + + $split && return + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help )' \ + -- "$cur" ) ) + [[ $COMPREPLY == *= ]] && compopt -o nospace + return + fi + + _filedir '@(@(?(e)ps|?(E)PS|[pf]df|[PF]DF|dvi|DVI)?(.gz|.GZ|.bz2|.BZ2|.xz|.XZ)|cb[rz]|djv?(u)|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|epub)' +} && +complete -F _mupdf mupdf diff --git a/.local/share/bash-completion/completions/pd b/.local/share/bash-completion/completions/pd new file mode 100644 index 0000000..4eb8044 --- /dev/null +++ b/.local/share/bash-completion/completions/pd @@ -0,0 +1,2 @@ +_xfunc perl _perldoc +complete -F _perldoc -o bashdefault pm pd -- cgit v1.2.3