Tutorial by Examples

To change PS1, you just have to change the value of PS1 shell variable. The value can be set in ~/.bashrc or /etc/bashrc file, depending on the distro. PS1 can be changed to any plain text like: PS1="hello " Besides the plain text, a number of backslash-escaped special characters are s...
If you are inside a folder of a git repository it might be nice to show the current branch you are on. In ~/.bashrc or /etc/bashrc add the following (git is required for this to work): function prompt_command { # Check if we are inside a git repository if git status > /dev/null 2>&a...
You can have functions in the PS1 variable, just make sure to single quote it or use escape for special chars: gitPS1(){ gitps1=$(git branch 2>/dev/null | grep '*') gitps1="${gitps1:+ (${gitps1/#\* /})}" echo "$gitps1" } PS1='\u@\h:\w$(gitPS1)$ ' It will...
timeNow(){ echo "$(date +%r)" } PS1='[$(timeNow)] \u@\h:\w$ ' It will give you a prompt like this: [05:34:37 PM] user@Host:/path$ Notes: Make the changes in ~/.bashrc or /etc/bashrc or ~/.bash_profile or ~./profile file (depending on the OS) and save it. Run source ~/.ba...
This is how the author sets their personal PS1 variable: gitPS1(){ gitps1=$(git branch 2>/dev/null | grep '*') gitps1="${gitps1:+ (${gitps1/#\* /})}" echo "$gitps1" } #Please use the below function if you are a mac user gitPS1ForMac(){ git branch 2> ...
Sometimes we need a visual hint to indicate the return status of previous command. The following snippet make put it at the head of the PS1. Note that the __stat() function should be called every time a new PS1 is generated, or else it would stick to the return status of last command of your .bashr...

Page 1 of 1