Alpha of subversion URL tab completion 3

Posted by Tim Connor Fri, 23 Mar 2007 23:32:00 GMT

Despite how much I really hate shell scripting I’ve actually got something semi-functional going on this whole svn tab completion idea. It only does anything when you tab on a full directory path (http://youserver/ or http://youserver/foo), but it will list the possibilities when you do, and autocomplete if there is only one.

I guess that just leaves getting partial completion working, ie http://yourserver/fo => http://yourserver/foo/, and then it’s done. I’m happy just to have it this far, though, so I won’t be cranking that out immediately. Down the road a bit maybe I’ll think about hostname completion too.

I cover the prerequisites in my quick intro to bash_completion of OS X. If you have that installed and the lastest svn bash_completion file, then you can just apply my patch.

bash_completion.patch.txt | bash_completion.patch

Index: bash_completion
===================================================================
--- bash_completion     (revision 24040)
+++ bash_completion     (working copy)
@@ -423,10 +423,19 @@
            return 0
        fi

-       # if not typing an option,
-       # then fallback on ordinary filename expansion
+       # if not typing an option
        if [[ $cur != -* || $stat = 'onlyarg' ]]  ; then
-           return 0
+          # if argument is an http directory
+           if [[ $cur == http://*/ ]] ; then
+             # strip leading http: due to completion issues with :
+            cur_path=${cur/http:/}
+             # query server and then prepend stripped path
+            ls_results=`svn ls $cur | sed s@^@$cur_path@g`
+            COMPREPLY=( $(compgen -W "$ls_results" -- "$cur_path") )
+            return 0
+          fi
+          # fallback on ordinary filename expansion
+          return 0
        fi

        # otherwise build possible options for the command
@@ -722,3 +731,4 @@
        return 0
 }
 complete -F _svnadmin -o default svnadmin
+

I forgot how much I really hate shell scripting

Posted by Tim Connor Fri, 23 Mar 2007 20:06:00 GMT

In 99.99% of the cases I’d just use a higher level scripting language, like ruby say, but when you are trying to extend existing shell scripted functionality…. I have learned a lot about programmable tab completion in bash, while trying to get subversion URL completion working, but I am still handicapped by my unfamiliarity with shell scripting, and my unwillingness to devote the next couple weeks to learning it.

I’m going to keep plugging at it here and there, but the url completion might take a while. If anyone out there is a decent bash scripter, I could use some pointers. ;)

The annoying part is the actual logic is pretty simple.