sant0sk1 / dotfiles

reusable configuration files

dotfiles / bashrc
100755 131 lines (105 sloc) 2.979 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Jerod Santo's Bash settings
 
### GENERAL
 
# set my prompt
function set_prompt() {
local GREEN='\[\033[0;32m\]'
local WHITE='\[\033[1;37m\]'
local NULL='\[\033k\033\\\]'
PS1="$NULL\u@\h:\w$GREEN\$(parse_git_branch)$WHITE$ "
export PS1
}
set_prompt
 
# find out what OS we're on
# OS X will have /Users
# Linux will have /home
if echo $HOME | grep -q Users; then
  os="OSX"
else
  os="LINUX"
fi
 
 
### ALIASES
 
# conditional aliases
if [ "$os" = "OSX" ]; then
alias listening='netstat -an | grep LISTEN | grep -v STREAM'
  alias ls='ls -G'
  alias flushdns='dscacheutil -flushcache'
else
alias listening='netstat -anp | grep LISTEN | grep -v STREAM'
  eval "`dircolors -b`"
  alias ls='ls --color=auto'
fi
 
if [ -f /usr/bin/htop ];then
  alias top='htop'
fi
 
# unconditional aliases
if [ -f ~/.bash_aliases ]; then
  source ~/.bash_aliases
fi
 
 
#### ENVIRONMENT VARIABLES
 
export PATH="/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:$PATH"
 
# source ruby path separately if exists. for easy Ruby version switching
if [ -f ~/.ruby_path ];then
  export ORIG_PATH=$PATH
  source ~/.ruby_path
fi
# same goes for git path
if [ -f ~/.git_path ];then
  export ORIG_PATH=$PATH
  source ~/.git_path
fi
 
if [ -f /usr/bin/mate ];then
  export EDITOR="mate -w"
  alias e='mate'
elif [ -f /usr/bin/vim ];then
  export EDITOR=vim
  alias vi='vim'
else
  export EDITOR=vi
  alias vim='vi'
fi
 
 
### FUNCTIONS
 
# removes returns for 'grep' on greps of ps output
function pps() { ps aux | grep "$@" | grep -v 'grep'; }
 
# easy access to find's size search
function find_big_files() { find "${1-.}" -size +10000k -exec du -h {} \; | sort -nr; }
 
# managing broken symlinks
function find_broken_symlinks() { find -x -L "${1-.}" -type l; }
function rm_broken_symlinks() { find -x -L "${1-.}" -type l -exec rm {} +; }
 
# add a few shortcut functions to copy/move and change directory at same time
function cpcd() { cp $1 $2 && cd $2; }
function mvcd() { mv $1 $2 && cd $2; }
 
# this function allows scp'ing a file to remote and then immediately ssh'ing to same remote
function scphh() { scp $1 $2 && ssh `echo $2 | sed ''s/:.*$//''` ; }
 
# print external IP address
function external_ip() { wget 'http://my-ip.heroku.com' -O - -o /dev/null; }
 
# count number of files in current directory recursively
function file_count() { find . -type f | wc -l; }
 
# determine current git branch
function parse_git_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "["${ref#refs/heads/}"]"
}
 
# quick access to domain availability check
function domain_available() {
  if whois $1 | grep "No match for" >&/dev/null; then
    echo "$1 is available";
    return 0;
  else
    echo "$1 is not available";
    return 1;
  fi
}
 
# cd ... instead of cd ../..
function cd () {
  if [[ $# > 0 ]]; then
    if [ ${1:0:2} == '..' ]; then
      rest=${1:2}
      rest=${rest//./../}
      builtin cd "${1:0:2}/${rest}"
    else
      builtin cd "$1"
    fi
  else
    builtin cd
  fi
}