Skip to content

Instantly share code, notes, and snippets.

@tonyta
Last active November 10, 2019 13:09
Show Gist options
  • Save tonyta/1fef791d1062e38687de to your computer and use it in GitHub Desktop.
Save tonyta/1fef791d1062e38687de to your computer and use it in GitHub Desktop.
Custom Prompt

My Custom Bash Prompt

terminal

I like that this adds a little color to and otherwise dull looking terminal window. From left to right, I'll describe what it includes:

  • a fun little alien
  • username
  • current directory
  • Ruby version (via rbenv... you'll have to change this if you use rvm)
  • Hearts that deplete throughout the day
  • Git branch
  • Git 'dirty' status shown with a lightning bolt

To load this, just paste it into your .bash_profile or, load it from another file, e.g.:

source ~/custom_prompt.bash

Aliases and Functions

Here are some useful bash aliases and functions that I load through .bash_profile as well:

### Aliases

alias l.='ls -GFhd .*'
alias ls='ls -GFh'

alias be='bundle exec'

alias tree='tree -CAF'

### Functions

function scripted {
  cd ~/Scripted
  bundle exec foreman start -f Procfile.development
}

function console {
  bundle exec pry -r ./config/environment
}

function jira {
  open 'https://scripted.atlassian.net/secure/Dashboard.jspa'
}

function gh {
  open 'https://github.com/scripted/scripted'
}

function pt {
  open 'https://www.pivotaltracker.com/n/projects/991930'
}

function ci {
  open 'https://circleci.com/gh/Scripted/Scripted'
}

function gg {
  local IFS='+'
  local query="$*"
  open "https://www.google.com/#q=${query}"
}

function gm {
  open 'https://mail.google.com/mail/u/0/#inbox'
}
# .custom_prompt
### Ruby version
function ruby_version {
rbenv version | grep --only-matching --regexp='^[0-z.\-]*'
}
### Git branch and status
function git_dirty_status {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "⚡️"
}
function git_branch {
local branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
if [ -n "$branch" ]; then
echo -e "\033[1;32mgit:\033[1;33m$branch\033[0;30m$(git_dirty_status)"
fi
}
### Hearts that diminish over time
function hearts {
local hour=$(date +%H)
if [ $hour -lt 6 ] || [ $hour -ge 24 ]; then
echo -e "\033[5m♡♡♡♡\033[m"
elif [ $hour -lt 12 ]; then
echo -e "♥♥♥♥"
elif [ $hour -lt 16 ]; then
echo -e "♥♥♥♡"
elif [ $hour -lt 20 ]; then
echo -e "♥♥♡♡"
elif [ $hour -lt 24 ]; then
echo -e "♥♡♡♡"
else
echo "Invalid Argument!" >&2
exit 1
fi
}
PS1='\n👾 \[\033[4;34m\]\u\[\033[m\]' # username
PS1=$PS1' \[\033[32m\]\w\[\033[m\]' # directory
PS1=$PS1' \[\033[31m\]🔻 $(ruby_version)\[\033[m\]' # ruby version
PS1=$PS1' \[\033[31m\]$(hearts)\[\033[m\]' # hearts
PS1=$PS1' $(git_branch)' # git info
PS1="$PS1\n \[\033[1;35m\]»\[\033[m\] " # prompt
export PS1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment