added completion for build/install that checks the whole sbo repository, takes some...
[slackrepo-completion.git] / slackrepo.completion
1 # bash completion for slackrepo(8) -*- shell-script -*-
2
3 _slackrepo() {
4
5 local confdir="/etc/slackrepo"
6 local userconffile="${HOME}/.slackreporc"
7
8 local cur prev words cword
9 _init_completion -n = || return
10
11 local split=false
12 if [[ "$cur" == -?*=* ]]; then
13 prev="${cur%%?(\\)=*}"
14 cur="${cur#*=}"
15 split=true
16 fi
17
18 case "$prev" in
19 --repo)
20 COMPREPLY+=( $(cd ${confdir}; compgen -d -- "$cur") )
21 return
22 ;;
23 --color)
24 COMPREPLY+=( $(compgen -W 'always auto no' -- "$cur") )
25 return
26 ;;
27 --nice)
28 # Requires a value but we can't suggest it
29 return
30 ;;
31 esac
32
33 $split && return
34
35 if [[ "$cur" == -* ]]; then
36 compopt -o nospace
37 COMPREPLY=( $(compgen -W '--repo= --dry-run --install --chroot --lint -v --verbose
38 -vv --very-verbose --keep-tmp --color= --nice=' -- "$cur") )
39 return
40 fi
41
42 local i action
43 for (( i=1; i<${#words[@]}; i++ )); do
44 if [[ "${words[i]}" != -* ]]; then
45 action="${words[i]}"
46 break
47 fi
48 done
49
50 [[ -r "$userconffile" ]] || return
51 . "$userconffile"
52
53 local SLACKBUILDS="/var/lib/slackrepo/${REPO}/slackbuilds"
54
55 case "$action" in
56 build | install )
57 # we should provide a list of packages or whole directories that might be built
58 # but I don't know if its feasible to scan the whole sbo repository for suggestions
59 # so I'll limit to categories
60 COMPREPLY+=( $(cd ${SLACKBUILDS}; compgen -d -- "$cur") )
61 COMPREPLY+=( $(cd ${SLACKBUILDS}; compgen -W "$(find . -type f -name '*.SlackBuild' -exec basename '{}' .SlackBuild \; )" -- "$cur" ) )
62 return
63 ;;
64 rebuild )
65 # here we provide a list of packages or whole directories in our local repository
66 COMPREPLY+=( $(cd ${PKGREPO}; compgen -d -- "$cur") )
67 COMPREPLY+=( $( grep 'txz$' ${PKGREPO}/FILELIST.TXT |rev |cut -f1 -d\ |cut -f1 -d/ |cut -f4- -d- |rev | command grep "^$cur") )
68 return
69 ;;
70 update )
71 # we should provide a list of packages or whole directories that might be updated
72 COMPREPLY+=( $(cd ${PKGREPO}; compgen -d -- "$cur") )
73 COMPREPLY+=( $( grep 'txz$' ${PKGREPO}/FILELIST.TXT |rev |cut -f1 -d\ |cut -f1 -d/ |cut -f4- -d- |rev | command grep "^$cur") )
74 return
75 ;;
76 remove )
77 # here we only provide packages that are already in our repository
78 COMPREPLY+=( $( grep 'txz$' ${PKGREPO}/FILELIST.TXT |rev |cut -f1 -d\ |cut -f1 -d/ |cut -f4- -d- |rev | command grep "^$cur") )
79 return
80 ;;
81 revert )
82 # we should provide a list of packages that might be reverted from backup
83 # in order to revert we check for the existance of a backup first
84 if [[ -e $PKGBACKUP ]]; then
85 COMPREPLY=( $(cd "$PKGBACKUP"; compgen -W "$(find . -type f -name '*.txz' -exec basename '{}' \; |rev |cut -f4- -d- |rev)" -- "$cur") )
86 fi
87 return
88 ;;
89 * )
90 COMPREPLY+=( $(compgen -W 'build rebuild update install remove revert' -- "$cur") )
91 return
92 ;;
93 esac
94
95 }
96
97 complete -F _slackrepo slackrepo
98
99 # ex: filetype=sh