How to set prompt in tcsh and bash

Wherever I go, I like to set prompt to display the current directory. I mean the complete path of current directory, not just the last element, and they all must be in one single line.

This is good:

/usr/bin/X11 >
Avoid this:

bash-3.2$ cd /usr/bin/X11
localhost$ cd /usr/bin
localhost$ /usr/bin
For tcsh, I have this in my $HOME/.tcshrc:
set prompt="%/ > "
For bash, include this in $HOME/.bashrc:
PS1="\w > "
, Or you can also run export PS1="\w > " from a bash terminal.

The benefits?

1. I don't need to type pwd 100s times a day. I don't even remember when was the last time I typed pwd.

2. I can easily copy the current working directory and pasted it elsewhere. Notice the trailing space in the value of prompt and PS1? With them I can simply double-click the path to select and copy it.

Tags: , ,


Anonymous said...

Very useful, except that on my distro (PCLinux) the \w shows up as ~ (tilde) rather than my full home directory (/home/user/). Any tips on how to fix? thanks

Unknown said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

eMexoT said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Internet Of Things training in electronic city