Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @brettstimmerman brettstimmerman revised this gist Apr 28, 2010. 1 changed file with 12 additions and 15 deletions.
    27 changes: 12 additions & 15 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,20 @@
    # Returns (svn:<revision>:<branch|tag>[*]) if applicable
    svn_prompt() {
    if [ -d ".svn" ] ; then
    if [ -d ".svn" ]; then
    local branch dirty rev info=$(svn info 2>/dev/null)

    branch=$(svn_parse_branch "${info}")
    branch=$(svn_parse_branch "$info")

    # Uncomment if you want to display the current revision.
    #rev=$(echo "${info}" | awk '/^Revision: [0-9]+/{print $2}')
    #rev=$(echo "$info" | awk '/^Revision: [0-9]+/{print $2}')

    # Uncomment if you want to display whether the repo is 'dirty.' In some
    # cases (on large repos) this may take a few seconds, which can
    # noticeably delay your prompt after a command executes.
    #[ "$(svn status)" ] && dirty='*'

    if [ "$branch" != "" ] ; then
    echo "(svn:${rev}:${branch}${dirty})"
    echo "(svn:$rev:$branch$dirty)"
    fi
    fi
    }
    @@ -23,24 +23,21 @@ svn_prompt() {
    svn_parse_branch() {
    local chunk url=$(echo "$1" | awk '/^URL: .*/{print $2}')

    echo ${url} | grep -q "/trunk\b"
    echo $url | grep -q "/trunk\b"
    if [ $? -eq 0 ] ; then
    echo trunk
    return
    else
    # first check /branches/releases
    chunk=$(echo ${url} | grep -o "/releases.*")
    if [ "${chunk}" == "" ] ; then
    # then check for some other branch
    chunk=$(echo ${url} | grep -o "/branches.*")
    if [ "${chunk}" == "" ] ; then
    # last check for a tag
    chunk=$(echo ${url} | grep -o "/tags.*")
    chunk=$(echo $url | grep -o "/releases.*")
    if [ "$chunk" == "" ] ; then
    chunk=$(echo $url | grep -o "/branches.*")
    if [ "$chunk" == "" ] ; then
    chunk=$(echo $url | grep -o "/tags.*")
    fi
    fi
    fi

    echo ${chunk} | awk -F/ '{print $3}'
    echo $chunk | awk -F/ '{print $3}'
    }

    export PS1="\w$(svn_prompt)>"
    export PS1="\w\$(svn_prompt)>"
  2. @brettstimmerman brettstimmerman revised this gist Apr 28, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Returns (svn:<revision>:<branch|tag>[*]) if applicable
    svn_prompt() {
    if [[ -d ".svn" ]] ; then
    if [ -d ".svn" ] ; then
    local branch dirty rev info=$(svn info 2>/dev/null)

    branch=$(svn_parse_branch "${info}")
  3. @brettstimmerman brettstimmerman revised this gist Apr 28, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Returns (svn:<revision>:<branch|tag>[*]) if applicable
    svn_prompt() {
    if [ -d ".svn" ] ; then
    if [[ -d ".svn" ]] ; then
    local branch dirty rev info=$(svn info 2>/dev/null)

    branch=$(svn_parse_branch "${info}")
  4. @brettstimmerman brettstimmerman created this gist Apr 28, 2010.
    46 changes: 46 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # Returns (svn:<revision>:<branch|tag>[*]) if applicable
    svn_prompt() {
    if [ -d ".svn" ] ; then
    local branch dirty rev info=$(svn info 2>/dev/null)

    branch=$(svn_parse_branch "${info}")

    # Uncomment if you want to display the current revision.
    #rev=$(echo "${info}" | awk '/^Revision: [0-9]+/{print $2}')

    # Uncomment if you want to display whether the repo is 'dirty.' In some
    # cases (on large repos) this may take a few seconds, which can
    # noticeably delay your prompt after a command executes.
    #[ "$(svn status)" ] && dirty='*'

    if [ "$branch" != "" ] ; then
    echo "(svn:${rev}:${branch}${dirty})"
    fi
    fi
    }

    # Returns the current branch or tag name from the given `svn info` output
    svn_parse_branch() {
    local chunk url=$(echo "$1" | awk '/^URL: .*/{print $2}')

    echo ${url} | grep -q "/trunk\b"
    if [ $? -eq 0 ] ; then
    echo trunk
    return
    else
    # first check /branches/releases
    chunk=$(echo ${url} | grep -o "/releases.*")
    if [ "${chunk}" == "" ] ; then
    # then check for some other branch
    chunk=$(echo ${url} | grep -o "/branches.*")
    if [ "${chunk}" == "" ] ; then
    # last check for a tag
    chunk=$(echo ${url} | grep -o "/tags.*")
    fi
    fi
    fi

    echo ${chunk} | awk -F/ '{print $3}'
    }

    export PS1="\w$(svn_prompt)>"