-
Notifications
You must be signed in to change notification settings - Fork 11
/
.bashrc
114 lines (91 loc) · 3.69 KB
/
.bashrc
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
# source code from https://github.com/appleboy/config
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="UTF-8"
export LANG="en_US.UTF-8"
# save bash history
# https://superuser.com/questions/950403/bash-history-not-preserved-between-terminal-sessions-on-mac/985099
export SHELL_SESSION_HISTORY=0
# set for mac
export CLICOLOR=1
# common variable
export BLOCKSIZE="k"
export EDITOR="vim"
export GIT_PAGER="less"
export LESS="-EfmrSwX"
export LSCOLORS="dxfxcxdxbxegedabagacad"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH"
# Add a timestamp to your bash history
export HISTTIMEFORMAT="%d/%m/%y %T "
# ref: http://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
# https://apple.stackexchange.com/questions/218731/why-bash-history-on-my-mac-wont-save
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# https://www.jianshu.com/p/26d365078081
export BASH_SILENCE_DEPRECATION_WARNING=1
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
# Add Autocompletion
[ -f "/etc/bash_completion" ] && source "/etc/bash_completion"
[ -f "/usr/local/etc/bash_completion" ] && source "/usr/local/etc/bash_completion"
[ -f "${HOME}/.git-completion.bash" ] && source "${HOME}/.git-completion.bash"
[ -f "/usr/local/share/git-core/contrib/completion/git-completion.bash" ] && source "/usr/local/share/git-core/contrib/completion/git-completion.bash"
[ -f "/opt/homebrew/etc/profile.d/bash_completion.sh" ] && source "/opt/homebrew/etc/profile.d/bash_completion.sh"
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "("${ref#refs/heads/}") ";
}
function git_since_last_commit {
now=`date +%s`;
last_commit=$(git log --pretty=format:%at -1 2> /dev/null) || return;
seconds_since_last_commit=$((now-last_commit));
minutes_since_last_commit=$((seconds_since_last_commit/60));
hours_since_last_commit=$((minutes_since_last_commit/60));
minutes_since_last_commit=$((minutes_since_last_commit%60));
echo "${hours_since_last_commit}h${minutes_since_last_commit}m ";
}
function git_diff() {
git diff --no-ext-diff -w "$@" | vim -R -
}
if [ "`uname -s`" == "Linux" ]; then
alias ls="/bin/ls -aF --color=always"
alias tmux="TERM=screen-256color /usr/bin/tmux"
else
alias ls="/bin/ls -aF"
fi
# support https://github.com/creationix/nvm
if [ -f "${HOME}/.nvm/nvm.sh" ]; then
export NVM_DIR=$HOME/.nvm
source ${HOME}/.nvm/nvm.sh > /dev/null 2>&1
nvm use stable > /dev/null 2>&1
fi
# support https://github.com/phpbrew/phpbrew
[ -f "${HOME}/.phpbrew/bashrc" ] && source ${HOME}/.phpbrew/bashrc
# init z! (https://github.com/rupa/z)
[ -f "${HOME}/z.sh" ] && source ${HOME}/z.sh
# support git semantic commits command.
if [ -d "${HOME}/.git-semantic-commits" ]; then
export PATH=$PATH:${HOME}/.git-semantic-commits
fi
# support composer command
if [ -d "${HOME}/.composer/vendor/bin" ]; then
export PATH=$PATH:${HOME}/.composer/vendor/bin
fi
# add bin folder to $PATH.
if [ -d "${HOME}/bin" ]; then
export PATH=$PATH:${HOME}/bin
fi
# Add RVM to PATH for scripting
if [ -d "$HOME/.rvm/bin" ]; then
export PATH="$PATH:$HOME/.rvm/bin"
fi
# Load the shell dotfiles, and then some:
# * ~/.path can be used to extend `$PATH`.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do
[ -r "$file" ] && [ -f "$file" ] && source "$file" > /dev/null 2>&1;
done;
unset file;
# end .bashrc file