Description of problem: In /etc/bashrc, PROMPT_COMMAND is set up to replace $HOME with ~ at the beginning of PWD, but it should only do so if the current directory is actually $HOME (or a subdirectory thereof). Version-Release number of selected component (if applicable): bash-4.1-6mdv2010.1 How reproducible: always Steps to Reproduce: 1. have a user with home dir "/home/user" 2. mkdir /home/user2; cd /home/user2 3. terminal title shows "user@host:~2"
A possible fix would be a PROMPT_COMMAND like this: PROMPT_COMMAND='echo -ne "\033]0;${USERNAME:-$USER}@${HOSTNAME%%.*}:"; case "$PWD" in $HOME|$HOME/*) echo -n "${PWD/#$HOME/~}" ;; *) echo -n "$PWD" ;; esac; echo -ne "\007"' But that's rather ugly...
I can't reproduce this issue, after cd /home/user2, it says 'user@hostname: user2'... Is there anything special about your setup, customisations... etc? which terminal emulator are you using?
I use gnome-terminal 3.0.0, but that should not matter (urxvt 9.10 behaves the same). Do you use the same PROMPT_COMMAND as me? In my /etc/bashrc, it is PROMPT_COMMAND='echo -ne "\033]0;${USERNAME:-$USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"' What does echo "${PWD/#$HOME/~}" show in "/home/user2" for you? I get "~2".
I think the problem is caused by the user names, 'user' and 'user'2, the share the 'user' part. [user@localhost ~]$ echo "${PWD/#$HOME/~}" ~ [user@localhost ~]$ cd /home/user2 [user@localhost user2]$ echo "${PWD/#$HOME/~}" ~2 [user@localhost user2]$ [a@localhost ~]$ echo "${PWD/#$HOME/~}" ~ [a@localhost ~]$ cd /home/user2 [a@localhost user2]$ echo "${PWD/#$HOME/~}" /home/user2 [a@localhost user2]$ The PROMPT_COMMAND here is the default one: PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"' it doesn' have ${USERNAME:-$USER} like yours, that may also explain the behaviour you see. (Of course assuming the user names on your box are actually 'user' 'user2' ...).
Maybe I should have made that clearer. The user names are indeed the problem, that's why I chose "user" and "user2" as the example.
CC: (none) => stormiAssignee: bugsquad => shlomif
pinging. because nothing happened to this report since more than 3 months ago, and it still has the status NEW or REOPENED @ Shlomi Please set status to ASSIGNED if you think this bug was assigned correctly. If for work flow reasons you can't do that, then please put OK on the whiteboard instead.
CC: (none) => marja11
I can reproduce this problem, but only on gnome-terminal - not on KDE's konsole. Assigning to me. Regards, -- Shlomi Fish
Status: NEW => ASSIGNED
This message is a reminder that Mageia 1 is nearing its end of life. In approximately 25 days from now, Mageia will stop maintaining and issuing updates for Mageia 1. At that time this bug will be closed as WONTFIX (EOL) if it remains open with a Mageia 'version' of '1'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, simply change the 'version' to a later Mageia version prior to Mageia 1's end of life. Bug Reporter: Thank you for reporting this issue and we are sorry that we may not be able to fix it before Mageia 1 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Mageia, you are encouraged to click on "Version" and change it against that version of Mageia. Although we aim to fix as many bugs as possible during every release's lifetime, sometimes those efforts are overtaken by events. Often a more recent Mageia release includes newer upstream software that fixes bugs or makes them obsolete. -- Mageia Bugsquad
Seems to be ok on Cauldron, so resolving.
Status: ASSIGNED => RESOLVEDResolution: (none) => WORKSFORME
Checked with bash-4.2-37.2.mga3 for Mageia 3 Alpha; the problem is still there. Please note that only PROMPT_COMMAND is affected (i.e. the window and tab title), but not PS1 (the bash prompt), since that uses "\W" to correctly replace "$HOME" with "~".
Status: RESOLVED => REOPENEDVersion: 1 => CauldronResolution: WORKSFORME => (none)
(In reply to comment #10) > Checked with bash-4.2-37.2.mga3 for Mageia 3 Alpha; the problem is still there. > > Please note that only PROMPT_COMMAND is affected (i.e. the window and tab > title), but not PS1 (the bash prompt), since that uses "\W" to correctly > replace "$HOME" with "~". Can you write a test case script? I find it hard to reproduce. Regards, -- Shlomi Fish
[root@localhost ~]# useradd user [root@localhost ~]# useradd user2 [root@localhost ~]# su - user [user@localhost ~]$ cd ~user2 [user@localhost user2]$ At that time, the LXTerminal (maybe others as well) show "user@localhost:~2" in the title, while it should be "user@localhost:/home/user2". Please note that this only affects user names where one is the prefix of the other, since then $HOME of "user" (= /home/user) is a prefix of $HOME of "user2" (= /home/user2), so that the path "/home/user2" gets transformed to "~2". (See comment #1 for a possible ugly fix.)
I can also do this: <<<< PROMPT_COMMAND='history -a; echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:$(perl -le '\''use Cwd; print Cwd::getcwd() =~ s#\A\Q$ENV{HOME}\E(?=/|\z)#~#r'\'');" echo -ne "\007"' >>>> Maybe it can be done using sed, but I dislike sed, and being Mageia we can always rely on perl to be there. But if someone can suggest a sed (or maybe awk) solution - I'm all ears. Regards, -- Shlomi Fish
This should be fixed on Mageia Cauldron. Please test. I think the bug is not critical enough to warrant an update on Mageia 2.
FWIW, the perl call should be replaced. For every prompt call, it's overkill to call an external program just to display pwd and shorten to ~ when in $HOME/. See also https://bugs.mageia.org/show_bug.cgi?id=3723#c47 Not sure why we don't simply use the bash prompt strings \w or \W to either show full path or only basename of current directory or ~ when pwd=$HOME, this works fine here for me. I'll see what I can dig up, there are several more readable solutions doing this either in bash or posix-compatible.
CC: (none) => doktor5000
I agree, using perl here for each new shell prompt line is overkill. Do we still need this PROMPT_COMMAND and PS1 hacks in /etc/bashrc?
CC: (none) => mageia, mageia, thierry.vignaud, tmb
(In reply to Florian Hubold from comment #15) > Not sure why we don't simply use the bash prompt strings \w or \W to either > show full path or only basename of current directory or ~ when pwd=$HOME, > this works fine here for me. We can not use \w or \W in PROMPT_COMMAND, since it contains a command to be executed, and does not expand special characters like PS1. I'll replace the perl command with something based on this: http://stackoverflow.com/questions/10036255/is-there-a-good-way-to-replace-home-directory-with-tilde-in-bash/10037257#10037257 And the xterm/screen case can be factorized a bit. This gives: i='${USER}@${HOSTNAME%%.*}:$([[ "${PWD}" =~ ^"${HOME}"(/|$) ]] && echo "~${PWD#${HOME}}" || echo "${PWD}")' case $TERM in xterm*) PROMPT_COMMAND='echo -ne "\033]0;'${i}'\007"' ;; screen) PROMPT_COMMAND='echo -ne "\033_'${i}'\033\\"' ;; *) ;; esac unset i
CC: (none) => shlomifAssignee: shlomif => mageia
Fixed in bash-4.3-42.5.mga6
Status: REOPENED => RESOLVEDResolution: (none) => FIXED