Skip to content

Instantly share code, notes, and snippets.

@theodson
Last active April 5, 2016 14:48
Show Gist options
  • Save theodson/2fe773d493cb674fde03 to your computer and use it in GitHub Desktop.
Save theodson/2fe773d493cb674fde03 to your computer and use it in GitHub Desktop.
# ENV
export MVN_HOME=~/tools/apache-maven-3
export ANT_HOME=~/tools/apache-ant-1.9.6
export VAGRANT_DEFAULT_PROVIDER=virtualbox
export WORKSPACE=~/Workspace
export PATH="$(brew --prefix homebrew/php/php70)/bin:~/bin:~/.composer/vendor/bin:~/tools/apache-maven-3/bin:$ANT_HOME/bin:~/packer:$PATH"
# Coloured ls
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
alias ls='ls -GFh'
alias ll='ls -la'
# General
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
alias prettyjson='python -m json.tool'
alias nospace='egrep -v "^#|^[[:space:]]*$"'
# https://nektony.com/products/funter OSX tool - Show/Hide hidden files in Finder
alias showhidden='defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder'
alias hidehidden='defaults write com.apple.finder AppleShowAllFiles FALSE && killall Finder'
# Force empty the trash
alias forceempty='sudo rm -rf ~/.Trash; sudo rm -rf /Volumes/*/.Trashes;'
# Reset to last commit and remove untracked files and directories.
alias nah='git reset --hard; git clean -df'
# Laravel Artisan
alias art='php artisan'
alias artisan='php artisan'
# PHP Testing
alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'
# Vagrant conveniences
alias vagrant='HOMESTEADVM='\''centos'\'' vagrant'
alias print_vagrant_ids='[ -e .vagrant/machines/default/virtualbox/id ] && echo -e "\n$(VBoxManage list vms | grep $(cat .vagrant/machines/default/virtualbox/id))"'
alias v_glob='vagrant global-status --prune'
alias v_kill='print_vagrant_ids; vagrant destroy -f'
alias v_noprov='vagrant up --no-provision'
alias v_stat='vagrant status'
alias vagrant='HOMESTEADVM='\''centos'\'' vagrant'
# Common commands
#source ~/bin/dev.commands.sh
# .NET https://github.com/tonysneed/VsCode-AspNet5-OsX , http://stackoverflow.com/questions/29952630/how-to-get-the-dnu-command-working-on-os-x
source dnvm.sh
# Auto Complete in BASH
if [ -f `brew --prefix`/etc/bash_completion ]; then
source `brew --prefix`/etc/bash_completion
fi
if [ -f `brew --prefix`/etc/bash_completion.d/vagrant ]; then
source `brew --prefix`/etc/bash_completion.d/vagrant
fi
confirm () {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
# Maven and JAVA on command line
function java6 () {
JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export JAVA_HOME
}
function java7 () {
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7/Contents/Home
export JAVA_HOME
}
function java8 () {
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home
export JAVA_HOME
}
function mvnhome32() {
MVN_HOME=~/tools/apache-maven-3.2.5
export MVN_HOME
rm -f ~/tools/apache-maven-3
ln -s $MVN_HOME ~/tools/apache-maven-3
}
function mvnhome33() {
MVN_HOME=~/tools/apache-maven-3.3.9
export MVN_HOME
rm -f ~/tools/apache-maven-3
ln -s $MVN_HOME ~/tools/apache-maven-3
}
function termtitle() {
printf "\033]0;%s\007" "$1"
}
# http://brettterpstra.com/2009/11/17/my-new-favorite-bash-prompt/
function fmt_time() { #format time just the way I likes it
if [ `date +%p` = "PM" ]; then
meridiem="pm"
else
meridiem="am"
fi
date +"%l:%M:%S$meridiem"|sed 's/ //g'
}
function pwdtail() { #returns the last 2 fields of the working directory
pwd|awk -F/ '{nlast = NF -1;print $nlast"/"$NF}'
}
function op() {
#export GREEN="\033[0;32m"
#export RED="\033[0;31m"
RESETCOLOR="\033[0;00m"
RESETCOLOR="$(tput setaf 0 2>/dev/null || echo '\e[0;00m')" # Black
BLACK="$(tput setaf 0 2>/dev/null || echo '\e[0;30m')" # Black
RED="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" # Red
GREEN="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" # Green
YELLOW="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" # Yellow
BLUE="$(tput setaf 4 2>/dev/null || echo '\e[0;34m')" # Blue
PURPLE="$(tput setaf 5 2>/dev/null || echo '\e[0;35m')" # Purple
CYAN="$(tput setaf 6 2>/dev/null || echo '\e[0;36m')" # Cyan
WHITE="$(tput setaf 7 2>/dev/null || echo '\e[0;37m')" # White
rootfolder="${WORKSPACE:-~/Documents}"
found=0 # 0 = Not Found; 1 = Found
project="$1" # Name of project given
repo="$2" # Name of repository given
count=0 # Array counter
# Following is in order of preference
if [[ $repo != "" ]]; then # Change to project repo
directories[$count]=$rootfolder/$project/$repo; ((count++));
directories[$count]=$rootfolder/stash-$project/$repo; ((count++));
directories[$count]=$rootfolder/stash-${project}*/bgdevlab-${repo}; ((count++));
directories[$count]=$rootfolder/stash-${project}*/${repo}*; ((count++));
fi
# Usually webapp is the common repo if no repo was specified
directories[$count]=$rootfolder/$project/webapp; ((count++));
directories[$count]=$rootfolder/stash-$project/webapp; ((count++));
directories[$count]=$rootfolder/$project/$project; ((count++));
directories[$count]=$rootfolder/stash-$project/$project; ((count++));
directories[$count]=$rootfolder/$project; ((count++));
directories[$count]=$rootfolder/stash-$project; ((count++));
directories[$count]=$rootfolder/stash-${project}*; ((count++));
# Look for possible project folders and change into it if one found.
for dir in ${directories[@]}; do
if [[ -d $dir ]]; then
found=1
cd $dir
echo -e "Changed directory to: '${GREEN}$dir${RESETCOLOR}'"
break
fi
done
termtitle "$(pwdtail)"
# Was folder changed?
if [[ $found == 0 ]]; then
echo -e "${RED}Project directory '$dir' not found!${RESETCOLOR}"
fi
}
# Command PROMPT FILE
# Different options for prompts
function parentpath() {
current="$(pwd)"
parent="$(basename $(dirname "$(pwd)"))"
if [ "$current" != ~ ] && [ "$current" != '/' ] && [ "$parent" != '/' ]; then
echo "[${parent}]"
fi
}
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
# These are taken from https://github.com/jimeh/git-aware-prompt
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch="$branch"
else
git_branch=""
fi
#RESET=$(tput sgr0)
#[ ! -z "${git_branch}" ] && echo "[${git_branch}]$RESET " || echo "$RESET"
}
find_git_dirty() {
# These are taken from https://github.com/jimeh/git-aware-prompt
local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
git_dirty='*'
else
git_dirty=''
fi
#echo "${git_dirty}"
}
# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html
# Bash provides an environment variable called PROMPT_COMMAND. The contents of this variable are executed as a regular Bash command just before Bash displays a prompt.
PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
function prompt_custom () {
# Regular
BLACK="$(tput setaf 0 2>/dev/null || echo '\e[0;30m')" # Black
RED="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" # Red
GREEN="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" # Green
YELLOW="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" # Yellow
BLUE="$(tput setaf 4 2>/dev/null || echo '\e[0;34m')" # Blue
PURPLE="$(tput setaf 5 2>/dev/null || echo '\e[0;35m')" # Purple
CYAN="$(tput setaf 6 2>/dev/null || echo '\e[0;36m')" # Cyan
WHITE="$(tput setaf 7 2>/dev/null || echo '\e[0;37m')" # White
# Bold
BLACKBOLD="$(tput setaf 0 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;30m')" # Black
REDBOLD="$(tput setaf 1 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;31m')" # Red
GREENBOLD="$(tput setaf 2 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;32m')" # Green
YELLOWBOLD="$(tput setaf 3 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;33m')" # Yellow
BLUEBOLD="$(tput setaf 4 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;34m')" # Blue
PURPLEBOLD="$(tput setaf 5 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;35m')" # Purple
CYANBOLD="$(tput setaf 6 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;36m')" # Cyan
WHITEBOLD="$(tput setaf 7 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;37m')" # White
REVERSE=$(tput rev)
RESET=$(tput sgr0)
#export PS1="$BLUE[\$(parentpath)][\W]$DKGRAY$BRANCH $GREEN $RESETCOLOR"
export PS1="\[$GREEN\]\[$REVERSE\]\$git_branch\[$RESET\]\[$BLUE\]\$(parentpath)[\W]\[$RESET\]$git_dirty\$ "
export PS2="> "
export SUDO_PS1="\[$PURPLE\]\u@\h\[$RESET\] \w\$ "
}
prompt_custom
@bgdevlab
Copy link

bgdevlab commented Mar 7, 2016

Issue I have with this is strange wrapping onto the same line and oddities when deleting characters, any ideas?

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