Skip to content

Commit

Permalink
Add bash completions
Browse files Browse the repository at this point in the history
Closes: mquinson#417
Signed-off-by: Alexander Golubev <[email protected]>
  • Loading branch information
Fat-Zer committed Nov 13, 2024
1 parent 7a7d424 commit c2f60fb
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions share/bash-completion/completions/msguntypot
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions share/bash-completion/completions/po4a
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions share/bash-completion/completions/po4a-display-man
16 changes: 16 additions & 0 deletions share/bash-completion/completions/po4a-display-pod
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions share/bash-completion/completions/po4a-gettextize
1 change: 1 addition & 0 deletions share/bash-completion/completions/po4a-normalize
1 change: 1 addition & 0 deletions share/bash-completion/completions/po4a-translate
1 change: 1 addition & 0 deletions share/bash-completion/completions/po4a-updatepo

0 comments on commit c2f60fb

Please sign in to comment.