forked from dcosson/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_includes
89 lines (79 loc) · 2.61 KB
/
bash_includes
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
###
### General bash configuration, to include in osx or linux servers
###
export EDITOR=vim
HISTFILESIZE=100000
HISTSIZE=10000
export HISTCONTROL=ignoredups
export HISTCONTROL=ignoreboth # ignore same sucessive entries
shopt -s histappend
PROMPT_COMMAND='history -a'
# up arrow bash history
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
###
### Prompt
###
# Show current git project info
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "*"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
current_virtualenv() {
echo `basename $VIRTUAL_ENV 2>/dev/null`
}
function __prompt_command() {
local LAST_EXIT_CODE="$?"
### Define Colors
txtblack='\[\033[0;30m\]'
txtred='\[\033[0;31m\]'
txtgreen='\[\033[0;32m\]'
txtorange='\[\033[0;33m\]'
txtblue='\[\033[0;34m\]'
txtpurple='\[\033[0;35m\]'
txtwhite='\[\033[0;37m\]'
txtend='\[\033[0m\]'
### Define PS1
# extra vertical space
PS1="\n"
# username @ hostname, then indicate previous exit code
PS1+="${txtgreen}\u$DIM${txtend} ${txtwhite}@${txtend} ${txtorange}\h${txtend}"
# python virtualenv, if we're in one
if [ -n "$(current_virtualenv)" ]
then
PS1+=" ${txtblue}($(current_virtualenv))${txtend}"
fi
# sun or rain based on last exit code
if [ $LAST_EXIT_CODE = 0 ]
then
PS1+=" ${txtgreen}☀${txtend}"
else
PS1+=" ${txtblue}☁${txtend}"
fi
PS1+="\n"
# pwd, git branch and prompt
PS1+="${txtpurple}\$PWD${txtend} ${txtwhite}\$(parse_git_branch)$ "
PS1+='\[$(~/.iterm2/it2setkeylabel set status \
"$(parse_git_branch)")\]'
}
export PROMPT_COMMAND=__prompt_command
###
### useful aliases
###
alias lsl='ls -G -lh --color=auto'
lsp() { ls -lh $1 | egrep -v '.*.pyc$'; }
alias grep='grep -i --color=auto'
alias gg='git grep -n --color --heading --break'
alias .b='source ~/.bashrc && source ~/.bash_profile'
# tmux 256 colors hack
alias tmux="TERM=screen-256color-bce tmux"
# rename the current tab in terminal/iterm2
rn() { export PROMPT_COMMAND="echo -ne \"\033]0;$1\007\""; }
# Get a rough outline of a python file - show class & function declarations, block comments, first line of docstrings
pyoutline() { egrep --color=auto '^[\t ]*class|^[\t ]*def|^[\t ]*###.+$|^[\t ]*""".+$' $1; } # apparently \s doesn't work so I use tab or space
wcr() { wc -l `find . -type f | egrep "$1$"`; } # recursive word count, pass in the file extension
alias ip='curl icanhazip.com'
# create an empty new bash script
bashscript() { touch $1; chmod a+x $1; echo -e "#!/bin/bash\n\n" > $1; vim $1; }