From 229b941b07317a44d5e63a518da24e20682f5d32 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Aug 2016 15:15:22 +1200 Subject: Slightly quicker git/svn detection --- bash/bashrc.d/prompt.bash | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'bash/bashrc.d/prompt.bash') diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 1e8c568d..5907f8ed 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -99,12 +99,8 @@ prompt() { # Git prompt function git) - # Bail if we have no git(1) - if ! hash git 2>/dev/null ; then - return 1 - fi - - # Bail if we're not in a work tree + # Bail if we're not in a work tree--or, implicitly, if we don't + # have git(1). local iswt iswt=$(git rev-parse --is-inside-work-tree 2>/dev/null) if [[ $iswt != true ]] ; then @@ -159,11 +155,6 @@ prompt() { # Subversion prompt function svn) - # Bail if we have no svn(1) - if ! hash svn 2>/dev/null ; then - return 1 - fi - # Determine the repository URL and root directory local key value url root while IFS=: read -r key value ; do @@ -177,10 +168,10 @@ prompt() { esac done < <(svn info 2>/dev/null) - # Exit if we couldn't get either - if [[ ! -n $url || ! -n $root ]] ; then - return 1 - fi + # Exit if we couldn't get either--or, implicitly, if we don't have + # svn(1). + [[ -n $url ]] || return + [[ -n $root ]] || return # Remove the root from the URL to get what's hopefully the branch # name, removing leading slashes and the 'branches' prefix, and any -- cgit v1.2.3