[opensuse] BASH prompt - change prompt on the fly -> shorter -> longer -> shorter



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



Relevant Pages

  • Re: bash error when I open a terminal
    ...      It shouldn't. ... # set variable identifying the chroot you work in (used in the prompt ... # We have color support; ... # Alias definitions. ...
    (comp.os.linux.misc)
  • Re: compressed mail lost
    ... is remove the prompt and it will start compacting on it's own with ... I would definitely leave the prompt there until we ... "Alias" wrote in message ... >:> anything about this new feature and there is nothing ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Why does $_ in $MAILPATH work weirdly?
    ... # set variable identifying the chroot you work in (used in the prompt below) ... # Alias definitions. ... the above setting about $MAILPATH works well in the cygwin on my box: $_ just expands to the mailfile name. ...
    (Ubuntu)
  • Why does $_ in $MAILPATH work weirdly?
    ... # set variable identifying the chroot you work in (used in the prompt ... # Alias definitions. ... the above setting about $MAILPATH works well in the cygwin on my box: $_ just expands to the mailfile name. ...
    (Ubuntu)
  • Re: compressed mail lost
    ... I would definitely leave the prompt there until we ... "Alias" wrote in message ... :> compacting. ... The help file ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)