Created
February 25, 2015 18:28
-
-
Save nickcarenza/1aa14818dd47426e2f5c to your computer and use it in GitHub Desktop.
Messing with the shell prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bold=`tput bold` | |
normal=`tput sgr0` | |
prompt_user() { | |
echo "${bold}\u${normal} in ${bold}\W${normal} >> " | |
} | |
prompt_vagrant() { | |
# Find closest .vagrant folder or exit | |
# @TODO | |
# Get Vagrant ID files | |
# find .vagrant -name id | |
# find .vagrant -name id -exec cat {} \; -exec echo "" \; | |
# List VMs | |
# VBoxManage list vms | |
# Matchs IDs against VMs | |
# - non-matches are "not started" | |
# - matches can be "up" "down" or "suspended" | |
echo "${bold}vm_name${normal} is ${bold}up${normal} >> " | |
} | |
# BUG freaks out when initializing a new repo | |
prompt_git() { | |
BRANCH=$(git status -sb 2> /dev/null | head -n 1 | cut -c 4-) | |
if [ -n "$BRANCH" ]; then | |
(git fetch origin &) &> /dev/null | |
tabname $(basename $(git rev-parse --show-toplevel 2> /dev/null)):$(git rev-parse --abbrev-ref HEAD 2> /dev/null) | |
echo "on branch ${bold}${BRANCH}${normal} >> " | |
else | |
tabname $(whoami)@$(basename $(pwd)) | |
fi | |
} | |
export PS1="$(prompt_user)\$(prompt_vagrant)\$(prompt_git)\n $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment