-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
The tilde should not have been escaped, and in fact I did not have it escaped in my main branch, but the PR I submitted did have it escaped and...now it shows up in the prompt line for all the PowerLine themes... oops.
- Loading branch information
There are no files selected for viewing
5 comments
on commit 953e422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently had the opportunity to explore all major bash versions via docker so I have them all handy to test:
bash 3.2
$ docker run --rm -it bash:3.2
$ mkdir -p one/two && cd one/two
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}"
version 3.2.57(1)-release : /home/dave/one/two : ~/one/two
bash 4.0
$ docker run --rm -it bash:4.0
$ mkdir -p one/two && cd one/two
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}"
version 4.0.44(1)-release : /home/dave/one/two : ~/one/two
bash 4.4
$ docker run --rm -it bash:4.4
$ mkdir -p one/two && cd one/two
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}"
version 4.4.23(1)-release : /home/dave/one/two : ~/one/two
bash 5.0
$ docker run --rm -it bash:5.0
$ mkdir -p one/two && cd one/two
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}"
version 5.0.18(1)-release : /home/dave/one/two : ~/one/two
bash 5.1
$ docker run --rm -it bash:5.1
$ mkdir -p one/two && cd one/two
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}"
version 5.1.8(1)-release : /home/dave/one/two : ~/one/two
Additionally, on my local mac:
$ cd ~
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}"
version 5.1.8(1)-release : /Users/david : ~
I no-longer have bash <5.1 on my mac in order to test if there's a mac-specific issue ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zou000,
Hmm ... wondering if maybe some shopt
option is behind this ... could you try:
within bash 3.2 on mac
$ shopt | sort > shopt.txt
And either post the results or compare to my docker's results for (almost) same version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @davidpfarrell,
Good suggestion. I looked into shopt
a bit, it turns out that echoing quoted strings has different behavior:
# in bash 3.2
❯echo ${PWD/$HOME/\~} "${PWD/$HOME/\~}"
~ \~
# in bash 5.1
❯echo ${PWD/$HOME/\~} "${PWD/$HOME/\~}"
~ ~
# in bash 5.1 and turn on 3.2 compatible mode
❯shopt -s compat32
❯echo ${PWD/$HOME/\~} "${PWD/$HOME/\~}"
~ \~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK So I completely botched my first test run - I created a non-root user for the test and did not realize that users are created with ash
as the their default shell (even though its the Bash docker image) ... So that post is invalidated. Here are the actual results, just running as root in ~ :
bash 3.2
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}" ":" ${PWD/#$HOME/\~}
version 3.2.57(1)-release : ~ : \~ : ~
bash 4.0
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}" ":" ${PWD/#$HOME/\~}
version 4.0.44(1)-release : ~ : \~ : ~
bash 4.4
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}" ":" ${PWD/#$HOME/\~}
version 4.4.23(1)-release : /root : ~ : ~
bash 5.0
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}" ":" ${PWD/#$HOME/\~}
version 5.0.18(1)-release : /root : ~ : ~
bash 5.1
$ echo "$(bash -version |egrep -o 'version [^ ]+-release')" ":" "${PWD/$HOME/~}" ":" "${PWD/$HOME/\~}" ":" ${PWD/#$HOME/\~}
version 5.1.8(1)-release : /root : ~ : ~
This confirms that @zou000's observation of not using outer quotes is correct.
Please not also my addition of /#
- This is to anchor the match as discussed here:
*Make pwd result in terms of "~"?
So I believe we need update #1974 with /#
but then I think we got it.
This won't work in bash-5 (mine is 5.1.4).
Long story:
${PWD/$HOME/~}
works in bash-3, but not in bash-5${PWD/$HOME/\~}
works in bash-5 but not in bash-3the original command was
$(pwd | sed "s|^${HOME}|~|")
, which works for both versions.I found out this a while ago, and "fixed" the issue by upgrading my macos' bash to version 5. 😄