From c2f60fbd6ebd5d9afbee943fb8f573a08b1d7af0 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Wed, 13 Nov 2024 03:03:39 +0300 Subject: [PATCH] Add bash completions Closes: https://github.com/mquinson/po4a/issues/417 Signed-off-by: Alexander Golubev --- share/bash-completion/completions/msguntypot | 16 ++++++ share/bash-completion/completions/po4a | 50 +++++++++++++++++++ .../completions/po4a-display-man | 1 + .../completions/po4a-display-pod | 16 ++++++ .../completions/po4a-gettextize | 1 + .../completions/po4a-normalize | 1 + .../completions/po4a-translate | 1 + .../bash-completion/completions/po4a-updatepo | 1 + 8 files changed, 87 insertions(+) create mode 100644 share/bash-completion/completions/msguntypot create mode 100644 share/bash-completion/completions/po4a create mode 120000 share/bash-completion/completions/po4a-display-man create mode 100644 share/bash-completion/completions/po4a-display-pod create mode 120000 share/bash-completion/completions/po4a-gettextize create mode 120000 share/bash-completion/completions/po4a-normalize create mode 120000 share/bash-completion/completions/po4a-translate create mode 120000 share/bash-completion/completions/po4a-updatepo diff --git a/share/bash-completion/completions/msguntypot b/share/bash-completion/completions/msguntypot new file mode 100644 index 000000000..bff72f97a --- /dev/null +++ b/share/bash-completion/completions/msguntypot @@ -0,0 +1,16 @@ +# bash completion for po4a(7) utilities. -*- shell-script -*- +# this file provides completion for msguntypot + +_comp_cmd_po4a_msguntypot() { + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W '-o -n' -- "$cur" ) ) + return + fi + + _filedir +} && complete -F _comp_cmd_po4a_msguntypot msguntypot + +# ex: filetype=sh diff --git a/share/bash-completion/completions/po4a b/share/bash-completion/completions/po4a new file mode 100644 index 000000000..41fb660ee --- /dev/null +++ b/share/bash-completion/completions/po4a @@ -0,0 +1,50 @@ +# bash completion for po4a(7) utilities. -*- shell-script -*- +# this file provides completions for po4a itself and old-style scripts: +# po4a-updatepo po4a-normalize po4a-gettextize po4a-translate + +_comp_cmd_po4a_utils() { + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + local cmd="$(basename "${comp_args[0]}")" + + case $prev in + -h | --help | -V | --version) return ;; + --help-format) [[ "$cmd" != "po4a" ]] && return ;; + --porefs) + if [[ "$cmd" != "po4a-translate" ]]; then + COMPREPLY=( $( compgen -W 'never file counter full' -- "$cur" ) ) + return + fi + ;; + -f | --format) + if [[ "$cmd" != "po4a" ]]; then + local formats=" + $(command "${cmd}" --help-format 2>&1 | { + local rx='^ - ([a-z]+):'; + while IFS= read line; do + [[ $line =~ $rx ]] && echo "${BASH_REMATCH[1]}" + done + })" + + COMPREPLY=( $( compgen -W "${formats}" -- "$cur" ) ) + return + fi + ;; + esac + + if [[ $cur == -* ]]; then + # po4a lists some arguments of other commands in its help message and + # they can end up first on the line e.g. msgmerge's "-U", so we should + # avoid leeking them to complitiones + _comp_compgen_help - < <( + command "${comp_args[0]}" --help 2>/dev/null | + command grep '^ -' 2>/dev/null + ) + return + fi + + _filedir +} && complete -F _comp_cmd_po4a_utils po4a po4a-updatepo po4a-normalize po4a-gettextize po4a-translate + +# ex: filetype=sh diff --git a/share/bash-completion/completions/po4a-display-man b/share/bash-completion/completions/po4a-display-man new file mode 120000 index 000000000..c7ac6cef1 --- /dev/null +++ b/share/bash-completion/completions/po4a-display-man @@ -0,0 +1 @@ +po4a-display-pod \ No newline at end of file diff --git a/share/bash-completion/completions/po4a-display-pod b/share/bash-completion/completions/po4a-display-pod new file mode 100644 index 000000000..be6c3d3b0 --- /dev/null +++ b/share/bash-completion/completions/po4a-display-pod @@ -0,0 +1,16 @@ +# bash completion for po4a(7) utilities. -*- shell-script -*- +# this file provides completion for po4a-display-pod and po4a-display-man + +_comp_cmd_po4a_scripts() { + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W '-m -o -p' -- "$cur" ) ) + return + fi + + _filedir +} && complete -F _comp_cmd_po4a_scripts po4a-display-pod po4a-display-man + +# ex: filetype=sh diff --git a/share/bash-completion/completions/po4a-gettextize b/share/bash-completion/completions/po4a-gettextize new file mode 120000 index 000000000..edd9e39e2 --- /dev/null +++ b/share/bash-completion/completions/po4a-gettextize @@ -0,0 +1 @@ +po4a \ No newline at end of file diff --git a/share/bash-completion/completions/po4a-normalize b/share/bash-completion/completions/po4a-normalize new file mode 120000 index 000000000..edd9e39e2 --- /dev/null +++ b/share/bash-completion/completions/po4a-normalize @@ -0,0 +1 @@ +po4a \ No newline at end of file diff --git a/share/bash-completion/completions/po4a-translate b/share/bash-completion/completions/po4a-translate new file mode 120000 index 000000000..edd9e39e2 --- /dev/null +++ b/share/bash-completion/completions/po4a-translate @@ -0,0 +1 @@ +po4a \ No newline at end of file diff --git a/share/bash-completion/completions/po4a-updatepo b/share/bash-completion/completions/po4a-updatepo new file mode 120000 index 000000000..edd9e39e2 --- /dev/null +++ b/share/bash-completion/completions/po4a-updatepo @@ -0,0 +1 @@ +po4a \ No newline at end of file