Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Unified Diff: gclient_completion.sh

Issue 100463007: Added basic completion (the commands) for gclient. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Let complete use the defaults unless using the help command. Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_completion.sh
diff --git a/gclient_completion.sh b/gclient_completion.sh
new file mode 100644
index 0000000000000000000000000000000000000000..2c8b5dfa338dba38dbac28a3dddcbe3df445d341
--- /dev/null
+++ b/gclient_completion.sh
@@ -0,0 +1,42 @@
+# Run from either local inclusion or /etc/bash_completions.d
bradn 2014/01/07 02:04:49 So I don't have "have" on my goobuntu system. I as
Sheridan Rawlins 2014/01/16 03:48:26 Ok, I realize that installation into /etc/bash_com
+declare -f have >/dev/null && have gclient || return
+
+__gclient_commands () {
+ gclient -h | grep -P '(?<= (?:\x1b)\[32m)([\w\d]+)' -o
bradn 2014/01/07 02:04:49 It looks like these terminal codes can vary depend
Sheridan Rawlins 2014/01/16 01:12:59 Added "update" manually, and used sed instead of g
bradn 2014/01/16 04:48:48 I think so.
+}
+
+__gclient_compute_all_commands () {
+ test -n "$__gclient_all_commands" ||
+ __gclient_all_commands=$(__gclient_commands)
+}
+
+# Passthrough to git completion
bradn 2014/01/07 02:04:49 Huh?
Sheridan Rawlins 2014/01/16 03:48:26 Improved comment - basically just aliased so that
+_gclient_fetch=_git_fetch
+
+_gclient () {
+ local cur prev words cword
+ _get_comp_words_by_ref -n =: cur prev words cword
+
+ local i c=1 command
+ while [ $c -lt $cword ]; do
+ i="${words[$c]}"
+ case "$i" in
+ -*) : ignore options ;;
bradn 2014/01/07 02:04:49 This hangs for me when there are flags, should tha
Sheridan Rawlins 2014/01/16 03:48:26 Wow copied from git-completion.bash, but forgot th
+ *) command="$i"; break ;;
+ esac
+ done
+
+ local completion_func="_gclient_${command//-/_}"
+ local -f $completion_func >/dev/null && $completion_func && return
+
+ case "$command" in
+ ""|help)
+ if [[ "$command" != help || "$cword" -le 2 ]]; then
bradn 2014/01/07 02:04:49 Maybe a comment explaining this is so gclient help
Sheridan Rawlins 2014/01/16 03:48:26 Done.
+ __gclient_compute_all_commands
+ COMPREPLY=($(compgen -W "$__gclient_all_commands" $cur))
+ fi
+ ;;
+ *) : just use the default ;;
+ esac
+} &&
+complete -F _gclient -o default gclient
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698