[opensuse] BASH prompt - change prompt on the fly -> shorter -> longer -> shorter
- From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 May 2010 23:27:41 -0500
Guys,
I keep my prompt set so I always have the time and can simply copy/paste the
prompt as an rsync or scp or sftp source/destination. example:
21:43 nirvana:~/dt/e17/themes>
So if I need to transfer something to/from any host it is just a simple copy &
middle-mouse paste for:
rsync -uav nirvana:~/dt/e17/themes .
One issue that arises is that prompt length grows quickly as you drill down a
directory tree, especially if you are su'ed root: eg:
[21:55 alchemy:/usr/share/enlightenment/data/themes] #
So a solution was to create a small function in .bashrc and short alias to
accomplish what I needed. Since in the path statement, '\w' displays the full
path while '\W' will display only the current directory, toggling the path
required nothing more than re-exporting the path with the 'w' or 'W' set as
needed. The function that worked - (note all case statements are on a single line):
SetPrompt() {
case $1 in
w) export PS1="\[\e[0;37m\]\A\[\e[1;34m\] \[\e[1;34m\]\h:\w> \[\e[0m\]";;
W) export PS1="\[\e[0;37m\]\A\[\e[1;34m\] \[\e[1;34m\]\h:\W> \[\e[0m\]";;
*) echo -e "\n ${0##*/} [w,W] for 'full' or 'current' directory shown
in prompt -- try again.\n" >&2
return 1;;
esac
return 0
}
Then the efficient aliases used for 'SetPrompt w' or 'SetPrompt W':
alias spw='SetPrompt w'
alias spW='SetPrompt W'
If you use different prompts for root and regular users, then just adding a
test for the $UID allows you to set the appropriate prompt. (I like my user
prompt in blue/gray and my root prompt in red/yellow:
SetPrompt() {
case $1 in
w) [[ $UID -eq 0 ]] && \
export PS1="\[\e[0;37m\]\A \[\e[1;33m\]\h\[\e[0;31m\]:\w\[\e[1;33m\] #
\[\e[0m\]" || \
export PS1="\[\e[0;37m\]\A\[\e[1;34m\] \[\e[1;34m\]\h:\w> \[\e[0m\]";;
W) [[ $UID -eq 0 ]] && \
export PS1="\[\e[0;37m\]\A \[\e[1;33m\]\h\[\e[0;31m\]:\W\[\e[1;33m\] #
\[\e[0m\]" || \
export PS1="\[\e[0;37m\]\A\[\e[1;34m\] \[\e[1;34m\]\h:\W>
\[\e[0m\]";;
*) echo -e "\n ${0##*/} [w,W] for 'full' or 'current' directory shown
in prompt -- try again.\n" >&2
return 1;;
esac
return 0
}
Here is an alternate root prompt that I really like as well:
PS1="\[\e[1;34m\][\[\e[1;31m\]\A \[\e[1;34m\]\h\[\e[0;31m\]:\w\[\e[1;34m\]] #
\[\e[0m\]"
(to try out the prompts, just copy and paste the ( PS1="stuff" ) line to your
command line and hit return -- in any terminal)
Somewhere in the past I recall suse having some 'beautify path' options that
did something similar to this, but I couldn't find it with a limited search.
Does anybody else recall something like a 'beautify path' option that would
shorten the path to no more than 3 directory depth displayed starting at the
current dir and working back up the tree?
As long as we are on prompts, here is another super time-saver that takes you
back to the prior directory with a short alias that your fingers are already over:
alias cdl='cd $OLDPWD'
Next time you change directories and need to change back, just 'cdl'
Enjoy :p
--
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
- Follow-Ups:
- Prev by Date: Re: [opensuse] where do I turn tracker off at?
- Next by Date: Re: [opensuse] how to solve dependencies for stellarium 10.4
- Previous by thread: [opensuse] where do I turn tracker off at?
- Next by thread: Re: [opensuse] BASH prompt - change prompt on the fly -> shorter -> longer -> shorter
- Index(es):
Relevant Pages
|