[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug] Home dir in PS1 not abbreviated to tilde

From: dethrophes
Subject: Re: [bug] Home dir in PS1 not abbreviated to tilde
Date: Tue, 13 Mar 2012 16:35:53 +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 16:27, schrieb Eric Blake:
On 03/13/2012 09:18 AM, Roman Rakus wrote:

as a workaround to your problem you could have something like this in
your bashrc
if shopt extglob&>/dev/null ; then
   HOME="${HOME/%+(\/)}"   # strip all trailing forward slashes
    while [ "${HOME}" != "${HOME%\/}" ] ; do

I think it should hide your problem.

Is it all necessary?
That only strips one trailing slash.  If you want to strip multiple
trailing slashes, then you have to go with something more complex; but
the above if/shopt/else/loop approach is overkill, compared to this

$ foo=/a/b///
$ echo ${foo%%/}
$ echo ${foo%${foo##*[^/]}}

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##*[^/]}} ;;

Thanks I didn't see the one liner right away so I got lazy and did a loop.
Your solution is of course much better, though a lot harder for most people to understand.

I only do if shopt else as psuedo code to show options.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]