-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
161 lines (137 loc) · 4.21 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
export PATH=~/bin:$PATH
for f in ~/.bashrc-local \
/etc/bash_completion.d/git-prompt \
/usr/local/etc/bash_completion.d/git-completion.bash \
/usr/local/etc/bash_completion.d/git-prompt.sh
do
test -f $f && source $f
done
function __git_prompt() {
if [ -n "$(git rev-parse --git-dir 2>/dev/null)" ]; then
local gs_wd=$(git diff --no-ext-diff --quiet --exit-code; echo $?);
local gs_i=$(git diff-index --cached --quiet HEAD --; echo $?);
if [ $gs_wd = 0 ]; then
if [ $gs_i = 0 ]; then
local gs_untracked=$(! git ls-files --others --exclude-standard --error-unmatch -- '*' > /dev/null 2> /dev/null; echo $?);
if [ $gs_untracked = 0 ]; then
local color="\033[01;31m"; #red
else
local color="\033[35m";
fi;
else
local color="\033[01;33m"; # yellow
fi;
else
if [ $gs_i = 0 ]; then
local color="\033[01;32m"; # green
else
if [ "$(uname -s)" = "Darwin" ]; then
local color="\033[33;41m";
else
local color="\033[33;45m";
fi;
fi;
fi;
color="$2${color}$3";
__git_ps1 " "$color"%s";
return;
fi
}
if [ "$PS1" = '${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' ] || \
[ "$PS1" = '\h:\W \u\$ ' ] || \
[ "$PS1" = '\s-\v\$ ' ] || \
[ "$PS1" = '' ]; then
COLOR_RED="\033[01;31m"
COLOR_GREEN="\033[01;32m"
COLOR_YELLOW="\033[01;33m"
COLOR_BLUE="\033[01;34m"
COLOR_NONE="\033[00m"
PS1='${debian_chroot:+($debian_chroot)}'
PS1=$PS1"\[${COLOR_GREEN}\]\\u@\\h"
PS1=$PS1"\[${COLOR_NONE}\]:"
PS1=$PS1"\[${COLOR_BLUE}\]\\w"
PS1=$PS1"\$(__git_prompt ' "\[${COLOR_RED}\]"%s' \[ \])"
PS1=$PS1"\[${COLOR_NONE}\]\\$ "
fi
#PS1="\[\$(tput cup \"\$(tput lines)\")\]$PS1"
export CLICOLOR=1
export EDITOR=nvim
function setTitle() {
case "$TERM" in
screen*)
# Screen window title
printf '\ek%s\e\\' "$1"
# Terminal window title
printf '\e]0;%s\007' "$2"
;;
xterm*)
# Terminal window title
printf '\e]0;%s\007' "$1"
;;
esac
}
# http://stackoverflow.com/a/5687619
function shortPath() {
echo -n "${PWD/#$HOME/\~}" | awk -F / '{
if (length($0) > 14) { if (NF>4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF;
else if (NF>3) print $1 "/" $2 "/.../" $NF;
else print $1 "/.../" $NF; }
else print $0; }'
}
function promptCommand() {
local PRIMARY
if [ -n "$(git rev-parse --show-toplevel 2>/dev/null)" ]; then
PRIMARY=$(basename $(git rev-parse --show-toplevel))
else
PRIMARY=$(shortPath)
fi
local SECONDARY="$USER@$HOSTNAME - $PRIMARY"
if [ "$USER" = root ]; then
PRIMARY='[!] '"$PRIMARY"
SECONDARY='[!] '"$SECONDARY"
fi
setTitle "$PRIMARY" "$SECONDARY"
}
export PROMPT_COMMAND='promptCommand'
# Set the screen title to the hostname once on login
case "$TERM" in
screen | screen-256color)
echo -ne "\033k${HOSTNAME}\033\\"
;;
esac
which nvim &> /dev/null || {
alias vim='nvim -v'
alias vi='nvim -v'
}
# Merica
LANG=en_US.UTF-8
# Erase duplicate commands in history
export HISTCONTROL="erasedups:ignoreboth"
# Ignore commands prefixed by space
export HISTCONTROL="${HISTCONTROL}:ignorespace"
# Make the history file much bigger
export HISTFILESIZE=500000
export HISTSIZE=100000
# No need to remember the exit command
export HISTIGNORE="&:[ ]*:exit"
# Prevent bash overwriting history on exit
shopt -s histappend
# Save multi-line commands to the history as one command
shopt -s cmdhist
# Reduce the chance that multiple bash sessions will conflict when writing history by writing it
# after each command.
_bash_history_sync() {
builtin history -a
HISTFILESIZE=$HISTSIZE
builtin history -c
builtin history -r
}
history() {
_bash_history_sync
builtin history "$@"
}
PROMPT_COMMAND="_bash_history_sync;$PROMPT_COMMAND"
# Unmap software flow control pause (Ctrl-S) and resume (Ctrl-Q)
stty stop ''
stty start ''