[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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 28 May 2010 23:27:41 David C. Rankin wrote:
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'
or alias cdo='cd -' Not much shorter, but does the same :) -- Regards Rajko, -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Sat, 29 May 2010, Rajko M. wrote:
On Friday 28 May 2010 23:27:41 David C. Rankin wrote:
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'
or
alias cdo='cd -'
Not much shorter, but does the same :)
Even better: use pushd/popd to change dirs. You should already have '-' as an alias for popd. And I have '+' aliased to pushd. And neither aliases are in my ~/.alias. AFAIK, both are standard on SUSE and not some of my homespun stuff ;) And that's on a ex-SUSE 6.2! And I've not noticed it not working on the 11.2 on the new box. So, you can use '+ SOME_PATH' / '-' to navigate ;) Try shorten that, buster! ;P HTH, -dnh, who actually doesn't use pushd/popd much, but 'cd SOME_PATH' / 'cd -'. On purpose, just because I don't much work that way, not because I don't like it. Usually, I just open a new xterm anyway for a task (who cares about one more, if you already have 10 running anyway? ;) PS: my prompt: PS1="\[\033[1;37;44m\]\u@\h[ \[\010${TTY}\]]:\[\033[0m\] \w ( \[\010\$?\])\$\[\033[0m\] " case $TERM in xterm*) PS1="\[\033]0;\u@\h[${TTY}]: \w\007\]${PS1}" ;; *emacs*) PS1='\u@\h: \w $ ' ;; esac export PS1 Ah, $TTY is set in /etc/profile.local: TTY="`tty`" TTY="`echo \"$TTY\" | sed 's/.*\/\(ttyp\?\|pts\/\?\)//'`" export TTY (I once had and still have a bash-version of that as a comment, but such just doesn't belong in /etc/profile*. And, judging from as fast as xterms start here, on my "ancient" Athlon 500, I just don't care about performance!) Still has some glitches on long lines though. And root has a simpler, white on red version. And remote stuff has other colors (e.g. white on green or magenta or whatever). So I immediately see: "me, locally", "me, remote", "root, locally" "root, not locally" ;) I think I should reserve "white on pink" as "non-local-root" ;) *tippity-tap* ;) -- Shouldn't a "programmer's editor" be called a "bugger"? -- Graham Reed -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 05/29/2010 03:34 AM, David Haller wrote:
Even better: use pushd/popd to change dirs. You should already have '-' as an alias for popd. And I have '+' aliased to pushd. And neither aliases are in my ~/.alias. AFAIK, both are standard on SUSE and not some of my homespun stuff ;) And that's on a ex-SUSE 6.2! And I've not noticed it not working on the 11.2 on the new box.
So, you can use '+ SOME_PATH' / '-' to navigate ;)
Try shorten that, buster! ;P
HTH, -dnh, who actually doesn't use pushd/popd much, but 'cd SOME_PATH' / 'cd -'. On purpose, just because I don't much work that way, not because I don't like it. Usually, I just open a new xterm anyway for a task (who cares about one more, if you already have 10 running anyway? ;)
I like the '-', but I still haven't figured out the '+'. I mean I've confirmed what it does and how it works: david@alchemy[]: /var/log (0)$ david@alchemy[]: /var/log (0)$ dirs -v 0 /var/log 1 ~ david@alchemy[]: /var/log (0)$ + /var/log /var/log ~ david@alchemy[]: /var/log (0)$ cd /usr/share/ssl/misc/ david@alchemy[]: /usr/share/ssl/misc (0)$ + /usr/share/ssl/misc /usr/share/ssl/misc /var/log ~ david@alchemy[]: /usr/share/ssl/misc (0)$ - /usr/share/ssl/misc /var/log ~ david@alchemy[]: /usr/share/ssl/misc (0)$ - /var/log ~ david@alchemy[]: /var/log (0)$ + /var/log /var/log ~ david@alchemy[]: /var/log (0)$ cd david@alchemy[]: ~ (0)$ - /var/log ~ david@alchemy[]: /var/log (0)$ cd david@alchemy[]: ~ (0)$ dirs -v 0 ~ 1 ~ david@alchemy[]: ~ (0)$ - ~ david@alchemy[]: ~ (0)$ But remembering to pushd '+' any directory I need to come back to, seem like something that I would forget to do a lot ;-) -- 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@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Thu, 03 Jun 2010, David C. Rankin wrote:
I like the '-', but I still haven't figured out the '+'. I mean I've confirmed what it does and how it works:
+ is just an alias to pushd. Hm, actually, what's it aliased to? On my 6.2 box, it's aliased to 'pushd .' and I thought it was aliased to 'pushd'.
david@alchemy[]: /var/log (0)$ + /var/log /var/log ~
You just put /var/log (again) onto the dirs-stack. So, with that alias, you can push a dir onto the stack after you changed to that dir.
But remembering to pushd '+' any directory I need to come back to, seem like something that I would forget to do a lot ;-)
re-alias it as 'pushd' (as I thought it was) and use it instead of pushd ;) I.e.: $ + /foo $ - To push after the fact, use '+ .' or alias '+.' to that ;) Hey! I use bash for ~13 years and I'm still discovering new stuff. And that's on the old box (OS installed in 1999): $ rpm -q --queryformat '%{name}-%{version} %{installtime:date}\n' bash bash-2.03 Tue 11 Jul 2000 08:47:52 PM CEST HTH, -dnh -- "The command 'man man' works fine, but 'man woman' produces: No manual entry for woman." -- Constantinos Maltezos -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (3)
-
David C. Rankin
-
David Haller
-
Rajko M.