-
Notifications
You must be signed in to change notification settings - Fork 122
/
xsos-bash-completion.bash
96 lines (80 loc) · 3.27 KB
/
xsos-bash-completion.bash
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
# This file is part of xsos, providing intelligent xsos tab-completion for BASH
# Save it to: /etc/bash_completion.d/
#
# Revision date: 2015/07/11 matching up with xsos v0.7.x
# Latest version: <http://github.com/ryran/xsos>
#
# Copyright 2013, 2015 Ryan Sawhill Aroha <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License <gnu.org/licenses/gpl.html> for more details.
#
#-------------------------------------------------------------------------------
_xsos() {
# Variables
local curr prev shrtopts longopts
# Wipe out COMPREPLY array
COMPREPLY=()
# Set cur & prev appropriately
curr=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# Short and long options
shrtopts="-h -V
-a -b -o -k -c -f -m -d -t -l -e -r -n -g -i -s -p -S -F -I -N
-6 -q -u -v -w
-x -y -z"
longopts="--help --version
--all --bios --os --kdump --cpu --intrupt --mem --disks --mpath --lspci --ethtool --softirq --netdev --bonding --ip --net --sysctl --ps -ss --firewall --ifcfg --netstat
--B --C --F --M --D --T --L --R --N --G --I --P
--scrub --ipv6 --wwid --unit --threads --verbose --width
--nocolor --less --more"
# Check previous arg to see if we need to do anything special
case "$prev" in
# Disable autocompletion for solo options that can only be run alone
-h|--help|-V|--version)
return 0
;;
# These special opts require filenames as arguments
--B|--C|--F|--M|--D|--T|--L|--R|--N|--G|--I|--P)
compopt -o plusdirs # Important!
COMPREPLY=( $(compgen -f -- "$curr") )
return 0
;;
# For unit, choices are b-t
-u|--unit)
COMPREPLY=( $(compgen -W "b k m g t" -- "$curr") )
return 0
;;
# For verbosity, choices are 0-4
-v|--verbose)
COMPREPLY=( $(compgen -W "0 1 2 3 4" -- "$curr") )
return 0
;;
# For width, choices are w, 0, or any number
-w|--width)
COMPREPLY=( $(compgen -W "w 0" -- "$curr") )
return 0
esac
# Now that we've made it past the options that require args,
# we can enable directory completion
compopt -o plusdirs
if [[ $curr == --* ]]; then
# If current arg starts w/2 dashes, attempt to autocomplete long opts
COMPREPLY=( $(compgen -W "$longopts" -- "$curr") )
return 0
elif [[ $curr == -* ]]; then
# Otherwise, if current only starts w/1 dash, attempt autocomplete short opts
COMPREPLY=( $(compgen -W "$shrtopts" -- "$curr") )
return 0
fi
}
# Add the names of any xsos aliases (or alternate file-names) to the end of the following line
# (And remove "x" if you have an "x" command that *isn't* an alias for xsos)
complete -F _xsos xsos x