Skip to content

Instantly share code, notes, and snippets.

@damouse
Last active June 12, 2018 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damouse/85e8f43913f591e2d0fa to your computer and use it in GitHub Desktop.
Save damouse/85e8f43913f591e2d0fa to your computer and use it in GitHub Desktop.
Personal bashrc, shared and updated among many, many machines running all kinds of OS. Self updating with rcpush and rcpull.
# Damouse's autoupdateing bash script, with autoupdating and sublime syncing
#
# To install: remove .bashrc, git clone git@github.com:85e8f43913f591e2d0fa.git, and move contents into home directory
#
# Go commands required for GoOracle:
# go get -u golang.org/x/tools/cmd/goimports
# go get -u golang.org/x/tools/cmd/vet
# go get -u golang.org/x/tools/cmd/oracle
# go get -u golang.org/x/tools/cmd/godoc
#
# Symlinking subl on OSX
# sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
####################
# Configuration and Constants
####################
# Origin for sublime settings
SUBL_ORIGIN="git@github.com:damouse/sublime-packages.git"
# Platform specific config
if [[ "$(uname)" == 'Linux' ]]; then
OSX=false
SUBL_PKG_PATH=$HOME/.config/sublime-text-3/Packages/User
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
elif [[ "$(uname)" == 'Darwin' ]]; then
OSX=true
SUBL_PKG_PATH=${HOME}/Library/Application\ Support/Sublime\ Text\ 3/Packages/User
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
# Turn off mouse acceleration
defaults write .GlobalPreferences com.apple.mouse.scaling -1
# Turn off key symbol suggestions
defaults write -g ApplePressAndHoldEnabled -bool false
# Allow apps downloaded from anywhere. This needs to be sudo
# spctl --master-disable
fi
####################
# Environment Variables
####################
[[ -s "${HOME}/.gvm/scripts/gvm" ]] && source "${HOME}/.gvm/scripts/gvm"
[[ -s "${HOME}/.rvm/scripts/rvm" ]] && source ~/.rvm/scripts/rvm
# Swiftenv
export SWIFTENV_ROOT=~/.swiftenv
export PATH=$SWIFTENV_ROOT/bin:$PATH
[[ -s "${HOME}/.swiftenv/" ]] && eval "$(swiftenv init -)"
# Set default GOPATH for all versions of GO
export GOPATH=$HOME/code/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH/bin
export EDITOR=subl
# GoPy
export PKG_CONFIG_PATH=/System/Library/Frameworks/Python.framework/Versions/2.7/lib/pkgconfig
# Maven
export PATH=$PATH:$HOME/code/java/apache-maven/bin
# Android Tools
export PATH=$PATH:$HOME/code/libs/platform-tools
# Java through PPA as linked here: http://askubuntu.com/questions/521145/how-to-install-oracle-java-on-ubuntu-14-04
export ANDROID_HOME=$HOME/Android/Sdk
# Homebrew things
export PATH=$PATH:/usr/local/sbin
# gradle
export PATH=$HOME/Documents/android-studio/gradle/gradle-2.8/bin:"${PATH}"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PATH="$PATH:$HOME/.rvm/bin"
####################
# Custom commands
####################
# go up the passed set of directories
# Usage: up 3, or up
up(){
local d=""
limit=$1
for ((i=1 ; i <= limit ; i++))
do
d=$d/..
done
d=$(echo $d | sed 's/^\///')
if [ -z "$d" ]; then
d=..
fi
cd $d
}
# Kill the last backgrounded task
kbg(){
bg
kill $!
kill $!
}
pyserve(){
python -m SimpleHTTPServer
}
# Update this profile and reload it
rcpull() {
git -C ~ pull origin master
source ~/.bashrc
}
# commit changes and push them back up
rcpush() {
git -C ~ add ~/.bashrc
git -C ~ commit -m "Automatic update $(date +%Y-%m-%d) from $(hostname)"
git -C ~ push origin master
}
# Synchronize sublime text packages and settings with origin
subpull() {
git -C "$SUBL_PKG_PATH" pull origin master
}
subpush() {
git -C "$SUBL_PKG_PATH" add --all
git -C "$SUBL_PKG_PATH" commit -m "Automatic update $(date +%Y-%m-%d) from $(hostname)"
git -C "$SUBL_PKG_PATH" pull origin master
git -C "$SUBL_PKG_PATH" push origin master
}
# bootstrap sublime text pacakges and settings
subbootstrap() {
if [ ! subl &> /dev/null ]; then
echo "Sublime text doesnt appear to be installed (subl command did not execute"
fi
# Note: existing pacakges NOT merged in1!
git clone $SUBL_ORIGIN $SUBL_PKG_PATH.tmp
}
# Add and commit to the current branch in one step
gac() {
git add --all :/
git commit -a -m "$*"
}
gap() {
git add --all :/
git commit -a -m "$*"
git push
}
glog() {
git log --oneline --graph --decorate
}
astudio() {
~/Documents/android-studio/bin/studio.sh
}
####################
# Bash customization
####################
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
####################
# Coloring
####################
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
# don't put duplicate lines in the history. See bash(1) for more options
HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
HISTCONTROL=ignoreboth
#Color defines
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
# Bold
BBlack='\e[1;30m' # Black
BRed='\e[1;31m' # Red
BGreen='\e[1;32m' # Green
BYellow='\e[1;33m' # Yellow
BBlue='\e[1;34m' # Blue
BPurple='\e[1;35m' # Purple
BCyan='\e[1;36m' # Cyan
BWhite='\e[1;37m' # White
# Underline
UBlack='\e[4;30m' # Black
URed='\e[4;31m' # Red
UGreen='\e[4;32m' # Green
UYellow='\e[4;33m' # Yellow
UBlue='\e[4;34m' # Blue
UPurple='\e[4;35m' # Purple
UCyan='\e[4;36m' # Cyan
UWhite='\e[4;37m' # White
# Background
On_Black='\e[40m' # Black
On_Red='\e[41m' # Red
On_Green='\e[42m' # Green
On_Yellow='\e[43m' # Yellow
On_Blue='\e[44m' # Blue
On_Purple='\e[45m' # Purple
On_Cyan='\e[46m' # Cyan
On_White='\e[47m' # White
# High Intensity
IBlack='\e[0;90m' # Black
IRed='\e[0;91m' # Red
IGreen='\e[0;92m' # Green
IYellow='\e[0;93m' # Yellow
IBlue='\e[0;94m' # Blue
IPurple='\e[0;95m' # Purple
ICyan='\e[0;96m' # Cyan
IWhite='\e[0;97m' # White
# Bold High Intensity
BIBlack='\e[1;90m' # Black
BIRed='\e[1;91m' # Red
BIGreen='\e[1;92m' # Green
BIYellow='\e[1;93m' # Yellow
BIBlue='\e[1;94m' # Blue
BIPurple='\e[1;95m' # Purple
BICyan='\e[1;96m' # Cyan
BIWhite='\e[1;97m' # White
# High Intensity backgrounds
On_IBlack='\e[0;100m' # Black
On_IRed='\e[0;101m' # Red
On_IGreen='\e[0;102m' # Green
On_IYellow='\e[0;103m' # Yellow
On_IBlue='\e[0;104m' # Blue
On_IPurple='\e[0;105m' # Purple
On_ICyan='\e[0;106m' # Cyan
On_IWhite='\e[0;107m' # White
#this version includes the user name as the first term of the terminal line
#PS1='\[\e[0;36m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '
# \e[1;32m
if $OSX == true; then
PS1="\[${IBlue}\]\w\[\e[m\] \[${Green}\]\$\[\e[m\] "
else
PS1="\[${Blue}\]\w\[\e[m\] \[${Green}\]\$\[\e[m\] "
fi
############### Aliases and Power User commands ##################
alias histg="history|grep "
alias findg="find . |grep "
alias psg="ps -aux |grep "
alias lsg="ls | grep "
# alias o="gnome-open "
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval $(dircolors -b $HOME/.dircolors)
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment