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
    +
Comments

Leave a comment

  1. Avatar
    dan.ellis@displaylink.com about 1 month later:

    This sorts it out for partial paths as well (sorry it’s not a patch):

    1. if not typing an option,
    2. then fallback on ordinary filename expansion
    3. if argument is an URL
      if [[ $cur == :/ ]] ; then
    4. strip leading protocol due to completion issues with :
      cur_path=${cur/*:/}
    5. query server and then prepend stripped path – add . to paths so that
    6. if they’re real directories we get them i.e. dir/ > dir/. → dir
      ls_results=`svn ls $(dirname $cur.) 2> /dev/null | sed -e “s@^$(dirname $cur_path.)/”`
      COMPREPLY=( $(compgen -W “$ls_results” -
      “$cur_path”) )
      return 0
      fi
    7. fallback on ordinary filename expansion
      _filedir
      return 0


    with:

    complete -o filenames -o nospace -f -F _svn $default svn

  2. Avatar
    Tim Connor about 1 month later:

    Nice! I’ll have to check this out, Dan.

  3. Avatar
    Ben Damman 9 months later:

    Thanks for sharing these patches, Tim & Dan. Very handy when I can’t remember paths in old project repositories.

Comments