VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more



Are you brilliant? We're hiring. Read more

Getting Bash Completion for Remote Subversion Paths

DevOps

Do you want automatic completion for remote paths when using svn in bash? Do you want to switch easier between branches? I’ve written a small script that gives you autocompletion for all remote paths.

It has one issue though; it requires that you are in a working copy and use ^/ when writing the remote path.

Developer at VG. @androa


1 comments

  • Yves

    thx for the info :-)
    this should complete the http:// further:

    function complete_remote_paths() {
    word_to_complete=${COMP_WORDS[COMP_CWORD]}

    # If the command line contains ^/ we should start completing
    if [[ "$word_to_complete" == ^/* ]]; then

    # Create a base path for svn to use which only contains complete folder
    # names. Examples:
    # ^/bra => ^/
    # ^/branches/foo = ^/branches/
    basepath=$(echo "${word_to_complete}"|sed -re 's#[^/]+$##')
    elif [[ "$word_to_complete" == //* ]]; then
    basepath=http:$(echo "${word_to_complete}"|sed -re 's#[^/]+$##')
    fi

    if [[ "0$basepath" != "0" ]]; then
    # Generate a list of words to complete the command.
    COMPREPLY=($(compgen -W "$(get_remote_paths)" -- ${word_to_complete}))
    fi
    }

    function get_remote_paths() {
    # List all remote paths at given base path. Prepend the basepath to all
    # lines from svn ls in order to work with compgen.
    compl=$(echo $basepath | sed -e 's#http:##')
    svn ls ${basepath} 2>/dev/null | sed -e 's#^#'$compl'#'
    }


Leave your comment