Skip to content

Commit 4fcf512

Browse files
author
Daniel Flanagan
committed
Fix bash prompt so last path part is not shortened
1 parent af4be9a commit 4fcf512

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

shell/bash/prompt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ PROMPT_SUCCESS_COLOR='\[\e[0;34m\]'
66
PROMPT_FAILURE_COLOR='\[\e[0;31m\]'
77
DIR_COLOR='\[\e[0;35m\]'
88

9-
MAX_PATH_PIECE_CHARS=3
9+
MAX_PATH_PIECE_CHARS=${BASH_PROMPT_MAX_PATH_PIECE_CHARS:-3}
1010

1111
# prompt rendering functions
1212
preprocess_pwd() {
1313
p="$PWD"
1414
[[ "$p" == "/" ]] && echo "/" && return 1
1515
[[ "$p" == "${NICE_HOME}" ]] && echo "~" && return 0
1616
# with ellipsis
17-
# echo "$(<<< "$p" cut -c2- | awk '{split($0,p,"/");for(k in p){if(length(p[k])>'"$((MAX_PATH_PIECE_CHARS+1))"'){printf "/%.'"$((MAX_PATH_PIECE_CHARS))"'s…",p[k]}else{printf "/%s",p[k]}}}')"
17+
#echo "$(<<< "$p" cut -c2- | awk '{split($0,p,"/");for(k in p){if(k==length(p)){printf "/%s",p[k]}else{if(length(p[k])>'"$((MAX_PATH_PIECE_CHARS+1))"'){printf "/%.'"$((MAX_PATH_PIECE_CHARS))"'s…",p[k]}else{printf "/%s",p[k]}}}}')"
1818
# without ellipsis
19-
echo "$(<<< "$p" cut -c2- | awk '{split($0,p,"/");for(k in p){printf "/%.'"$MAX_PATH_PIECE_CHARS"'s",p[k]}}')"
19+
echo "$(<<< "$p" cut -c2- | awk '{split($0,p,"/");for(k in p){if(k==length(p)){printf "/%s",p[k]}else{printf "/%.'"$MAX_PATH_PIECE_CHARS"'s",p[k]}}}')"
2020
}
2121
export -f "preprocess_pwd"
2222

0 commit comments

Comments
 (0)