LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

A good $PS1 for displaying long paths in the bash prompt

Posted 03-13-2013 at 11:29 PM by the dsc
Updated 03-13-2013 at 11:30 PM by the dsc
Tags bash, prompt, ps1

Code:
PS1='${debian_chroot:+($debian_chroot)}\t \u $(if [ ${#PWD} -gt 30 ] ; then myPWD="${PWD:0:12}…/\W" ; myPWD="${myPWD:0:25}…" ; else myPWD=$PWD; fi ; echo $myPWD) $ '
It will display full paths smaller than 30 characters entirely, but for longer paths it will get only the first characters of the whole path, and the fist characters of the last folder in the full path.

The end result is something like:

HH:MM:SS tuxguy /home/tuxguy/mystuf.../xmas pics $
HH:MM:SS tuxguy /home/tuxguy/mystuf.../long folder nam... $

It's a combination of what I already had (everything up to "\u") and something I saw here, in the comment section:

http://www.cyberciti.biz/tips/howto-...up-prompt.html

It was using a somewhat different method that didn't work for me, perhaps because of different/wrong quote characters, environment variables, or whatever.. So I stuck it all into PS1, ditching the "PROMPT_COMMAND" part that I didn't get. And it worked.

I like having the first characters of the current folder better, they're often more informative than the last ones I guess.
Posted in Uncategorized
Views 1298 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:57 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration