From f6b528e4243780e9495204c71a619f59cf0963bc Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 15 Aug 2018 23:15:43 +0200 Subject: [PATCH] Update calculation of short_pwd to also work on Bash 4 --- .bashrc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index df9c57e..a5e2e46 100644 --- a/.bashrc +++ b/.bashrc @@ -186,7 +186,12 @@ PS1="${debian_chroot:+($debian_chroot)}" # Short PWD, if it's to long. short_pwd() { - FIXED_PWD="${PWD/#$HOME/~}" + local FIXED_PWD=${PWD#$HOME} + if [ ${#FIXED_PWD} -le ${#PWD} ]; then + FIXED_PWD="~${FIXED_PWD}" + else + FIXED_PWD="${PWD}" + fi if [[ ${#FIXED_PWD} -gt $PWD_LENGTH ]]; then echo "${FIXED_PWD:0:$((4))}...${FIXED_PWD:$((${#PWD}-$PWD_LENGTH+7)):$(($PWD_LENGTH-7))}" else