Last active
May 8, 2020 11:22
-
-
Save zulaica/a70903e4cd588f5a2ca19388de72a7f2 to your computer and use it in GitHub Desktop.
Super Prompt
This file contains hidden or 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
### | |
# 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 |
Author
zulaica
commented
Mar 23, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment