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$
Just enter PS1='\u:\W\$ '
and press enter.
In your ~/.bashrc
, find the following section:
if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi
Remove the @\h
, and replace the \w
with an uppercase \W
, so that it becomes:
if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u:\W\$ ' fi
Save, exit, close terminal and start another to see the result.
HOST='\033[02;36m\]\h' HOST=' '$HOST parse_git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; } TIME='\033[01;31m\]\t \033[01;32m\]' LOCATION=' \033[01;34m\]
pwd | sed "s#(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/).*(/[^/]\{1,\}/[^/]\{1,\})/\{0,1\}#\1_\2#g"' BRANCH=' \033[00;33m\]$(parse_git_branch)\[\033[00m\]\n\$ ' PS1=$TIME$USER$HOST$LOCATION$BRANCH PS2='\[\033[01;36m\]>'
May 19, 2015 at 12:44
Run this code in the current terminal
PROMPT_DIRTRIM=3
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:
/var/lib/apt/lists# PROMPT_DIRTRIM=3
/.../lib/apt/lists#
If you want to make it permanently, add the following line to ~/.bashrc
in the beginning:
PROMPT_DIRTRIM=3
or another number greater than zero.
promptdir() { PROMPT_DIRTRIM=$1; }
just to make live easier...
This is my preferred prompt setting:
added in ~/.bashrc
PS1='[\u@\h \W]\$ '
it looks like this:
[user@hostname dirname]$
(with a space after the $
sign)
PS1='\[\033[01;34m\][\u @ \h \W]\[\033[00m\]\$ '
, but adding space between each word looks ugly tho...
Sep 17, 2021 at 2:06
Personally I prefer to see only current folder in the bash prompt. I can do this with the following command:
PS1='\W\$ '
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.
alias c='clear'
alias shorten='PS1="$Blue$USER:\W$ "&& c'
To achieve the OP's desired prompt string:
alias shorten='PS1="$USER:\W$ "'
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.
Blue='\e[0;34m' # Blue
I wrote a function you can modify to suit your needs:
function termprompt() {
PS1="${PS1//@\\h/}" # Remove @host
PS1="${PS1//\\w/\\W}" # Change from full directory to last name
}
Place this function at or near the bottom of ~/.bashrc
after the PS1
line has been fully computed.
You would type termprompt
whenever you wanted to shorten your prompt or, have termprompt
called from the bottom of your ~/.bashrc
for permanency.
The advantage of this technique over many other answers is .bashrc
can setup PS1
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.