Currently it is:
michael@Castle2012-Ubuntu-laptop01:~/Dropnot/webs/rails_v3/linker/spec/controllers$
Outside of renaming my machine and directory structure...
How could I make it be something more like:
michael:controllers$
Currently it is:
michael@Castle2012-Ubuntu-laptop01:~/Dropnot/webs/rails_v3/linker/spec/controllers$
Outside of renaming my machine and directory structure...
How could I make it be something more like:
michael:controllers$
To change it for the current terminal instance only
Just enter
PS1='\u:\W\$ '
and press enter.To change it "permanently"
In your
~/.bashrc
, find the following section:Remove the
@\h
, and replace the\w
with an uppercase\W
, so that it becomes:Save, exit, close terminal and start another to see the result.
Tons more options!
Run this code in the current terminal
Now the bash prompt will show only the last 3 directory names. You can choose 1 to show only current directory. More information is available in the GNU documentation.
The effect:
If you want to make it permanently, add the following line to
~/.bashrc
in the beginning:or another number greater than zero.
This is my preferred prompt setting:
added in
~/.bashrc
it looks like this:
(with a space after the
$
sign)Personally I prefer to see only current folder in the bash prompt. I can do this with the following command:
If you want it to take effect after each start then add the above command into your ~/.bashrc.
I realize this is super old but since nobody suggested creating an alias I figured I'd post. Using Bash Prompt Escape Sequences I made an alias
shorten
In
~/.bash_aliases
here you will notice the $Blue var to set the prompt colour which you can omit or change based on preference I also clear the terminal when calling shorten.To achieve the OP's desired prompt string:
I have colours defined in
~/.bashrc
copy and pasted from https://wiki.archlinux.org/index.php/Color_Bash_Prompt. On a side note what's with ansi code colours? I'm confused just looking at it.I wrote a function you can modify to suit your needs:
Place this function at or near the bottom of
~/.bashrc
after thePS1
line has been fully computed.You would type
termprompt
whenever you wanted to shorten your prompt or, havetermprompt
called from the bottom of your~/.bashrc
for permanency.The advantage of this technique over many other answers is
.bashrc
can setupPS1
in four different ways (xterm+no-color, xterm+color, no-xterm+no-color, no-xterm+color). This answer supports all four current methods and probably future methods too.Another advantage is this method has less complex control codes to traverse over in order to insert your changes.
Noting the answers I found in this post I came up with a template that I prefer to use. I also include colors in the command.
it looks like this:
To test it for the current terminal instance
To make it permanent for every terminal instance