From 2af42d7e44d306c9ff2c25bdfb470f48d5ee6c5f Mon Sep 17 00:00:00 2001 From: Jonathan D'Andries Date: Thu, 16 Aug 2018 11:32:18 -0400 Subject: [PATCH 1/3] Add git_branch_space and git_dirty_space --- prompt.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prompt.sh b/prompt.sh index 6a737b8..8ade5f1 100644 --- a/prompt.sh +++ b/prompt.sh @@ -6,8 +6,10 @@ find_git_branch() { branch='detached*' fi git_branch="($branch)" + git_branch_space=" " else git_branch="" + git_branch_space="" fi } @@ -15,8 +17,10 @@ find_git_dirty() { local status=$(git status --porcelain 2> /dev/null) if [[ "$status" != "" ]]; then git_dirty='*' + git_dirty_space=" " else git_dirty='' + git_dirty_space="" fi } From 7ed461adabb11fbce7ac3f38de70fc39efd2c948 Mon Sep 17 00:00:00 2001 From: Jonathan D'Andries Date: Fri, 31 Aug 2018 13:48:23 -0400 Subject: [PATCH 2/3] Revert "Add git_branch_space and git_dirty_space" This reverts commit 2af42d7e44d306c9ff2c25bdfb470f48d5ee6c5f. --- prompt.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/prompt.sh b/prompt.sh index 8ade5f1..6a737b8 100644 --- a/prompt.sh +++ b/prompt.sh @@ -6,10 +6,8 @@ find_git_branch() { branch='detached*' fi git_branch="($branch)" - git_branch_space=" " else git_branch="" - git_branch_space="" fi } @@ -17,10 +15,8 @@ find_git_dirty() { local status=$(git status --porcelain 2> /dev/null) if [[ "$status" != "" ]]; then git_dirty='*' - git_dirty_space=" " else git_dirty='' - git_dirty_space="" fi } From 3653738075c2b7f2482d169d1676da7f267722a5 Mon Sep 17 00:00:00 2001 From: Jonathan D'Andries Date: Fri, 31 Aug 2018 14:08:48 -0400 Subject: [PATCH 3/3] Add conditional space in the README example PS1 values via ${git_branch:+ ...}. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ffaadcc..fc07763 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ end of the same file you pasted the installation code into earlier. #### Mac OS X ```bash -export PS1="\u@\h \W \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " +export PS1="\u@\h \W\${git_branch:+ \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty}\[$txtrst\] \$ " ``` Optionally, if you want a nice pretty prompt when using `sudo -s`, also add @@ -81,19 +81,19 @@ export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ " Standard: ```bash -export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " +export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\${git_branch:+ \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty}\[$txtrst\] \$ " ``` Colorized: ```bash -export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " +export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\${git_branch:+ \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty}\[$txtrst\] \$ " ``` #### Windows ```bash -export PS1="\[\033]0;$MSYSTEM:\w\007\033[32m\]\u@\h:\[\033[33m\w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\033[0m\]\$ " +export PS1="\[\033]0;$MSYSTEM:\w\007\033[32m\]\u@\h:\[\033[33m\w\${git_branch:+ \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty}\[$txtrst\] \033[0m\]\$ " ``` ## Updating