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_pathg`
+ COMPREPLY=( $(compgen -W “$ls_results” -
“$cur_path”) )
+ return 0
+ fi
+ # fallback on ordinary filename expansion
+ return 0
fi

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

Superior bash tab completion in OS X

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

As a precursor to my upcoming subversion URL completion (I’m still working on the patch), I’m posting about the really cool prerequisite, bash_completion. This is improved, over what is included by default in OS X, extensible tab completion. It does things like limiting options based on the cmd (only listing directories for the “cd” command") and hostname completion for ssh. It also allows for customizable completion for any command, which is the basis of the forthcoming URL completion.

Since it’s not included in the base OS X install, you need to install it yourself. You could go about this a variety of ways, but I went the DarwinPorts route. After installing Xcode, and DarwinPorts, and then using that to install bash_completion (all actually pretty easy), I sourced the file in my .bash_login

source  /opt/local/etc/bash_completion

I’d recommend dropping the most up to date subversion bash_completion script into the bash_completion.d and it will overwrite the default behavior.