I started playing with more complete completions for git using make_completions.py. I hacked make_completions.py slightly to support
python make_completions.py git clone
to invoke e.g. man git-clone.
I attach the patch, and a sample output from the modified script.
I got a bit discouraged when I realized that the use of ^ in
fish and git clashes. Then I thought about it a little and realized
it clashes with regexes too. I'm not sure how much pain and suffering
it will take to learn to quote every caret.
You can browse the current git repo at
http://pivot.cs.unb.ca/git?p=fish-git.git;a=summary
or clone it via
git clone http://pivot.cs.unb.ca/git/fish-git.git
I'll report again when I have tested completions for more of the
140(!) git subcommands.
patch
Description: Binary data
git-add.fish
Description: Binary data
@@ -35,12 +35,23 @@ def clean(s):
res = r.sub(str, res)
return res
-def print_completion( cmd, switch_arr, arg, desc ):
+def get_short(man):
+ match=re.search(r"\nNAME\n.* - (.*)\n",man)
+ if match:
+ return match.group(1)
+ else:
+ return ''
+
+def print_completion( cmd, subcmd, switch_arr, arg, desc ):
if len(switch_arr)==0:
return
-
- res = "complete -c %s" % (cmd)
+
+ if subcmd=='':
+ res = "complete -c %s" % (cmd)
+ else:
+ res = "complete -c %s -n 'contains \\'%s\\' (commandline -poc)'" %
(cmd,subcmd)
+
for sw in switch_arr:
offset=1
@@ -48,10 +59,10 @@ def print_completion( cmd, switch_arr, arg, desc ):
if len(sw) == 2:
switch_type = "s"
-
- if sw[1] == "-":
- switch_type = "l"
- offset=2
+ else:
+ if sw[1] == "-":
+ switch_type = "l"
+ offset=2
res += " -%s %s" % (switch_type, escape(sw[offset:]))
@@ -59,12 +70,27 @@ def print_completion( cmd, switch_arr, arg, desc ):
print res
-cmd = sys.argv[1]
+if (len(sys.argv)>=3):
+ basecmd = sys.argv[1]
+ subcmd = sys.argv[2]
+ cmd=basecmd+'-'+subcmd
+ subcommand_mode=True
+else:
+ cmd=sys.argv[1]
+ subcommand_mode=False
header(cmd)
+
man = commands.getoutput( "man %s | col -b" % cmd )
+short_desc=get_short(man)
+
+if subcommand_mode:
+ print 'complete -c %s -n \'__fish_use_subcommand\' -x -a %s --description
\'%s\'' % (basecmd,subcmd,short_desc)
+
+
+
remainder = man
MODE_NONE = 0
@@ -142,7 +168,9 @@ for c in man:
if stop:
mode=MODE_NONE
- print_completion( cmd, sw_arr, None, desc )
+ print_completion( cmd, '', sw_arr, None, desc )
+ if subcommand_mode:
+ print_completion( basecmd, subcmd, sw_arr, None, desc )
sw_arr = []
------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php
_______________________________________________ Fish-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/fish-users
