aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-06-11 11:32:21 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-06-11 11:32:21 +1200
commitbd67e60f00bf5deb75b402adc1c71f36a8180735 (patch)
treeaade6f8618019143a32985f1bff82efa27cfc6a1 /bash
parentCheck for ~/.reminders (diff)
downloaddotfiles-bd67e60f00bf5deb75b402adc1c71f36a8180735.tar.gz
dotfiles-bd67e60f00bf5deb75b402adc1c71f36a8180735.zip
Some completion for sudo(8) and sudoedit(8)
Imperfect but covers 99.9% of my use cases (selecting users/groups, mostly)
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/sudo.bash26
-rw-r--r--bash/bashrc.d/sudoedit.bash21
2 files changed, 47 insertions, 0 deletions
diff --git a/bash/bashrc.d/sudo.bash b/bash/bashrc.d/sudo.bash
index 41a97a9e..df2abcc1 100644
--- a/bash/bashrc.d/sudo.bash
+++ b/bash/bashrc.d/sudo.bash
@@ -7,3 +7,29 @@ sudo() {
fi
}
+# Some imperfect but mostly-useful sudo(8) completion
+_sudo() {
+ word=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # Completion for this word depends on the previous word
+ case $prev in
+
+ # If the previous word was an option for -g, complete with group names
+ -*g)
+ COMPREPLY=( $(compgen -A group -- "$word") )
+ ;;
+
+ # If the previous word was an option for -u, complete with user names
+ -*u)
+ COMPREPLY=( $(compgen -A user -- "$word") )
+ ;;
+
+ # Otherwise complete with commands
+ *)
+ COMPREPLY=( $(compgen -A command -- "$word") )
+ ;;
+ esac
+}
+complete -F _sudo -o default sudo
+
diff --git a/bash/bashrc.d/sudoedit.bash b/bash/bashrc.d/sudoedit.bash
new file mode 100644
index 00000000..a13f484e
--- /dev/null
+++ b/bash/bashrc.d/sudoedit.bash
@@ -0,0 +1,21 @@
+# Some imperfect but mostly-useful sudoedit(8) completion
+_sudoedit() {
+ word=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # Completion for this word depends on the previous word
+ case $prev in
+
+ # If the previous word was an option for -g, complete with group names
+ -*g)
+ COMPREPLY=( $(compgen -A group -- "$word") )
+ ;;
+
+ # If the previous word was an option for -u, complete with user names
+ -*u)
+ COMPREPLY=( $(compgen -A user -- "$word") )
+ ;;
+ esac
+}
+complete -F _sudoedit -o default sudoedit
+