Skip to content

Instantly share code, notes, and snippets.

@CjMoore
Last active April 13, 2017 20:30
Show Gist options
  • Save CjMoore/13565b944d20d102488812d51b9d5630 to your computer and use it in GitHub Desktop.
Save CjMoore/13565b944d20d102488812d51b9d5630 to your computer and use it in GitHub Desktop.

BASH

What is the Shell/BASH?

Shell is a command language. Over time people have developed different varities of shell by adding extra features

  • BASH(Born Again SHell)
  • Other types of command processors
    • zsh - Another type of command processor that is extremely powerful. It was built off of BASH but has more features. You can customize it to autocomplete github repos. Unlike BASH, zsh does not follow POSIX standards.
    • tcsh

What is your .bash_profile?

You can also run bash commands from a file, this is called a script. Your bash profile runs scripts everytime you open it. If you have a styled bash prompt it is stored in your profile as a script.

How to customize your BASH prompt

  1. Open .bash_profile in your favorite text editor
  2. What do you see?
  3. Here are some generators you can use to style your prompt
  4. Find the generated output and add it to your bash profile.
    • It should look something like this. export PS1="\[\033[38;5;10m\]\H\[$(tput sgr0)\]\[\033[38;5;14m\]-\[$(tput sgr0)\]"
  5. Restart your terminal and see your fancy new prompt.

How to add your current branch to your BASH prompt

Reference

  1. Add this code somewhere in your .bash_profile
parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
  1. Call the function parse_git_branch in your prompt.
  • It should look like this:
export PS1="\[\033[38;5;10m\]\H\[$(tput sgr0)\]\[\033[38;5;14m\]-\[$(tput sgr0)\]$(parse_git_branch)\[38;5;14m\]"
  1. Return to your terminal and run source ~/.bash_profile

  2. If that didnt work try following this guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment