Last active
March 13, 2020 18:29
-
-
Save canvaspixels/f363c57bf0b75dd9e203f878c71d1cae to your computer and use it in GitHub Desktop.
.bash_profile
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
export BASH_SILENCE_DEPRECATION_WARNING=1 | |
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" | |
[[ -r "/Users/$USER/.bash_user" ]] && . "/Users/$USER/.bash_user" | |
# export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home/" | |
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home" | |
export M2_HOME="/usr/local/Cellar/maven/3.3.3/libexec" | |
export M2="/usr/local/Cellar/maven/3.3.3/libexec/bin" | |
alias ct="PATH=$(npm bin):$PATH NODE_OPTIONS=--no-deprecation ct" | |
export PATH="/Users/$USER/npm:/Users/$USER/npm/bin:/usr/local/bin:/usr/local/sbin:/bin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:$CATALINA_HOME/bin:$JAVA_HOME/bin:$M2_HOME/bin:$PATH" | |
export PATH=${PATH}:/Users/${USER}/Projects/cordova/android-sdk-macosx/platform-tools:/Users/${USER}/Projects/cordova/android-sdk-macosx/tools | |
export PATH=~/.local/bin:$PATH | |
function gpss { | |
current_branch=$(git symbolic-ref --short HEAD) | |
git push -u origin "${current_branch}" | |
return 1 | |
} | |
# aliases | |
alias nr='npm run' | |
alias m='mate' | |
alias m="sublime" | |
alias s2="sublime" | |
alias c="code" | |
alias s="subl3" | |
alias l='ls -la' | |
alias ..='cd ../; ls -a' | |
alias grb='git rebase' | |
alias gco='git checkout' | |
alias gci='git commit' | |
alias gbn='git checkout -b' | |
alias gaa='git add .' | |
alias ga='git add' | |
alias gpl='git pull' | |
alias gm='git merge --no-ff' | |
alias gps='git push' | |
alias gd='git diff -w' | |
alias gl='git log' | |
alias gs='git status' | |
alias gb='git branch -a --sort=-committerdate' | |
alias gbrr='git push origin --delete' | |
# alias gbrr='git push origin' | |
alias gbrl='git branch -D' | |
# colour lookup found at http://www.ibm.com/developerworks/linux/library/l-tip-prompt/ | |
D=$'\e[37m' | |
PINK=$'\e[35;40m' | |
GREEN=$'\e[32;40m' | |
RED=$'\e[31;40m' | |
ORANGE=$'\e[33;40m' | |
CYAN=$'\e[36;40m' | |
GREYBEIGEBOLD=$'\e[1;30;47m' | |
function under_bash () { | |
[[ "`ps -p $$ | tail -1|awk '{print $NF}'`" == "-bash" ]] 2>&1 && return | |
return 1 | |
} | |
msrp_color_red=$'\e[31m' | |
msrp_color_yellow=$'\e[33m' | |
msrp_color_green=$'\e[32m' | |
msrp_color_cyan=$'\e[36m' | |
msrp_color_blue=$'\e[34m' | |
msrp_color_magenta=$'\e[35m' | |
msrp_color_white=$'\e[37m' | |
msrp_color_bold_red=$'\e[31;1m' | |
msrp_color_bold_yellow=$'\e[33;1m' | |
msrp_color_bold_green=$'\e[36;1m' | |
msrp_color_bold_cyan=$'\e[32;1m' | |
msrp_color_bold_blue=$'\e[34;1m' | |
msrp_color_bold_magenta=$'\e[35;1m' | |
msrp_color_bold_white=$'\e[37;1m' | |
msrp_reset_color=$'\e[37m' | |
# edit colours and characters here | |
############################################# | |
# msrp_user_color=$msrp_color_green - change the user to green | |
msrp_user_color=$msrp_color_cyan | |
msrp_host_color=$msrp_color_yellow | |
msrp_root_color=$msrp_color_green | |
msrp_repo_color=$msrp_color_red | |
msrp_branch_color=$msrp_color_white | |
msrp_dirty_color=$msrp_color_red | |
msrp_preposition_color=$msrp_color_white | |
msrp_promptchar_color=$msrp_color_magenta | |
msrp_time_color=$msrp_color_cyan | |
msrp_promptchar_bash='$' | |
msrp_promptchar_git='±' | |
############################################# | |
function in_git_repo { | |
git branch > /dev/null 2>&1 && return | |
return 1 | |
} | |
function in_repo { | |
(in_git_repo) && return | |
return 1 | |
} | |
function prompt_char { | |
in_git_repo && echo -ne $msrp_promptchar_git && return | |
echo $msrp_promptchar_bash | |
} | |
function location_title { | |
if in_repo; then | |
local root=$(get_repo_root) | |
local uroot="$(get_unversioned_repo_root)/" | |
echo "${root/$uroot/} ($(get_repo_type))" | |
else | |
echo "${PWD/$HOME/~}" | |
fi | |
} | |
function get_repo_type { | |
in_git_repo && echo -ne "git" && return | |
return 1 | |
} | |
function get_repo_branch { | |
in_git_repo && echo $(git branch | grep '*' | cut -d ' ' -f 2) && return | |
return 1 | |
} | |
function get_main_branch_name () { | |
in_git_repo && echo "master" && return | |
return 1 | |
} | |
function get_repo_status { | |
in_git_repo && git status --porcelain && return | |
return 1 | |
} | |
function get_repo_root { | |
in_git_repo && echo $(git rev-parse --show-toplevel) && return | |
return 1 | |
} | |
function get_unversioned_repo_root { | |
local lpath="$1" | |
local cPWD=`echo $PWD` | |
# see if $lpath is non-existent or empty, and if so, assign | |
if test ! -s "$lpath"; then | |
local lpath=`echo $PWD` | |
fi | |
cd "$lpath" &> /dev/null | |
local repo_root="$(get_repo_root)" | |
# see if $repo_root is non-existent or empty, and if so, assign | |
if test ! -s "$repo_root"; then | |
echo $lpath | |
else | |
local parent="${lpath%/*}" | |
get_unversioned_repo_root "$parent" | |
fi | |
cd "$cPWD" &> /dev/null | |
} | |
# display current path | |
function ps_status { | |
in_repo && repo_status && return | |
echo -e "$msrp_root_color${PWD/#$HOME/~} $msrp_reset_color" | |
} | |
function repo_status { | |
# set locations | |
local here="$PWD" | |
local user_root="$HOME" | |
local repo_root="$(get_repo_root)" | |
local root="`get_unversioned_repo_root`/" | |
local lpath="${here/$root/}" | |
if [[ "`echo $root`" =~ ^$user_root ]]; then | |
root=`echo "$root" | sed "s:^$user_root:~:g"` | |
fi | |
# get branch information - empty if no (or default) branch | |
local branch=$(get_repo_branch) | |
# underline branch name | |
if [[ $branch != '' ]]; then | |
if under_bash; then | |
local branch=" on \033[4m${branch}\033[0m" | |
fi | |
fi | |
# status of current repo | |
if in_git_repo; then | |
local lstatus="`get_repo_status | sed 's/^ */g/'`" | |
else | |
local lstatus='' | |
fi | |
local status_count=`echo "$lstatus" | wc -l | awk '{print $1}'` | |
# if there's anything to report on... | |
if [[ "$status_count" -gt 0 ]]; then | |
local changes="" | |
# modified file count | |
local modified="$(echo "$lstatus" | grep -c '^[gm]M')" | |
if [[ "$modified" -gt 0 ]]; then | |
changes="$modified changed" | |
fi | |
# added file count | |
local added="$(echo "$lstatus" | grep -c '^[gm]A')" | |
if [[ "$added" -gt 0 ]]; then | |
if [[ "$changes" != "" ]]; then | |
changes="${changes}, " | |
fi | |
changes="${changes}${added} added" | |
fi | |
# removed file count | |
local removed="$(echo "$lstatus" | grep -c '^(mR|gD)')" | |
if [[ "$removed" -gt 0 ]]; then | |
if [[ "$changes" != "" ]]; then | |
changes="${changes}, " | |
fi | |
changes="${changes}${removed} removed" | |
fi | |
# renamed file count | |
local renamed="$(echo "$lstatus" | grep -c '^gR')" | |
if [[ "$renamed" -gt 0 ]]; then | |
if [[ "$changes" != "" ]]; then | |
changes="${changes}, " | |
fi | |
changes="${changes}${removed} renamed" | |
fi | |
# missing file count | |
local missing="$(echo "$lstatus" | grep -c '^m!')" | |
if [[ "$missing" -gt 0 ]]; then | |
if [[ "$changes" != "" ]]; then | |
changes="${changes}, " | |
fi | |
changes="${changes}${missing} missing" | |
fi | |
# untracked file count | |
local untracked="$(echo "$lstatus" | grep -c '^[gm]?')" | |
if [[ "$untracked" -gt 0 ]]; then | |
if [[ "$changes" != "" ]]; then | |
changes="${changes}, " | |
fi | |
changes="${changes}${untracked} untracked" | |
fi | |
if [[ "$changes" != "" ]]; then | |
changes=" (${changes})" | |
fi | |
fi | |
if in_git_repo; then | |
local repo_head="`git log -n1 --oneline`" | |
local repo_head_sha=`echo $repo_head | awk '{print $1}'` | |
local repo_head_message=`echo $repo_head | grep -o ' .*$' | egrep -o '[^ ].*$'` | |
local git_repo_head=", at $msrp_host_color$repo_head_sha $msrp_preposition_color($repo_head_message)" | |
fi | |
echo -e "$msrp_root_color$root$msrp_repo_color$lpath$msrp_branch_color$branch$git_repo_head$msrp_dirty_color$update$changes" | |
} | |
function construct_prompt () { | |
echo -e "$msrp_time_color`date "+%H:%M:%S"` ${msrp_preposition_color}at $msrp_host_color`hostname -s` ${msrp_preposition_color}in $(ps_status)$msrp_promptchar_color\n$(prompt_char)" | |
} | |
if under_bash; then | |
export PS1='$(construct_prompt)\[$msrp_reset_color\] ' | |
fi | |
export DISPLAY=:0.0 | |
# use man ls for info on colours | |
export CLICOLOR=1 | |
export LSCOLORS="Gxfxcxdxbxegedabagacad" | |
if [ -f ~/.git-completion.bash ]; then | |
. ~/.git-completion.bash | |
fi | |
# Compress the cd, ls -l series of commands. | |
alias lc="cl" | |
function cl () { | |
if [ $# = 0 ]; then | |
cd && l | |
else | |
cd "$*" && l | |
fi | |
} | |
export ANDROID_HOME=/Users/$USER/Library/Android/sdk | |
export PATH=$PATH:$ANDROID_HOME/tools | |
export PATH=$PATH:$ANDROID_HOME/tools/bin | |
export PATH=$ANDROID_HOME/platform-tools:$PATH | |
export PATH="$HOME/.fastlane/bin:$PATH" | |
# increase size of .bash_history to 10000 rather than 1000 lines | |
export HISTSIZE=10000 | |
# ensures that when you exit a shell, the history from that session is appended to ~/.bash_history | |
shopt -s histappend | |
export EDITOR=nano | |
#export GIT_EDITOR=true git commit | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment