File: wajig.bash

package info (click to toggle)
wajig 4.1.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 408 kB
  • sloc: python: 2,553; makefile: 146; sh: 117
file content (145 lines) | stat: -rw-r--r-- 5,825 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
_have grep-status && {
_comp_dpkg_installed_packages()
{
    grep-status -P -e "^$1" -a -FStatus 'install ok installed' -n -s Package
}
} || {
_comp_dpkg_installed_packages()
{
    command grep -A 1 "Package: $1" /var/lib/dpkg/status | \
        command grep -B 1 -Ee "ok installed|half-installed|unpacked| \
            half-configured" \
            -Ee "^Essential: yes" | \
        command grep "Package: $1" | cut -d\  -f2
}
}

_have grep-status && {
_comp_dpkg_hold_packages()
{
    grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package
}
} || {
_comp_dpkg_hold_packages()
{
    command grep -B 2 'hold' /var/lib/dpkg/status | \
        command grep "Package: $1" | cut -d\  -f2
}
}

_have wajig &&
_wajig()
{
    local cur dashoptions prev special i

    COMPREPLY=()
    _get_comp_words_by_ref cur prev

    dashoptions='-h --help -V --version'

    for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
        if [[ ${COMP_WORDS[i]} == \
			       @(addcdrom|add-cdrom|addgroup|add-group|addkey|add-key|addrepo|aptlog|autoalts|autoclean|auto-clean|\
autodownload|autoremove|build|\
builddeps|changelog|clean|commands|contents|dailyupgrade|dependents|describe|describenew|detail|details|\
distupgrade|download|editsources|extract|fixconfigure|fixinstall|fixmissing|force|hold|\
info|init|install|installsuggested|integrity|large|lastupdate|listall|listalternatives|listcache|\
listdaemons|listfiles|listhold|listinstalled|listlog|listnames|listpackages|listscripts|listsection|\
listsections|liststatus|localupgrade|madison|move|new|newdetail|news|nonfree|orphans|passwords|policy|\
purge|purgeorphans|purgeremoved|rbuilddeps|readme|reboot|recdownload|recommended|reconfigure|\
reinstall|reload|remove|removeorphans|repackage|reportbug|repos|restart|rmrepo|rpm2deb|\
rpminstall|safeupgrade|safe-upgrade|search|\
searchapt|show|sizes|snapshot|source|start|status|stop|sysinfo|tasksel|todo|toupgrade|\
tutorial|unhold|unofficial|update|updatealternatives|updatepciids|updateusbids|upgrade|upgradesecurity|\
verify|version|versions|whichpackage) ]];
         then special=${COMP_WORDS[i]}
        fi
    done

    if [[ -n "$special" ]]; then
       case $special in
           install|distupgrade|download|show|changelog|builddeps|dependents|describe|detail|details|policy|recdownload|source)
               COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
               if [[ "$special" == "install" ]]; then
                   _filedir
               fi
               return 0
               ;;
           purge|remove|reinstall|listinstalled|hold|news|readme|recommended|reconfigure|repackage|todo|verify)
               COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
               return 0
               ;;
           reload|*start|status|stop)
               _services "$cur"
               return 0
               ;;
           unhold)
               COMPREPLY=( $( _comp_dpkg_hold_packages "$cur" ) )
               return 0
               ;;
           contents|extract|info|rpm2deb|rpminstall)
               _filedir
               ;;
       esac
    fi

    case $prev in
        # don't complete anything if these options are found
        autoclean|clean|search|upgrade|update)
            return 0
            ;;
        -S)
            _filedir
            return 0
            ;;
    esac

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $( compgen -W "$dashoptions" -- "$cur" ) )
    elif [[ -z "$special" ]]; then

	# 20241204 gjw Add general commands here to have them complete
	# in bash. This is manually updated and so some commands are
	# missing. Also the - versions were not included and are
	# gradually being added, manually as requested in
	# https://github.com/gjwgit/wajig/issues/21. This could surely
	# be automated but for now manually update as I notice they
	# are missing or requested to do so through the issue. The
	# following will list the dashed aliases:
	#
	# grep alias wajig/__init__.py
	#
	# Bound to be a better way but need time to research/review.
	
        commands=(addcdrom add-cdrom addgroup add-group addkey add-key addrepo aptlog
		  autoalts autoclean auto-clean autodownload auto-download autoremove build builddeps
                  changelog clean commands contents dailyupgrade dependents describe
                  describenew detail details distupgrade dist-upgrade download editsources edit-sources
		  extract fixconfigure fix-configure fixinstall fix-install
                  fixmissing fix-missing force hold info init install installsuggested integrity large lastupdate
                  listall listalternatives listcache listdaemons listfiles listhold listinstalled
                  listlog listnames listpackages listscripts listsection listsections liststatus
                  localupgrade madison move new newdetail news nonfree orphans passwords policy
		  purge purgeorphans purge-orphans
                  purgeremoved purge-removed rbuilddeps readme reboot recdownload recommended reconfigure reinstall
                  reload remove removeorphans repackage reportbug repos restart rmrepo rpm2deb rpminstall
		  safeupgrade safe-upgrade search
                  searchapt show sizes snapshot source start status stop sysinfo tasksel
                  todo toupgrade tutorial unhold unofficial update updatealternatives updatepciids
                  updateusbids upgrade upgradesecurity verify version versions whichpackage)

        local option oldNoCaseMatch=$(shopt -p nocasematch)
        shopt -s nocasematch
        COMPREPLY=( $( for command in "${commands[@]}"; do
                [[ ${command:0:${#cur}} == "$cur" ]] && printf '%s\n' $command
                done ) )
        eval "$oldNoCaseMatch" 2> /dev/null
    fi

    return 0
}
complete -F _wajig wajig

# Local variables:
# mode: shell-script
# End: