Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Last active February 9, 2021 22:30
Show Gist options
  • Save igoralves1/0906569190edb3b92b95bd26de324b01 to your computer and use it in GitHub Desktop.
Save igoralves1/0906569190edb3b92b95bd26de324b01 to your computer and use it in GitHub Desktop.
Show your branch name on the Linux prompt, changing .bashrc on Ubuntu 16.04.
Show your branch name on the Linux prompt. Updated
1-Go to ~/ directory, or /home/"username";
2-type sudo subl .bashrc. So this will be the full command ila@ig:~$ sudo subl .bashrc. That will open the .bashrc file
3-After this Introductory sentence of the .bashrc:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
4-Put this function declaration:
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
5-Find this portion of the code:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
6-And change for this:
if [ "$color_prompt" = yes ]; then
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' #Igor put in comment
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' #Igor added this line
else
#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' #Igor put in comment
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ ' #Igor added this line
fi
unset color_prompt force_color_prompt
7-GO to the master directory, make a `$git add .` and `$git commit -m "The first commit"` IF IT WAS NOT DONE BEFORE.
THE SHELL WILL BE ABLE TO SEE THE BRANCH NAME JUST AFTER THE FIRST COMMIT WAS DONE.
At the end of this process you will have a colored shell with the git branch name.
https://www.leaseweb.com/labs/2013/08/git-tip-show-your-branch-name-on-the-linux-prompt/
=========
Para computadores MAC
1-Criar um arquivo `touch .bash_profile` se nao existir
2-Ir em Terminal > preferences > General > Shells Open with `/bin/bash`. Make it sure that it points to `/bin/bash`. Other options could be `/bin/zsh` or `/bin/ksh` or `/bin/tcsh` or `/bin/bash` or `/bin/sh` https://osxdaily.com/2012/03/21/change-shell-mac-os-x/
3-Usar o seguinte codigo dentro do `.bash_profile`
`
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
`
Se quiser outras configuracoes de cores estudar as opcoes desse arquivo para `zshrc` - https://github.com/olivierverdier/zsh-git-prompt/blob/master/zshrc.sh
Tbm estudar => https://www.youtube.com/watch?v=j6vKLJxAKfw&list=PL-osiE80TeTvGhHkpvfmKWOiIPF8UVy6c
OLD .bash_profile that is working:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
alias ll='ls -al'
alias vh='cd ~/Documents/vhosts'
alias ~='cd ~'
alias fwBreakdown_node_ec2='ssh -i "/Users/ialves/Documents/ec2_access_scican.pem" ubuntu@ec2-54-209-138-210.compute-1.amazonaws.com'
export PATH="$PATH:/Users/ialves/Documents/vhosts/flutter/bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment