Skip to content

Commit c2f60fb

Browse files
committed
Add bash completions
Closes: mquinson#417 Signed-off-by: Alexander Golubev <[email protected]>
1 parent 7a7d424 commit c2f60fb

File tree

8 files changed

+87
-0
lines changed

8 files changed

+87
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# bash completion for po4a(7) utilities. -*- shell-script -*-
2+
# this file provides completion for msguntypot
3+
4+
_comp_cmd_po4a_msguntypot() {
5+
local cur prev words cword comp_args
6+
_comp_initialize -- "$@" || return
7+
8+
if [[ $cur == -* ]]; then
9+
COMPREPLY=( $( compgen -W '-o -n' -- "$cur" ) )
10+
return
11+
fi
12+
13+
_filedir
14+
} && complete -F _comp_cmd_po4a_msguntypot msguntypot
15+
16+
# ex: filetype=sh
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# bash completion for po4a(7) utilities. -*- shell-script -*-
2+
# this file provides completions for po4a itself and old-style scripts:
3+
# po4a-updatepo po4a-normalize po4a-gettextize po4a-translate
4+
5+
_comp_cmd_po4a_utils() {
6+
local cur prev words cword comp_args
7+
_comp_initialize -- "$@" || return
8+
9+
local cmd="$(basename "${comp_args[0]}")"
10+
11+
case $prev in
12+
-h | --help | -V | --version) return ;;
13+
--help-format) [[ "$cmd" != "po4a" ]] && return ;;
14+
--porefs)
15+
if [[ "$cmd" != "po4a-translate" ]]; then
16+
COMPREPLY=( $( compgen -W 'never file counter full' -- "$cur" ) )
17+
return
18+
fi
19+
;;
20+
-f | --format)
21+
if [[ "$cmd" != "po4a" ]]; then
22+
local formats="
23+
$(command "${cmd}" --help-format 2>&1 | {
24+
local rx='^ - ([a-z]+):';
25+
while IFS= read line; do
26+
[[ $line =~ $rx ]] && echo "${BASH_REMATCH[1]}"
27+
done
28+
})"
29+
30+
COMPREPLY=( $( compgen -W "${formats}" -- "$cur" ) )
31+
return
32+
fi
33+
;;
34+
esac
35+
36+
if [[ $cur == -* ]]; then
37+
# po4a lists some arguments of other commands in its help message and
38+
# they can end up first on the line e.g. msgmerge's "-U", so we should
39+
# avoid leeking them to complitiones
40+
_comp_compgen_help - < <(
41+
command "${comp_args[0]}" --help 2>/dev/null |
42+
command grep '^ -' 2>/dev/null
43+
)
44+
return
45+
fi
46+
47+
_filedir
48+
} && complete -F _comp_cmd_po4a_utils po4a po4a-updatepo po4a-normalize po4a-gettextize po4a-translate
49+
50+
# ex: filetype=sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
po4a-display-pod
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# bash completion for po4a(7) utilities. -*- shell-script -*-
2+
# this file provides completion for po4a-display-pod and po4a-display-man
3+
4+
_comp_cmd_po4a_scripts() {
5+
local cur prev words cword comp_args
6+
_comp_initialize -- "$@" || return
7+
8+
if [[ $cur == -* ]]; then
9+
COMPREPLY=( $( compgen -W '-m -o -p' -- "$cur" ) )
10+
return
11+
fi
12+
13+
_filedir
14+
} && complete -F _comp_cmd_po4a_scripts po4a-display-pod po4a-display-man
15+
16+
# ex: filetype=sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
po4a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
po4a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
po4a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
po4a

0 commit comments

Comments
 (0)