|
| From: | dethrophes |
| Subject: | Re: [bug] Home dir in PS1 not abbreviated to tilde |
| Date: | Tue, 13 Mar 2012 18:03:26 +0100 |
| User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
Am 13.03.2012 17:53, schrieb Eric Blake:
Ok thanks that makes sense now, so you shorten 3 or more forward slashes into 1 forward slash.On 03/13/2012 09:47 AM, dethrophes wrote:Am 13.03.2012 16:42, schrieb Eric Blake:On 03/13/2012 09:27 AM, Eric Blake wrote:Be aware that both approaches will misbehave if HOME is a root directory (/ or //), where you _don't_ want to strip trailing slashes. So you really want: case $HOME in *[^/]* ) HOME=${HOME%${HOME##*[^/]}} ;; esacActually, shortening /// to / is okay (it's only // that must not unconditionally be shortened to /, due to POSIX specification and Cygwin behavior of //), so a modified version would be: case $HOME in *[^/]* ) HOME=${HOME%${HOME##*[^/]}} ;; / | // ) ;; *) HOME=/ ;; esacwouldn't this be better? case "$HOME" in / | // ) ;; * ) HOME="${HOME%${HOME##*[^/]}}" ;; esacNope, because that strips /// into the empty string, but you really want it collapsed into the single slash. Also, I intentionally omitted the redundant "" around the variable assignment.
the missing "" in the case isn't redundant.
i.e. case "$HOME" in
in the assignment they are redundant but I just find it good coding practice to always
"", because it means I'm less likely to forget.
case "$HOME" in
*[^/]* ) HOME=${HOME%${HOME##*[^/]}} ;;
/ | // ) ;;
*) HOME=/ ;; # //+(/)
esac
| [Prev in Thread] | Current Thread | [Next in Thread] |