Super Git console Linux
instructions
- Go to your default ubuntu console by hitting
ctrl + alt + T
or selecting it from your applications list - paste this and hit enter:
gedit ~/.bashrc
-
paste the code from the block (below) to the bottom of the now opened ~/.bashrc document on your desktop
# Git status stuff # Note: This should be placed in your .bashrc or .bash or .profile or whatever it is you use to control your # terminals appearance. # Reset Color_Off="\[\033[0m\]" # Text Reset # Regular Colors Black="\[\033[0;30m\]" # Black Red="\[\033[0;31m\]" # Red Green="\[\033[0;32m\]" # Green Yellow="\[\033[0;33m\]" # Yellow Blue="\[\033[0;34m\]" # Blue Purple="\[\033[0;35m\]" # Purple Cyan="\[\033[0;36m\]" # Cyan White="\[\033[0;37m\]" # White # Bold BBlack="\[\033[1;30m\]" # Black BRed="\[\033[1;31m\]" # Red BGreen="\[\033[1;32m\]" # Green BYellow="\[\033[1;33m\]" # Yellow BBlue="\[\033[1;34m\]" # Blue BPurple="\[\033[1;35m\]" # Purple BCyan="\[\033[1;36m\]" # Cyan BWhite="\[\033[1;37m\]" # White Time12h="\T" Time12a="\@" PathShort="\W" PathFull="\w" NewLine="\n" Jobs="\j" Login="${debian_chroot:+($debian_chroot)}$BBlue\u@\h$Color_Off:" export PS1=$Color_Off$Login$BPurple$PathFull$Color_Off'$(git branch &>/dev/null;\ if [ $? -eq 0 ]; then \ echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \ if [ "$?" -eq "0" ]; then \ # @4 - Clean repository - nothing to commit echo "'$Green'"$(__git_ps1 " {%s}"); \ else \ # @5 - Changes to working tree echo "'$BRed'"$(__git_ps1 " {%s}"); \ fi) '$Color_Off'\$ "; \ else \ # @2 - Prompt when not in GIT repo echo " '$Color_Off'\$ "; \ fi)'
Customisation
Line numbers in the description should be shown in relation to the code
file
- You can change text colors in your terminal by replacing the color-namings (where B before a color is Bold) in rule 37 to other values from 9 to 27.
Color_OFF
resets the current color to the default console color again this is necessary when applying other colors after current color to. - you can make a short path description (with only current folder instead of the full story) by replacing
PathFull
from rule 37 toPathShort
. - You can insert the current time using
$Time12h
or$time12a
- There's a Newline command to! insert it with
$NewLine
- Jobs can be viewed as well by inserting
$Jobs
Good luck!
Written by Hendrik Peter
Related protips
1 Response
thx for sharing i didnt try but i use this https://github.com/magicmonty/bash-git-prompt and it seems to be the best git ps1 i found so far. PS. i changed it to include the current timestamp for practical reasons
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#