Skip to content

Instantly share code, notes, and snippets.

@zulaica
Last active May 8, 2020 11:22
Show Gist options
  • Save zulaica/a70903e4cd588f5a2ca19388de72a7f2 to your computer and use it in GitHub Desktop.
Save zulaica/a70903e4cd588f5a2ca19388de72a7f2 to your computer and use it in GitHub Desktop.
Super Prompt
###
# Super Prompt
#
# Output:
# πŸ“‚ WORKING_DIRECTORY : 🌱 GIT_BRANCH
# πŸ’Ž RUBY_VERSION-pPATCH@GEMSET : πŸ›€ RAILS_VERSION : 🐹 EMBER_VERSION : β˜‘οΈοΈ TYPESCRIPT_VERSION : πŸ’  NODE_VERSION
# πŸ’°
#
# WTF:
# 1. WORKING_DIRECTORY displays in the default color.
# 2. GIT_BRANCH only displays when working in a directory with git initialized.
# 3. GIT_BRANCH displays in light green when clean, light yellow when dirty.
# 4. RUBY_VERSION displays in light red.
# 5. Ruby PATCH number and GEMSET display only if they are not the default.
# 6. RAILS_VERSION displays in light grey, if installed.
# 7. EMBER_VERSION displays in orange, if installed.
# 8. TYPESCRIPT_VERSION displays in cobalt blue, if installed.
# 9. TYPESCRIPT_VERSION displays workspace version if different than global.
# 10. NODE_VERSION displays in dark green.
# 11. πŸ’° is your prompt
#
###
###
# Formatting
###
C_DEFAULT="\x1B[00m"
C_DIVIDER="\x1B[90m" # Dark Grey
C_EMBER="\x1B[38;5;214m" # Orange
C_GIT_CLEAN="\x1B[92m" # Light Green
C_GIT_DIRTY="\x1B[93m" # Light Yellow
C_RAILS="\x1B[37m" # Light Grey
C_RUBY="\x1B[91m" # Light Red
C_TYPESCRIPT="\x1B[38;5;32m" # Cobalt Blue
C_NODE="\x1B[38;5;34m" # Dark Green
DIVIDER="$C_DIVIDER : $C_DEFAULT"
HORIZONTAL_RULE="$C_DIVIDER\n
\r╠══════════════════════════════════════════════════════════════════════════════╣\n
$C_DEFAULT"
###
# Functions
###
currentGitBranch() {
GIT_STATUS="$(git status --porcelain 2> /dev/null)"
if [[ ${GIT_STATUS} == "" ]]
then
C_GIT_STATUS=${C_GIT_CLEAN}
else
C_GIT_STATUS=${C_GIT_DIRTY}
fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
[ "$CURRENT_BRANCH" != "" ] && CURRENT_BRANCH="🌱 $CURRENT_BRANCH"
if [ "$CURRENT_BRANCH" != "" ]
then
echo -e "$DIVIDER$C_GIT_STATUS$CURRENT_BRANCH"
fi
}
currentRubyAndGemset() {
RUBY=$(echo "$RUBY_VERSION" | awk -F'-' '{print $2}')
RUBY_PATCH=$(echo "$MY_RUBY_HOME" | awk -F'p' '{print $2}')
[ "$RUBY_PATCH" != "" ] && RUBY_PATCH="-p$RUBY_PATCH"
GEMSET=$(echo "$GEM_HOME" | awk -F'@' '{print $2}')
[ "$GEMSET" != "" ] && GEMSET="@$GEMSET"
echo -e "πŸ’Ž $C_RUBY$RUBY$RUBY_PATCH$GEMSET$DIVIDER"
}
currentRails() {
# `rails --version` is slower to execute when a non-default version of Rails
# is being used. First check to see if a Gemfile.lock exists and parse the
# Rails version out of it, otherwise just run `rails --version`.
if [ -f Gemfile.lock ]
then
RAILS=$(awk '/( rails )/ { print $2 }' Gemfile.lock)
RAILS=$(echo "$RAILS" | awk '{ gsub ("[()=<>]", ""); print $0 }')
else
RAILS=$(rails --version | awk -F'Rails ' '{ print $2 }')
[ "$RAILS" != "" ] && rails="$rails"
fi
echo -e "πŸ›€ $C_RAILS$RAILS$DIVIDER"
}
currentNode() {
if which node &> /dev/null
then
NODE=$(node --version)
echo -e "πŸ’  $C_NODE$NODE$C_DEFAULT"
fi
}
currentEmber() {
$(type ember > /dev/null 2> /dev/null)
if [ $? == 0 ]
then
EMBER=$(ember version | awk -F'ember-cli: ' '{ print $2 }')
echo -e "🐹 $C_EMBER$EMBER$DIVIDER"
fi
}
currentTypeScript() {
$(type tsc > /dev/null 2> /dev/null)
if [ $? == 0 ]
then
if [ -f node_modules/typescript ]
then
TYPESCRIPT=$(node_modules/typescript/bin/tsc -v | awk -F'Version ' '{ print $2 }')
else
TYPESCRIPT=$(tsc -v | awk -F'Version ' '{ print $2 }')
fi
echo -e "β˜‘οΈοΈ $C_TYPESCRIPT$TYPESCRIPT$DIVIDER"
fi
}
###
# Output
###
PS1="$(echo -e $HORIZONTAL_RULE)
πŸ“‚ \W\$(currentGitBranch)
\$(currentRubyAndGemset)\$(currentRails)\$(currentEmber)\$(currentTypeScript)\$(currentNode)
πŸ’° "
export PS1
@zulaica
Copy link
Author

zulaica commented Mar 23, 2017

screen shot 2017-04-06 at 9 06 04 pm

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