1. To have the shell prompt always start at the left hand side of terminal:
When you have long pathname for the current working directory and you have a even longer command to execute, the display gets all screwed up. So it always helps you to have the shell prompt start at left hand side of terminal. You have to change the PS1 - to customize your bash prompt.
In the fig, you can't distinguish where the dir name ends and where the command starts. So open ".bashrc" file in home folder
gedit ~/.bashrc
and add the following code. Note: as a good coding practice, add a line of comment saying when and why added the piece of code and add the new code at the end of the file.PS1=$'\[\e]2; \h::\]$PWD\[\a\]\[\e]1;\]$(basename "$(dirname "$PWD")")/\W\[\a\] \w\n\T \$ '
Then the bash prompt becomes like this,
The current working directory name in first line(s) and in a new line current time followed by $ for you to type in the command.
Much better huh, what exactly does the code do? Let's review from back
\$ - if the effective UID is 0, a #, otherwise a $
\T - the current time in 12-hour HH:MM:SS format
\n - newline
\w - current working directory with ~ instead of $HOME directory
\[ \] - begin and end of a series of non-printing characters
\W - basename of the current working directory with ~ instead of $HOME directory
\e - escape character
\h - hostname
Source: to customize you bash prompt you can follow this help document.
You can also create aliases for opening and refreshing bashrc file like this (if you have to change it frequently)
In "~/.bashrc" file add the following code,
alias refprofile=' source ~/.bashrc'
alias editprofile='vi ~/.bashrc'
whereas, editprofile - opens the file for editing and refprofile - refreshes the file to reflect the change made.
alias editprofile='vi ~/.bashrc'
whereas, editprofile - opens the file for editing and refprofile - refreshes the file to reflect the change made.
Happy customization!
No comments:
Post a Comment