Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
59 - 1
# Completions for tools included in util-linux (not necessarily Linux specific)
2
 
3
# renice(8) completion
4
#
5
have renice &&
6
_renice()
7
{
8
    local command cur curopt i
9
 
10
    COMPREPLY=()
11
    _get_comp_words_by_ref cur
12
    command=$1
13
 
14
    i=0
15
    # walk back through command line and find last option
16
    while [[ $i -le $COMP_CWORD && ${#COMPREPLY[@]} -eq 0 ]]; do
17
        curopt=${COMP_WORDS[COMP_CWORD-$i]}
18
        case "$curopt" in
19
            -u)
20
                _allowed_users
21
                ;;
22
            -g)
23
                _pgids
24
                ;;
25
            -p|$command)
26
                _pids
27
                ;;
28
        esac
29
        i=$(( ++i ))
30
    done
31
} &&
32
complete -F _renice renice
33
 
34
# kill(1) completion
35
#
36
have kill &&
37
_kill()
38
{
39
    local cur
40
 
41
    COMPREPLY=()
42
    _get_comp_words_by_ref cur
43
 
44
    if [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then
45
        # return list of available signals
46
        _signals
47
    else
48
        # return list of available PIDs
49
        _pids
50
    fi
51
} &&
52
complete -F _kill kill
53
 
54
# look(1) completion
55
#
56
have look &&
57
_look()
58
{
59
    local cur
60
 
61
    COMPREPLY=()
62
    _get_comp_words_by_ref cur
63
 
64
    if [ $COMP_CWORD = 1 ]; then
65
        COMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur" ) )
66
    fi
67
} &&
68
complete -F _look -o default look
69
 
70
# Local variables:
71
# mode: shell-script
72
# sh-basic-offset: 4
73
# sh-indent-comment: t
74
# indent-tabs-mode: nil
75
# End:
76
# ex: ts=4 sw=4 et filetype=sh
77
 
78
# chsh(1) completion
79
 
80
_chsh()
81
{
82
    local cur prev
83
 
84
    COMPREPLY=()
85
    _get_comp_words_by_ref cur prev
86
 
87
    case $prev in
88
        --list-shells|--help|-v|--version)
89
            return 0
90
            ;;
91
        -s|--shell)
92
            _shells
93
            return 0
94
            ;;
95
    esac
96
 
97
    if [[ "$cur" == -* && "$( uname -s )" == @(Linux|GNU|GNU/*) ]]; then
98
        COMPREPLY=( $( compgen -W '--shell --list-shells --help --version' \
99
            -- "$cur" ) )
100
    else
101
        COMPREPLY=( $( compgen -u -- "$cur" ) )
102
    fi
103
 
104
    return 0
105
}
106
complete -F _chsh chsh
107
 
108
# Local variables:
109
# mode: shell-script
110
# sh-basic-offset: 4
111
# sh-indent-comment: t
112
# indent-tabs-mode: nil
113
# End:
114
# ex: ts=4 sw=4 et filetype=sh
115
 
116
# mount(8) completion. This will pull a list of possible mounts out of
117
# /etc/{,v}fstab, unless the word being completed contains a ':', which
118
# would indicate the specification of an NFS server. In that case, we
119
# query the server for a list of all available exports and complete on
120
# that instead.
121
#
122
have mount &&
123
{
124
 
125
# Just like COMPREPLY=(`compgen -W "${COMPREPLY[*]}" -- "$cur"`), only better!
126
#
127
# This will correctly escape special characters in COMPREPLY.
128
_reply_compgen_array()
129
{
130
    # Create the argument for compgen -W by escaping twice.
131
    #
132
    # One round of escape is because we want to reply with escaped arguments. A
133
    # second round is required because compgen -W will helpfully expand it's
134
    # argument.
135
    local i wlist
136
    for i in ${!COMPREPLY[*]}; do
137
        local q=$(quote "$(printf %q "${COMPREPLY[$i]}")")
138
        wlist+=$q$'\n'
139
    done
140
 
141
    # We also have to add another round of escaping to $cur.
142
    local ecur="$cur"
143
    ecur="${ecur//\\/\\\\}"
144
    ecur="${ecur//\'/\'}"
145
 
146
    # Actually generate completions.
147
    local oldifs=$IFS
148
    IFS=$'\n' eval 'COMPREPLY=(`compgen -W "$wlist" -- "${ecur}"`)'
149
    IFS=$oldifs
150
}
151
 
152
# Unescape strings in the linux fstab(5) format (with octal escapes).
153
__linux_fstab_unescape() {
154
    eval $1="'${!1//\'/\047}'"
155
    eval $1="'${!1/%\\/\\\\}'"
156
    eval "$1=$'${!1}'"
157
}
158
 
159
# Complete linux fstab entries.
160
#
161
# Reads a file from stdin in the linux fstab(5) format; as used by /etc/fstab
162
# and /proc/mounts.
163
_linux_fstab()
164
{
165
    COMPREPLY=()
166
 
167
    # Read and unescape values into COMPREPLY
168
    local fs_spec fs_file fs_other
169
    local oldifs="$IFS"
170
    while read -r fs_spec fs_file fs_other; do
171
        if [[ $fs_spec = [#]* ]]; then continue; fi
172
        if [[ $1 == -L ]]; then
173
            local fs_label=${fs_spec/#LABEL=}
174
            if [[ $fs_label != "$fs_spec" ]]; then
175
                __linux_fstab_unescape fs_label
176
                IFS=$'\0'
177
                COMPREPLY+=("$fs_label")
178
                IFS=$oldifs
179
            fi
180
        else
181
            __linux_fstab_unescape fs_spec
182
            __linux_fstab_unescape fs_file
183
            IFS=$'\0'
184
            [[ $fs_spec = */* ]] && COMPREPLY+=("$fs_spec")
185
            [[ $fs_file = */* ]] && COMPREPLY+=("$fs_file")
186
            IFS=$oldifs
187
        fi
188
    done
189
 
190
    _reply_compgen_array
191
}
192
 
193
_mount()
194
{
195
    local cur sm host prev
196
 
197
    COMPREPLY=()
198
    _get_comp_words_by_ref -n : cur prev
199
 
200
    case $prev in
201
        -t|--types)
202
            _fstypes
203
            return 0
204
            ;;
205
    esac
206
 
207
    [[ "$cur" == \\ ]] && cur="/"
208
 
209
    if [[ "$cur" == *:* ]]; then
210
        for sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount; do
211
            [ -x "$sm" ] || continue
212
            COMPREPLY=( $( compgen -W "$( "$sm" -e ${cur%%:*} | \
213
                awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) )
214
            return 0
215
        done
216
    fi
217
 
218
    if [[ "$cur" == //* ]]; then
219
        host=${cur#//}
220
        host=${host%%/*}
221
        if [ -n "$host" ]; then
222
            COMPREPLY=( $( compgen -P "//$host" -W \
223
                "$( smbclient -d 0 -NL $host 2>/dev/null |
224
                sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
225
                sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|/\1|p' )" \
226
                    -- "${cur#//$host}" ) )
227
        fi
228
    elif [ -r /etc/vfstab ]; then
229
        # Solaris
230
        COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) )
231
    elif [ ! -e /etc/fstab ]; then
232
        # probably Cygwin
233
        COMPREPLY=( $( compgen -W "$( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) )
234
    else
235
        # probably Linux
236
        if [ "$prev" = -L ]; then
237
            _linux_fstab -L < /etc/fstab
238
        elif [ "$prev" = -U ]; then
239
            COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
240
        else
241
            _linux_fstab < /etc/fstab
242
        fi
243
    fi
244
 
245
    return 0
246
} &&
247
complete -F _mount -o default -o dirnames mount
248
 
249
# umount(8) completion. This relies on the mount point being the third
250
# space-delimited field in the output of mount(8)
251
#
252
have umount &&
253
_umount()
254
{
255
    local cur
256
    _get_comp_words_by_ref cur
257
    COMPREPLY=()
258
 
259
    if [[ $(uname -s) = Linux && -r /proc/mounts ]]; then
260
        # Linux /proc/mounts is properly quoted. This is important when
261
        # unmounting usb devices with pretty names.
262
        _linux_fstab < /proc/mounts
263
    else
264
        local IFS=$'\n'
265
        COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- "$cur" ) )
266
    fi
267
 
268
    return 0
269
} &&
270
complete -F _umount -o dirnames umount
271
 
272
}
273
 
274
# Local variables:
275
# mode: shell-script
276
# sh-basic-offset: 4
277
# sh-indent-comment: t
278
# indent-tabs-mode: nil
279
# End:
280
# ex: ts=4 sw=4 et filetype=sh
281
 
282
# bash completion for rtcwake
283
 
284
have rtcwake &&
285
_rtcwake()
286
{
287
    COMPREPLY=()
288
    local cur prev split=false
289
    _get_comp_words_by_ref cur prev
290
 
291
    _split_longopt && split=true
292
 
293
    case "$prev" in
294
        --help|-h|--version|-V|--seconds|-s|--time|-t)
295
            return 0
296
            ;;
297
        --mode|-m)
298
            COMPREPLY=( $( compgen -W 'standby mem disk on no off' -- "$cur" ) )
299
            return 0
300
            ;;
301
        --device|-d)
302
            COMPREPLY=( $( command ls -d /dev/rtc?* 2>/dev/null ) )
303
            COMPREPLY=( $( compgen -W '${COMPREPLY[@]#/dev/}' -- "$cur" ) )
304
            return 0
305
            ;;
306
    esac
307
 
308
    $split && return 0
309
 
310
    COMPREPLY=( $( compgen -W '--device --local --mode --seconds --time --utc \
311
        --verbose --version --help' -- "$cur" ) )
312
} &&
313
complete -F _rtcwake rtcwake
314
 
315
# Local variables:
316
# mode: shell-script
317
# sh-basic-offset: 4
318
# sh-indent-comment: t
319
# indent-tabs-mode: nil
320
# End:
321
# ex: ts=4 sw=4 et filetype=sh