Debian Codegraph @

bash-completion/dcut.bash

raw
1 # bash-completion/dcut.bash
2 # Programmable Bash command completion for ‘dcut’ command.
3 # See the Bash manual “Programmable Completion” section.
4 #
5 # This is free software, and you are welcome to redistribute it under
6 # certain conditions; see the end of this file for copyright
7 # information, grant of license, and disclaimer of warranty.
8
9 _have dcut &&
10 _dcut () {
11 COMPREPLY=()
12
13 local cur="${COMP_WORDS[COMP_CWORD]}"
14 local prev="${COMP_WORDS[COMP_CWORD-1]}"
15 local -a options=(
16 --host
17 -O --output
18 -P --passive
19 -U --upload
20 -c --config
21 -d --debug
22 -h --help
23 -i --input
24 -k --keyid
25 -m --maintaineraddress
26 -s --simulate
27 -v --version
28 )
29
30 local -a config_files=(
31 "${XDG_CONFIG_HOME:-$HOME/.config}/dput/dput.cf"
32 "$HOME/.dput.cf"
33 "/etc/dput.cf"
34 )
35 local -a hosts
36 readarray -t hosts < <( {
37 grep --no-filename "^\[.*\]" "${config_files[@]}" \
38 2> /dev/null \
39 | tr --delete '[]' || /bin/true
40 } | grep --invert-match '^DEFAULT$' | sort --unique )
41
42 local -a queue_commands=(
43 cancel
44 reschedule
45 rm
46 )
47
48 case "$prev" in
49 -c|--config)
50 readarray -t COMPREPLY < <( compgen -G "${cur}*" )
51 compopt -o filenames
52 compopt -o plusdirs
53 ;;
54 -k|--keyid)
55 # FIXME: gathering the secret keys can typically take
56 # several seconds by this method. Is there a faster way to
57 # reliably present the current user's secret key IDs?
58 local -a keyids
59 readarray -t keyids < <(
60 gpg --list-secret-keys --with-colons \
61 2> /dev/null \
62 | grep '^sec' | cut --delimiter ':' --fields 5 \
63 | sort --unique
64 )
65 readarray -t COMPREPLY < <( compgen -W "${keyids[*]}" -- "$cur" )
66 ;;
67 -m|--maintaineraddress)
68 # We have no useful completion for an email address.
69 ;;
70 -i|--input)
71 readarray -t COMPREPLY < <( compgen -G "${cur}*.changes" )
72 compopt -o filenames
73 compopt -o plusdirs
74 ;;
75 -U|--upload|-O|--output)
76 readarray -t COMPREPLY < <( compgen -G "${cur}*.commands" )
77 compopt -o filenames
78 compopt -o plusdirs
79 ;;
80 --host)
81 readarray -t COMPREPLY < <( compgen -W "${hosts[*]}" -- "$cur" )
82 ;;
83 ',')
84 readarray -t COMPREPLY < <(
85 compgen -W "${queue_commands[*]}" -- "$cur"
86 )
87 ;;
88 *)
89 readarray -t COMPREPLY < <(
90 compgen -W "${hosts[*]}" -- "$cur"
91 compgen -W "${queue_commands[*]}" -- "$cur"
92 compgen -W "${options[*]}" -- "$cur"
93 )
94 ;;
95 esac
96
97 return 0
98
99 } && complete -F _dcut dcut
100
101
102 # Copyright © 2015–2026 Ben Finney <[email protected]>
103 # Copyright © 2002 Roland Mas <[email protected]>
104 #
105 # This is free software: you may copy, modify, and/or distribute this work
106 # under the terms of the GNU General Public License as published by the
107 # Free Software Foundation; version 3 of that license or any later version.
108 # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details.
109
110 # Local variables:
111 # coding: utf-8
112 # mode: shell-script
113 # End:
114 # vim: fileencoding=utf-8 filetype=bash :