Last active
August 13, 2016 17:28
-
-
Save tonylukasavage/8346694 to your computer and use it in GitHub Desktop.
custom bash prompt for Titanium/Alloy development (and git) Shows the git branch in the current working directory, as well as the Titanium SDK and Alloy version if you are in a Titanium project. The git branch will also show a star (*) next to it if the branch has uncommitted changes. I'm using this with Mac OSX 10.9.1 Terminal and the Droid San…
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
find-up() { | |
local path=$(pwd) | |
while [[ "$path" != "" && ! -e "$path/$1" ]]; do | |
path=${path%/*} | |
done | |
if [ "$path" != "" ] | |
then | |
echo "$path" | |
fi | |
} | |
parse_git_branch() { | |
local branch=$(echo -n $(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')) | |
if [ ! -z "$branch" ]; then | |
[[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && branch="$branch*" | |
echo -en "--(\\033[2;37m$branch\\033[0;0m)" | |
fi | |
} | |
parse_alloy_version() { | |
local version=$(alloy --version 2> /dev/null | sed -e 's/\(.*\)/\1/') | |
if [ ! -z "$version" ]; then | |
echo -n "‡" | |
echo -en "\\033[0;36m$version\\033[0;0m" | |
fi | |
} | |
parse_titanium_version() { | |
local tiapp=`find-up tiapp.xml` | |
if [ -z "$tiapp" ]; then return; fi | |
local tiversion=$(cat $tiapp/tiapp.xml 2> /dev/null | sed -n 's/<sdk-version>\(.*\)<\/sdk-version>/\1/p' | tr -d ' \t\n\r\f') | |
if [ -z "$tiversion" ]; then return; fi | |
echo -en "--(\\033[2;36m$tiversion\\033[0;0m" | |
parse_alloy_version | |
echo -n ")" | |
} | |
export PS1="\n(\033[0;32m\w\033[0;0m)\$(parse_git_branch)\$(parse_titanium_version)\n≫ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend changing:
$(cat $tiapp/tiapp.xml 2> /dev/null | sed -n 's/(.)</sdk-version>/\1/p' | tr -d ' \t\n\r\f')
to
$(cat "$tiapp/tiapp.xml" 2> /dev/null | sed -n 's/(.)</sdk-version>/\1/p' | tr -d ' \t\n\r\f')
This allows things to work when the project is in a sub-dir of a dir with a space in the name