You are not logged in.

#1 2009-12-04 02:37:16

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Putting a \n at the end of your PS1.

Does anyone like to put a newline after their prompt? I just discovered it, I get more space and can put more crap on my prompt at the expense of vertical space. (which isn't as critical with scrolling).


Personally, I'd rather be back in Hobbiton.

Offline

#2 2009-12-04 02:48:17

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: Putting a \n at the end of your PS1.

I have a newline and a $ in that order as the end of my prompt.


I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

#3 2009-12-04 04:23:02

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Putting a \n at the end of your PS1.

I tent to cut and paste alot from the terminal so I like to do it, req:

vMnd1dQ


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#4 2009-12-04 04:30:51

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,493
Website

Re: Putting a \n at the end of your PS1.

My prompt looks exactly like at the top of this: http://dev.archlinux.org/~allan/

Offline

#5 2009-12-04 06:24:19

presario
Member
From: Tashkent, Uzbekistan
Registered: 2008-12-07
Posts: 57
Website

Re: Putting a \n at the end of your PS1.

<off-topic>
@Gen2ly
What font are you using? It looks very nice smile
</off-topic>


Running ArchLinux on Compaq Presario v2000

Offline

#6 2009-12-04 07:28:11

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Putting a \n at the end of your PS1.

It's blasphemy, but I use Redmond's consolas.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#7 2009-12-04 12:52:44

alexandrite
Member
Registered: 2009-03-27
Posts: 326

Re: Putting a \n at the end of your PS1.

I do.  At first, I didn't really think doing such a thing would be practical, but it really helps visibility when you want to do a long command in a deep directory.

/--[ alex@Hal-Jr-Arch ~/Music/Presidents_of_the_United_States_of_America/The_Presidents_Of_The_United_States_Of_America ]--(07:47:10)-
\--> for i in *.mp3; do x=`echo $i | sed -e 's/\..*//' -e 's/[0-9]*\ //'`; mid3v2 --song="$x" "$i"; done;

can fit on two lines in a smallish terminal.

Last edited by alexandrite (2009-12-04 12:53:09)

Offline

#8 2009-12-04 14:20:10

lswest
Member
From: Munich, Germany
Registered: 2008-06-14
Posts: 456
Website

Re: Putting a \n at the end of your PS1.

I use a newline at the end of my Zsh prompt.  In case anyone is interested, to do so is slightly different than in Bash.  My Prompt code (important part marked in bold):

export PS1="%{$fg[white]%}┌─[%{$fg[green]%}%n%{$fg[cyan]%}@%{$fg[green]%}%m%{$fg[white]%}:%{$fg[yellow]%}%~%{$fg[white]%}]%{$fg[yellow]%}-%{$fg[red]%}[%{$fg[cyan]%}%*%{$fg[red]%}]%{$reset_color%}%{$reset_color%}"$'\n'"%{$fg[white]%}└─>%{$reset_color%} "

Basically you have to break out of any double quotes there are, and add $'\n', in order to have a newline.  I thought I'd post it here since it took me a while to figure that one out.

Results in this prompt (in the terminal it's colored, thus the colors above):

    ┌─[lswest@lswest-netbook:~]-[15:21:07]
    └─>

Last edited by lswest (2009-12-04 14:25:45)


Lswest <- the first letter of my username is a lowercase "L".
"...the Linux philosophy is "laugh in the face of danger". Oops. Wrong one. "Do it yourself". That's it." - Linus Torvalds

Offline

#9 2009-12-04 14:47:27

Rede
Member
Registered: 2009-02-27
Posts: 33

Re: Putting a \n at the end of your PS1.

lswest wrote:

I use a newline at the end of my Zsh prompt.  In case anyone is interested, to do so is slightly different than in Bash.  My Prompt code (important part marked in bold):

export PS1="%{$fg[white]%}┌─[%{$fg[green]%}%n%{$fg[cyan]%}@%{$fg[green]%}%m%{$fg[white]%}:%{$fg[yellow]%}%~%{$fg[white]%}]%{$fg[yellow]%}-%{$fg[red]%}[%{$fg[cyan]%}%*%{$fg[red]%}]%{$reset_color%}%{$reset_color%}"$'\n'"%{$fg[white]%}└─>%{$reset_color%} "

Basically you have to break out of any double quotes there are, and add $'\n', in order to have a newline.  I thought I'd post it here since it took me a while to figure that one out.

Results in this prompt (in the terminal it's colored, thus the colors above):

    ┌─[lswest@lswest-netbook:~]-[15:21:07]
    └─>

That's quite a nice PS1, very creative. Well done.

Offline

#10 2009-12-04 15:32:17

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Putting a \n at the end of your PS1.

My laptop's prompt stuff is here. My main box is on the master branch.

Offline

#11 2009-12-04 16:12:47

lswest
Member
From: Munich, Germany
Registered: 2008-06-14
Posts: 456
Website

Re: Putting a \n at the end of your PS1.

Rede wrote:

That's quite a nice PS1, very creative. Well done.

Thanks smile  I got the general idea for the layout of the prompt off someone either here on the Forums, or on UbuntuForums, so I can't take all the credit, but I added in the things I found most useful.  I always find having a timestamp on command useful, in case you want to know how long it takes and such.  I also have a variation to use in Screen, that displays the number of the screen window in the prompt, though that section was borrowed off someone else's config.

Last edited by lswest (2009-12-04 16:13:39)


Lswest <- the first letter of my username is a lowercase "L".
"...the Linux philosophy is "laugh in the face of danger". Oops. Wrong one. "Do it yourself". That's it." - Linus Torvalds

Offline

#12 2009-12-04 18:32:09

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Putting a \n at the end of your PS1.

export PS1='\[\033[0;32m\]╔═[\[\033[0m\033[0;36m\]\u\[\033[0;32m\]@\[\033[0m\033[0;36m\]\h\[\033[0;32m\]]═[\[\033[0m\033[0;36m\]\t \d\[\033[0;32m\]]═[\[\033[0m\033[0;36m\]\w\[\033[0;32m\]]\n\[\033[0;32m\]╚═══[\[\033[0m\033[0;36m\]\$\[\033[0;32m\]]>\[\033[0m\] '

results in
╔═[hatten@prinplup]═[19:24:32 Fri Dec 04]═[~]
╚═══[$]>
in teal and light green. sexy!

Offline

#13 2009-12-05 00:23:33

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Putting a \n at the end of your PS1.

I wouldn't want to waste vertical space. Single-character prompts for me. Using the shell is more pleasant when visiting directories with long names doesn't obliterate your entire screen.

Offline

#14 2009-12-05 00:55:46

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Putting a \n at the end of your PS1.

pauldonnelly wrote:

I wouldn't want to waste vertical space. Single-character prompts for me. Using the shell is more pleasant when visiting directories with long names doesn't obliterate your entire screen.

I got no conky, so i need to have the clock/date somewhere, and if i had a single character prompt i wouldn't be able to see which computer i were working on. But having a single-character prompt, won't you have to use pwd and the like quite often?

Offline

#15 2009-12-06 20:23:51

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Putting a \n at the end of your PS1.

hatten wrote:
pauldonnelly wrote:

I wouldn't want to waste vertical space. Single-character prompts for me. Using the shell is more pleasant when visiting directories with long names doesn't obliterate your entire screen.

I got no conky, so i need to have the clock/date somewhere,

Don't you need to press Enter to get an up-to-date time? I could type "date" as easily as that. But I do run an Xclock to tell me the time.

and if i had a single character prompt i wouldn't be able to see which computer i were working on.

I color-code mine.

But having a single-character prompt, won't you have to use pwd and the like quite often?

%grep -c pwd .histfile 
1
%wc -l .histfile
1000 .histfile

Not particularly. Maybe if I leave the computer and there's nothing on the screen to remind me which directory I was in when I come back. The number of times per day that I forget what directory I'm in doesn't come close to justifying having it in my prompt at all times for me.

Offline

#16 2009-12-06 22:05:14

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Putting a \n at the end of your PS1.

Well whatever suits your taste, might do that on my netbook where i don't have such a big screen.

Offline

#17 2009-12-06 22:57:01

alexandrite
Member
Registered: 2009-03-27
Posts: 326

Re: Putting a \n at the end of your PS1.

This may be OT, but how are you getting the "window border" characters into your propmts?  I know that I could just paste yours, but I'm betting there's a better way wink.

Offline

#18 2009-12-07 08:18:21

upsidaisium
Member
From: Vietnam
Registered: 2006-09-16
Posts: 263
Website

Re: Putting a \n at the end of your PS1.

pauldonnelly wrote:

The number of times per day that I forget what directory I'm in doesn't come close to justifying having it in my prompt at all times for me.

this thought has occurred to me before, but until today i hadn't tried using a single character prompt (well.. two characters if we're counting the space after the '>'). my screen is so much cleaner now smile now to figure out if i can change lftp's prompt, which gets so long and ugly after i cd into child directories..


I've seen young people waste their time reading books about sensitive vampires. It's kinda sad. But you say it's not the end of the world... Well, maybe it is!

Offline

#19 2009-12-07 08:22:33

jowilkin
Member
Registered: 2009-05-07
Posts: 243

Re: Putting a \n at the end of your PS1.

My prompt, modified slightly from one posted on these forums a while back:

╭─[jowilkin::bubba::~]
╰─[03:38:22]>

I'm considering taking the time out of it to get some more room and because I don't find it that useful.  Username is light green, host is light blue, cwd is black cool  My PS1:

╭─[\[\e[1;32m\]\u\[\e[0m\]::\[\e[1;36m\]\h\[\e[0m\]::\w] ╰─[\T]>

It turns red if I'm logged in as root, a nice reminder to not do anything stupid smile

Last edited by jowilkin (2009-12-07 08:24:02)

Offline

#20 2009-12-07 08:26:29

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Putting a \n at the end of your PS1.

Gen2ly wrote:

I tent to cut and paste alot from the terminal so I like to do it, req:

http://omploader.org/vMnd1dQ

I like that. Would you share that?


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#21 2009-12-07 10:53:25

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Putting a \n at the end of your PS1.

Yeah, no problem.

set_prompt_style () {
  local bldpur='\e[1;35m' # Purple
  local bldblu='\e[1;34m' # Blue
  local bldblk='\e[1;30m' # Black - Bold
  local bldred='\e[1;31m' # Red
  local txtrst='\e[0m'    # Text Reset
#  local bashuser="\[$bldpur\]\u@\[$txtrst\]"    # username
  local bashhost="\[$bldpur\]\h\[$txtrst\]"     # hostname
  local bashdir="\[$bldblu\]\w\[$txtrst\]"      # directory
  local bashprompt="\[$bldblk\]:\n\[$txtrst\]"  # prompt symbol
  if [ `whoami` == "root" ] ; then
#  local bashuser="\[$bldred\]\u@\[$txtrst\]"
  local bashhost="\[$bldred\]\h\[$txtrst\]"
  fi
PS1="$bashuser$bashhost $bashdir$bashprompt"
}
set_prompt_style

Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#22 2009-12-09 19:24:47

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: Putting a \n at the end of your PS1.

Here's what my prompt looks like:

.:[ b-con@beacon-laptop2 | 13:11:11 | ~/Desktop ]:.
$

My prompt function auto-trims the working directory to ensure that it doesn't go longer than the width of the terminal.

Offline

Board footer

Powered by FluxBB