Saturday, June 8, 2019

Linux Shell/bash customize

Easy bash prompt: http://ezprompt.net/


The current shell can be identified by using the SHELL environment variable in Linux.
echo $SHELL

For Global change:
sudo vi /etc/bash.bashrc

For Local change: 
~/.bashrc or ~/.bash_profile

echo $SHELL
ls -al ~/.
vi ~/.bashrc
vi /etc/bashrc

echo -e "\e[31mHello ${USER}!\e[0m"

sudo su
su ec2-user

source ~/.bashrc


$ vi ~/.bashrc
echo -e "\e[31mHello ${USER}!\e[0m" $ source ~/.bash

Example 3: Welcome message
echo "Welcome ${USER} to Node1!"


 

To show current branch name in Ubuntu Terminal type  below commands to related lines in the ~/.bashrc:

 

Find “PS1” in .bashrc like:

if [ "$color_prompt" = yes ]; then 

PS1= ...

else 

    PS1= ...

fi 

 

instead of above lines, paste blow lines

# git branch info if present

parse_git_branch() {

    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'

}

 

if [ "$color_prompt" = yes ]; then

   PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[33m\]$(parse_git_branch)\[\033[00m\]\$ '

else

   PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '

fi









No comments:

Post a Comment