Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active December 14, 2015 19:08
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 joyrexus/5133969 to your computer and use it in GitHub Desktop.
Save joyrexus/5133969 to your computer and use it in GitHub Desktop.
My base bash environment.
# My base ~/.bash_profile
SHELL=/bin/bash
PS1='\[\033[0;32m\]\w\[\033[0;33m\]$\[\033[0m\] ' # colored version of '\w\$ '
PS2='> '
ENV=~/.bashrc
PROFILE=~/.bash_profile
PATH=.:/usr/local/share/python:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/
sbin:/usr/X11/bin:/usr/texbin
MANPATH=usr/local/share/man:/usr/share/man
INFOPATH=/usr/share/info
VIM=/usr/share/vim
VIMRUNTIME=$VIM/vim72
EDITOR=/usr/bin/vim
SVN_EDITOR=$EDITOR
PAGER='less -RsMe'
LESS='-m'
DICT=/usr/share/dict/words
LC_ALL="en_US.UTF-8"
LANG="en_US"
# Colorize ls output
CLICOLOR=1
LSCOLORS=exfxcxdxbxegedabagCxEx
# Node
NPM_BIN=/usr/local/share/npm/bin
NPM_LIB=/usr/local/share/npm/lib/node_modules
NODE_PATH=.:$NPM_LIB:$LDP_LIB/node:$LDP_LIB/coffee
PATH=$NPM_BIN:$PATH
# Python
export PYTHONPATH=$LDP_LIB/python:$LIB/python
export PYTHONSTARTUP="/Users/jvoigt/.pystartup"
# Perl
PERLDIR=/System/Library/Perl/5.10.0
PERLLIB=/Library/Perl/5.10.0:/System/Library/Perl/5.10.0:$LIB/perl
. ~/.bashrc # Source environment for custom aliases and bash functions
umask 022
set -o vi
set -o noclobber
set -o notify
set -o allexport
shopt -s expand_aliases
shopt -s extglob
shopt -s nocaseglob # Case-insensitive globbing (used in pathname expansion)
shopt -s cmdhist
shopt -s histappend # Append to the Bash history file, rather than overwriting it
# My base ~/.bashrc
#
# Remember, use ...
# `help` to get help
# `env` to see environment
# `alias` to see aliases
# `declare -f` to see defined functions
# `declare -F` for non-verbose output
# FUNCTIONS/COMMANDS
# Make a file executable
cx () {
chmod ug+x $*
}
# Show revision number of repo
svnrev () {
svn info $1 | awk '/Rev:/ { sub(/.*: /, ""); print }'
}
# Start the subversion server
svnstart () {
svnserve -d -r ~/svn --listen-port=3690
}
# Remove directory from svn revision control
nosvn () {
DIR=${1:-"."}
if [ ! -d $DIR ]; then
echo "You need to specify a directory";
break
fi
read -e -p "Remove $DIR from revision control? (y/n): " CHOICE
if [ $CHOICE == "y" ]; then
find $DIR -name ".svn" -print0 | xargs -0 rm -Rf
fi
}
# Manage a simple HTTP server
# Usage: http start|stop|restart [port]
http () {
local port="${2:-8000}"
case $1 in
"start")
echo "starting http server"
nohup python -m SimpleHTTPServer >| /tmp/nohup.out &
open "http://localhost:${port}/"
;;
"stop")
echo "stopping http server"
kill $(ps aux | grep "python -m SimpleHTTPServer" \
| grep -v grep \
| awk '{print $2}') > /dev/null
;;
"restart")
echo "restarting http server"
kill $(ps aux | grep "python -m SimpleHTTPServer" \
| grep -v grep | awk '{print $2}') > /dev/null
nohup python -m SimpleHTTPServer >| /tmp/nohup.out &
;;
*)
echo "need start|stop|restart"
esac
}
# Convert restructuredText file to HTML
rst2html () {
FILE=$(echo $1 | sed s/rst/html/)
rst2html.py --stylesheet-path $CSS/style.css $1 >| $FILE
open $FILE
}
# DIR ALIASES
alias b="$BIN"
alias l="$LIB"
alias w=$WORK
alias x="$SANDBOX"
# COMMAND ALIASES
alias d='dirs -v'
alias r='pushd +1'
alias 0='pushd +0 > /dev/null ; dirs -v'
alias 1='pushd +1 > /dev/null ; dirs -v'
alias 2='pushd +2 > /dev/null ; dirs -v'
alias 3='pushd +3 > /dev/null ; dirs -v'
alias 4='pushd +4 > /dev/null ; dirs -v'
alias 5='pushd +5 > /dev/null ; dirs -v'
alias cp='cp -i'
alias rm='rm -i'
alias mv='mv -i'
alias vi='vim '
alias du='du -hc -d 1 '
alias ls='ls -F'
alias cd='cd '
alias cdc='cd ~; clear'
alias rmc='rm -f *class *pyc'
alias fix="perl -pi -e 's/\r/\n/g'" # fix line returns
alias unfix="perl -pi -e 's/\n/\r/g'" # unfix line returns
alias unmount='diskutil unmountDisk'
alias chmod='sudo chmod'
alias chown='sudo chown'
alias hlog='tail /var/log/apache2/error_log' # show tail of httpd error log
alias hhup='sudo apachectl restart' # restart web server
alias hchk='sudo apachectl configtest' # check web config
# alias http='python -m SimpleHTTPServer' # start a web server
alias sql=sqlite3
alias sqlite=sqlite3
alias q="sqlite3 $DB" # query target database
alias vie='vi ~/.bashrc'
alias vib='vi ~/.bash_profile'
alias scb='source ~/.bash_profile'
alias hotcopy="hot-backup.py --num-backups=2 --archive-type=zip"
# Backup svn repo(s) with hotcopy
backup () {
SOURCE=~/svn
TARGET="$MY/backups/repos"
if [ -n "$*" ]; then
for repo in "$@"; do
hotcopy $SOURCE/$repo $TARGET/$repo
done
else
for repo in "code" "data" "sandbox"; do
hotcopy $SOURCE/$repo $TARGET/$repo
done
fi
}
# Mirror backups to $RSYNC
mirror () {
SOURCE="$MY/backups"
TARGET="$RSYNC:backups"
echo "Mirroring backups on $RSYNC"
rsync -arzL --delete $SOURCE/* $TARGET
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment