Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bash prompt help

4 views
Skip to first unread message

Mihamina Rakotomandimby

unread,
Feb 13, 2012, 5:55:45 AM2/13/12
to help-gn...@gnu.org
Hi all,

Running Bash 4.2.20, I would like to have a prompt composed by the first
letters of the base path, excluding the last one.


Example:
- /u/l/bin if I'm in /usr/local/bin
- /v/w/h/my-website if I'm in /var/www/html/my-website
- /h/mihamina if I'm in /home/mihamina

Of course, this could lead to some errors and confusion, but it's useful
for my particular use case, and if I want to explicitely print the
current directory, I'll just have to "cwd".

Thank you.

--
RMA.


Chris F.A. Johnson

unread,
Feb 13, 2012, 4:01:23 PM2/13/12
to
On 2012-02-13, Mihamina Rakotomandimby wrote:
> Hi all,
>
> Running Bash 4.2.20, I would like to have a prompt composed by the first
> letters of the base path, excluding the last one.
>
>
> Example:
> - /u/l/bin if I'm in /usr/local/bin
> - /v/w/h/my-website if I'm in /var/www/html/my-website
> - /h/mihamina if I'm in /home/mihamina

PROMPT_COMMAND='PS1=$(IFS=/ read -a x <<< "$PWD"
for d in "${x[@]}"
do
[ -n "$d" ] && pwd=$pwd/${d:0:1}
done
echo "$pwd${PWD##*/?}")\ \\$\ '


--
Chris F.A. Johnson <http://cfajohnson.com>
Author: =======================
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Bob Proulx

unread,
Feb 13, 2012, 5:36:50 PM2/13/12
to help-gn...@gnu.org, Mihamina Rakotomandimby
Mihamina Rakotomandimby wrote:
> Running Bash 4.2.20, I would like to have a prompt composed by the
> first letters of the base path, excluding the last one.

You also asked this question over in help-bash. There is good
response over in help-bash. If anyone else would like to response it
would be nicest if they responded over there.

Bob

0 new messages