@@ -32,11 +32,12 @@ LAST_STATUS_THEME_PROMPT_COLOR=52
3232
3333_collapsed_wd () {
3434 # echo -e "\u2771\u276d\u276f"
35- echo $( pwd | perl -pe "
35+ # shellcheck disable=SC2005
36+ echo " $( pwd | perl -pe "
3637 BEGIN {
3738 binmode STDIN, ':encoding(UTF-8)';
3839 binmode STDOUT, ':encoding(UTF-8)';
39- }; s|^$HOME |<HOME>|g; s|/([^/])[^/]*(?=/)|/\$ 1|g" ) \
40+ }; s|^$HOME |<HOME>|g; s|/([^/])[^/]*(?=/)|/\$ 1|g" ) " \
4041 | sed -re " s/\// /g"
4142}
4243
@@ -47,22 +48,22 @@ _swd() {
4748 current=" " # The section of the path we're currently working on.
4849 end=" ${2:- ${PWD} } /" # The unmodified rest of the path.
4950
50- if [[ " $end " =~ " $HOME " ]]; then
51+ if [[ " $end " =~ $HOME ]]; then
5152 INHOME=1
52- end=" ${end# $HOME } " # strip /home/username from start of string
53- begin=" $HOME " # start expansion from the right spot
53+ end=" ${end# " $HOME " } " # strip /home/username from start of string
54+ begin=" ${ HOME} " # start expansion from the right spot
5455 else
5556 INHOME=0
5657 fi
5758
58- end=" ${end#/ } " # Strip the first /
59- shortenedpath=" $end " # The whole path, to check the length.
59+ end=" ${end#/ } " # Strip the first /
60+ shortenedpath=" ${ end} " # The whole path, to check the length.
6061 maxlength=" ${1:- 0} "
6162
6263 shopt -q nullglob && NGV=" -s" || NGV=" -u" # Store the value for later.
6364 shopt -s nullglob # Without this, anything that doesn't exist in the filesystem turns into */*/*/...
6465
65- while [[ " $end " ]] && (( ${# shortenedpath} > maxlength)) ; do
66+ while [[ " ${ end} " ]] && (( ${# shortenedpath} > maxlength)) ; do
6667 current=" ${end%%/* } " # everything before the first /
6768 end=" ${end#*/ } " # everything after the first /
6869
@@ -71,10 +72,10 @@ _swd() {
7172
7273 for (( i = ${# current} - 2 ; i >= 0 ; i-- )) ; do
7374 subcurrent=" ${current: 0: i} "
74- matching=(" $begin / $ subcurrent" * ) # Array of all files that start with $subcurrent.
75- (( ${# matching[*]} != 1 )) && break # Stop shortening if more than one file matches.
76- shortcur=" $subcurrent "
77- shortcurstar=" $subcurrent *"
75+ matching=(" ${ begin} / ${ subcurrent} " * ) # Array of all files that start with $subcurrent.
76+ (( ${# matching[*]} != 1 )) && break # Stop shortening if more than one file matches.
77+ shortcur=" ${ subcurrent} "
78+ shortcurstar=" ${ subcurrent} *"
7879 done
7980
8081 # advance
@@ -88,6 +89,7 @@ _swd() {
8889
8990 # Replaces slashes with except first occurence.
9091 if [ $INHOME -eq 1 ]; then
92+ # shellcheck disable=SC2088
9193 echo " ~/$shortenedpath " | sed " s/\///2g" # make sure it starts with ~/
9294 else
9395 echo " /$shortenedpath " | sed " s/\///2g" # Make sure it starts with /
0 commit comments