You are not logged in.

#1 2010-08-20 01:01:37

EvanPurkhiser
Member
From: San Francisco
Registered: 2010-08-17
Posts: 225
Website

bashrc PS1 Question

(Hopefully this is in the right sub-forum)

I setup my PS1 console prompt too be very clean: "[directory/]>"

however I don't like the tilde abbreviation used when in my home directory "[~/]>". I would like instead for it too show the actual folder name "[evan/]>". I didn't see any prompt escapse similar to \w that wouldn't abbreviate my home directory as the tilde so Instead I did this

PS1=[\e[0;34m$(pwd | cut -d '/' -f $(($(pwd | grep -o '/' | wc -l) + 1)))/\e[0m]>

My question is: Is there a better, simpler, way too do this? I am still very new too the bash scripting language so hardly know many tricks just yet.

Thanks!

Offline

#2 2010-08-20 01:07:51

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: bashrc PS1 Question

There is a list of escapes on the Wiki: I think you are after \W

http://wiki.archlinux.org/index.php/Col … pt_escapes


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2010-08-20 01:12:28

EvanPurkhiser
Member
From: San Francisco
Registered: 2010-08-17
Posts: 225
Website

Re: bashrc PS1 Question

\W         the basename of the current working directory, with $HOME abbreviated with a tilde

\W also abbreviates my home directory as a tilde ><

Offline

#4 2010-08-20 01:14:36

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: bashrc PS1 Question

Sorry Evan, I misread your post...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2010-08-20 01:33:57

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: bashrc PS1 Question

$PWD is automatically set by bash, so you don't need to use $(pwd)

To cut off up to and including the last slash, you can use ${PWD##*/}

Offline

#6 2010-08-20 01:44:46

EvanPurkhiser
Member
From: San Francisco
Registered: 2010-08-17
Posts: 225
Website

Re: bashrc PS1 Question

Procyon wrote:

$PWD is automatically set by bash, so you don't need to use $(pwd)

To cut off up to and including the last slash, you can use ${PWD##*/}

This is exactly what I was looking for! If you don't mind could you explain what the ##* does?

Edit: Nevermind, http://www.gnu.org/software/bash/manual … -Expansion explains whats going on here quite well!

Thanks!

Last edited by EvanPurkhiser (2010-08-20 01:55:25)

Offline

#7 2010-08-20 01:46:16

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: bashrc PS1 Question

You could also use something like this:

PROMPT_COMMAND="PS1=\"\`hostname\`:\`pwd\` ${LOGNAME}> \""
PS1="\h:${PWD} \u> "

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB