aboutsummaryrefslogtreecommitdiffhomepage
path: root/make_mercurial_completions.fish
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2007-01-26 01:34:52 +1000
committerGravatar axel <axel@liljencrantz.se>2007-01-26 01:34:52 +1000
commitcc6f133368d20d35ec557975e48c2d29d5548e56 (patch)
tree0ce888ee5414e47e6e1e85d80836d2b4a513490d /make_mercurial_completions.fish
parent350b637a1afb39b9d7a20eed9e30c57b2e2120ee (diff)
make the make_mercurial_completions.fish script able to handle svn as well. Update svn completions.
darcs-hash:20070125153452-ac50b-60dce711d8614f99ba24ab9b24acfbd879d58bfa.gz
Diffstat (limited to 'make_mercurial_completions.fish')
-rwxr-xr-x[-rw-r--r--]make_mercurial_completions.fish129
1 files changed, 118 insertions, 11 deletions
diff --git a/make_mercurial_completions.fish b/make_mercurial_completions.fish
index 50b854c5..4a9aaf8d 100644..100755
--- a/make_mercurial_completions.fish
+++ b/make_mercurial_completions.fish
@@ -1,20 +1,80 @@
+#!/usr/bin/env fish
+
+#
+# This file produces command specific completions for either hg or darcs
+#
+
+function cap
+ set res (echo $argv |cut -c 1|tr a-z A-Z)(echo $argv |cut -c 2-)
+ echo $res
+end
+
+function esc
+ echo $argv | sed -e "s/'/\\\'/g"
+end
+
+
+set cmd $argv[1]; or exit 1
+
echo '
#
-# Completions for the hg command (Mercurial)
+# Completions for the '$cmd' command
# This file was autogenerated by the file make_mercurial_completions.fish
# which is shipped with the fish source code
#
#
+# Completions from commandline
+#
+'
+set -e argv[1]
+
+while count $argv >/dev/null
+ echo $argv[1]
+ set -e argv[1]
+end
+
+
+echo '
+#
# subcommands
#
'
-set -l cmd (hg help | sed -n -e 's/^ \([^ ][^ ]*\) *\([^ ].*\)$/-a \1 --description \'\2\'/p')
+eval "function cmd; $cmd \$argv; end"
+
+set -l cmd_str
+
+switch $cmd
+ case svn
-printf "complete -c hg -n '__fish_use_subcommand' -x %s\n" $cmd
+ function list_subcommand
+ set cmd1 '\([^ ]*\)'
+ set cmd2 '\([^,)]*\)'
+ set cmdn '\(, \([^,)]*\)\|\)'
+ set svn_re '^ *'$cmd1'\( ('$cmd2$cmdn$cmdn')\|\).*$'
+ cmd help|sed -ne 's/'$svn_re'/\1\n\3\n\5\n\7/p'| grep .
+ end
-for i in (hg help | sed -n -e 's/^ \([^ ][^ ]*\) .*$/\1/p')
+
+ for i in (list_subcommand)
+ set desc (cmd help $i|head -n 1|sed -e 's/[^:]*: *\(.*\)$/\1/')
+ set desc (esc $desc)
+ set cmd_str $cmd_str "-a $i --description '$desc'"
+ end
+
+ case '*'
+
+ function list_subcommand
+ cmd help | sed -n -e 's/^ *\([^ ][^ ]*\) .*$/\1/p'
+ end
+ set cmd_str (cmd help | sed -n -e 's/^ *\([^ ][^ ]*\)[\t ] *\([^ ].*\)$/-a \1 --description \'\2\'/p')
+
+end
+
+printf "complete -c $cmd -n '__fish_use_subcommand' -x %s\n" $cmd_str
+
+for i in (list_subcommand)
echo '
@@ -22,16 +82,63 @@ for i in (hg help | sed -n -e 's/^ \([^ ][^ ]*\) .*$/\1/p')
# Completions for the \''$i'\' subcommand
#
'
+ set -l cmd_str "complete -c $cmd -n 'contains $i (commandline -poc)' %s\n"
- set -l sw1 (hg help $i | sed -n -e 's/^ *-\(.\) *--\([^ ]*\) *\([^ ].*\)$/-s \1 -l \2 --description \'\3\'/p' )
- if count $sw1 >/dev/null
- printf "complete -c hg %s\n" $sw1
- end
+ set short_exp '\(-.\|\)'
+ set long_exp '--\([^ =,]*\)'
+ set arg_exp '\(\|[= ][^ ][^ ]*\)'
+ set desc_exp '\([\t ]*:[\t ]*\|\)\([^ ].*\)'
+ set re "^ *$short_exp *$long_exp$arg_exp *$desc_exp\$"
+
+ for j in (cmd help $i | sed -n -e 's/'$re'/\1\t\2\t\3\t\5/p')
+ set exploded (echo $j|tr \t \n)
+ set short $exploded[1]
+ set long $exploded[2]
+ set arg $exploded[3]
+ set desc (cap (esc $exploded[4]))
+
+ set str
+
+ switch $short
+ case '-?'
+ set str $str -s (echo $short|cut -c 2)
+ end
+
+ switch $long
+ case '?*'
+ set str $str -l $long
+ end
+
+ switch $arg
+ case '=DIRECTORY'
+ set str $str -x -a "(__fish_complete_directories (commandline -ct))"
+
+ case '=COMMAND'
+ set str $str -x -a "(__fish_complete_command)"
+
+ case '=USERNAME'
+ set str $str -x -a "(__fish_complete_users)"
+
+ case '=FILENAME' '=FILE'
+ set str $str -r
+
+ case ' arg'
+ set str $str -x
+
+ case '?*'
+ set str $str -x
+ echo "Don't know how to handle arguments of type $arg" >&2
+ end
+
+ switch $desc
+ case '?*'
+ set str $str --description \'$desc\'
+ end
+
+ echo complete -c $cmd -n "'contains $i (commandline -poc)'" $str
- set -l sw2 (hg help $i | sed -n -e 's/^ *--\([^ ]*\) *\([^ ].*\)$/-l \1 --description \'\2\'/p' )
- if count $sw2 >/dev/null
- printf "complete -c hg %s\n" $sw2
end
end
+echo \n\n