Bash Setup


Warning: count(): Parameter must be an array or an object that implements Countable in /home/cbc8fzob0jbt/domains/uhleeka.com/html/blog/wp-content/plugins/uhleeka-codebox/uhleeka-codebox.php on line 65

Base:

#green (local)
echo "export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bash_profile
#cyan (remote)
echo "export PS1='\[\e]0;\w\a\]\n\[\e[36m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bash_profile
#red (root)
echo "export PS1='\[\e]0;\w\a\]\n\[\e[31m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "export HISTSIZE=50000" >> ~/.bash_profile
echo "export HISTFILESIZE=50000" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "alias ls='ls -al --color=auto'" >> ~/.bash_profile
echo "alias grep='grep --color=auto'" >> ~/.bash_profile
echo "alias sudo='sudo '" >> ~/.bash_profile
echo "alias vi='vim'" >> ~/.bash_profile

source ~/.bash_profile

curl -o ~/.vimrc http://amix.dk/vim/vimrc.txt

Git:

echo "" >> ~/.bash_profile

echo "function ps1_git_branch {" >> ~/.bash_profile
echo "    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/';" >> ~/.bash_profile
echo "}" >> ~/.bash_profile
echo "export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\$(ps1_git_branch)\[\e[0m\]\n\$ '" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "export HISTSIZE=50000" >> ~/.bash_profile
echo "export HISTFILESIZE=50000" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "alias ls='ls -al --color=auto'" >> ~/.bash_profile
echo "alias grep='grep --color=auto'" >> ~/.bash_profile
echo "alias sudo='sudo '" >> ~/.bash_profile
echo "alias vi='vim'" >> ~/.bash_profile
echo "alias gitlog='git log --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --date=relative'" >> ~/.bash_profile

git config --global push.default simple
git config --global color.ui auto

source ~/.bash_profile

curl -o ~/.vimrc http://amix.dk/vim/vimrc.txt

Add git branch to a bash prompt

Add the following code to ~/.bash_profile or ~/.bashrc.

function ps1_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/'
}

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\$(ps1_git_branch)\[\e[0m\]\n\$ "

When in a folder that contains a .git repository, the current branch will show up in parenthesis.

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$

Looking for something more complicated? Check out richardhansen’s https://github.com/git/…/git-prompt.sh contribution.