GNOME Bugzilla – Bug 733504
bash 4.3+ replaces ~ (tilde) with $HOME undoing the $HOME->~ replacement in __vte_prompt_command
Last modified: 2014-07-23 20:47:57 UTC
Created attachment 281312 [details] [review] Fix ~ replacement in bash > 4.3 Since bash 4.3 things the nice replacement of /home/colin -> ~ in the terminal titles is undone by bash which flips it back to /home/colin again. Boo! Bad bash. Attached patch restores this behaviour and also fixes a small bug where the cd'ing into another users home dir which happens to share your own homedirs prefix (e.g. /home/colintesting) would result in a slightly odd and misleading replacement.
Incidentally, if it's deemed too much "work" being done here, then the alternative is to simply change the: "${PWD/#$HOME/~}" to just: "${PWD}"
Bug confirmed. The patch indeed fixes it with bash 4.3 (and doesn't break with 4.2) - thanks. However, it breaks it with zsh - where the title doesn't reflect the cwd by default, but if you alter it to do so (or execute __vte_profile_command manually) then the replacement doesn't work.
Looks like we need backslash-escaping instead of quoting: "${PWD/#$HOME/\~}" ^
(In reply to comment #3) > Looks like we need backslash-escaping instead of quoting: > "${PWD/#$HOME/\~}" I've not tested but I thought that that would break in older bashes (the \ making it through to display), but if not, that's a much simpler fix Although note that the (existing) bug where if there are two user's with homes /home/colin and /home/colintesting, the title would end up being "~testing" if I (colin) did a cd into /home/colintesting folder.
> I've not tested but I thought that that would break in older bashes (the \ > making it through to display), but if not, that's a much simpler fix Sure we'd need to test with older bashes too. > Although note that the (existing) bug where if there are two user's with homes > /home/colin and /home/colintesting, the title would end up being "~testing" if > I (colin) did a cd into /home/colintesting folder. Definitely, the additional lines of "local pwd" and conditional assigning is required, nice catch.
(In reply to comment #5) > Definitely, the additional lines of "local pwd" and conditional assigning is > required, nice catch. Can't take credit for that one TBH, it was Mantas Mikulėnas who highlighted it to me when we were chatting about this issue! :)
Created attachment 281502 [details] [review] fix v2 This works for me with bash 3.2, 4.0, 4.2, 4.3 and zsh 5.0. Please test ;)
Review of attachment 281502 [details] [review]: Works for me in Bash 4.3 and 4.2, and I'll take your word for it on the others (looks good generally - seems my concern about the \~ being printed literally in bash < 4.2 was unfounded according to both your and my tests. Ship it!!!