Skip to content

Commit

Permalink
theme/powerline: fix an oops in the last patch
Browse files Browse the repository at this point in the history
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
gaelicWizard committed Oct 12, 2021
1 parent 49698e2 commit 953e422
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion themes/powerline/powerline.base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function __powerline_scm_prompt() {
}

function __powerline_cwd_prompt() {
local cwd="${PWD/$HOME/\~}"
local cwd="${PWD/$HOME/~}"

This comment has been minimized.

Copy link
@zou000

zou000 Oct 16, 2021

Contributor

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-3
the 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. 😄


echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
}
Expand Down

5 comments on commit 953e422

@davidpfarrell
Copy link
Contributor

@davidpfarrell davidpfarrell commented on 953e422 Oct 16, 2021

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 ...

@zou000
Copy link
Contributor

@zou000 zou000 commented on 953e422 Oct 17, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidpfarrell
Copy link
Contributor

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.


docker-bash3.2-shopt.txt

@zou000
Copy link
Contributor

@zou000 zou000 commented on 953e422 Oct 17, 2021

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/\~}"
~ \~

@davidpfarrell
Copy link
Contributor

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.

Please sign in to comment.