Debian Codegraph @

contrib/pkgcli

raw
1 #
2 # bash completion support for PackageKit's console commands.
3 #
4 # Copyright (C) 2007 James Bowes <[email protected]>
5 # Copyright (C) 2010 Richard Hughes <[email protected]>
6 # Copyright (C) 2025 Matthias Klumpp <[email protected]>
7 #
8 # Licensed under the GNU General Public License Version 2
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # To use the completion:
16 # 1. Copy this file somewhere (e.g. ~/.pk-completion.sh).
17 # 2. Add the following line to your .bashrc:
18 # source ~/.pk-completion.sh
19
20
21 __pkgcli_commandlist="
22 backend
23 history
24 search
25 list
26 show
27 list-depends
28 list-requiring
29 what-provides
30 files
31 list-updates
32 show-update
33 resolve
34 organization
35 show-os-upgrade
36 last-time
37 refresh
38 install
39 remove
40 update
41 upgrade
42 download
43 offline-update
44 install-sig
45 repair
46 quit
47 repo-list
48 repo-enable
49 repo-disable
50 repo-remove
51 monitor
52 "
53
54 __pkgclicomp ()
55 {
56 local all c s=$'\n' IFS=' '$'\t'$'\n'
57 local cur="${COMP_WORDS[COMP_CWORD]}"
58 if [ $# -gt 2 ]; then
59 cur="$3"
60 fi
61 for c in $1; do
62 case "$c$4" in
63 *.) all="$all$c$4$s" ;;
64 *) all="$all$c$4 $s" ;;
65 esac
66 done
67 IFS=$s
68 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
69 return
70 }
71
72 _pkgcli_search ()
73 {
74 local i c=1 command
75 while [ $c -lt $COMP_CWORD ]; do
76 i="${COMP_WORDS[c]}"
77 case "$i" in
78 name|details|group|file)
79 command="$i"
80 break
81 ;;
82 esac
83 c=$((++c))
84 done
85
86 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
87 __pkgclicomp "name details group file"
88 fi
89 return
90 }
91
92 _pkgcli ()
93 {
94 local i c=1 command
95
96 while [ $c -lt $COMP_CWORD ]; do
97 i="${COMP_WORDS[c]}"
98 case "$i" in
99 --version|--help|--verbose|-v|-n|-h|-?) ;;
100 *) command="$i"; break ;;
101 esac
102 c=$((++c))
103 done
104
105 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
106 case "${COMP_WORDS[COMP_CWORD]}" in
107 --*=*) COMPREPLY=() ;;
108 --*) __pkgclicomp "
109 --version
110 --filter
111 --verbose
112 --help
113 "
114 ;;
115 -*) __pkgclicomp "
116 -v
117 -n
118 -h
119 -?
120 --version
121 --verbose
122 --help
123 --filter
124 "
125 ;;
126 *) __pkgclicomp "$__pkgcli_commandlist" ;;
127 esac
128 return
129 fi
130
131 case "$command" in
132 search) _pkgcli_search ;;
133 *) COMPREPLY=() ;;
134 esac
135 }
136
137 complete -o default -o nospace -F _pkgcli pkgcli