-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
277 lines (237 loc) · 6.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
test -s ~/.alias && . ~/.alias || true
test -s ~/.alias.env && . ~/.alias.env || true
export PATH=${HOME}/local/bin/:${HOME}/opt/bin:${HOME}/bin:/usr/local/bin:/usr/local/sbin/:/bin:/sbin/:/usr/bin:/usr/sbin/:/usr/lib/mit/sbin:/opt/cross/bin:${PATH}
shopt -s cdspell
shopt -s dirspell
shopt -s checkhash
shopt -s globstar
HISTCONTROL=ignoreboth
HISTFILE=${HOME}/.bash_history
HISTFILESIZE=100000
HISTSIZE=100000
HISTTIMEFORMAT='%c '
function print_time( )
{
NUM=$1
NUMD=${#NUM}
if [[ $NUMD -gt 9 ]];
then
PRE=$((NUMD-9))
PRED=${NUM:0:${PRE}}
POST=${NUM:${PRE}:3}
SUF="s"
elif [[ $NUMD -gt 6 ]];
then
PRED=$NUM
PRE=$((NUMD-6))
PRED=${NUM:0:${PRE}}
POST=${NUM:${PRE}:3}
SUF="ms"
elif [[ $NUMD -gt 3 ]];
then
PRED=$NUM
PRE=$((NUMD-3))
PRED=${NUM:0:${PRE}}
POST=${NUM:${PRE}:3}
SUF="µs"
else
PRED=$NUM
POST="0"
SUF="ns"
fi
printf "%s.%s%s" ${PRED} ${POST} ${SUF}
}
function trim_zeroes( )
{
NUM=$1
while [[ ${NUM:0:1} == "0" ]];
do
NUM=${NUM:1}
done
echo $NUM
}
function bark_ps0( )
{
echo "BARK"
}
function get_time( )
{
date "+%s.%N"
}
function stats_start( )
{
if [[ "${PROMPT_COMMAND}" != *"${BASH_COMMAND}"* ]];
then
TIMER_START=$(get_time)
fi
}
function stats_stop( )
{
if [[ -z "$TIMER_START" ]];
then
LAST_POST_RESULT=" "
return
fi
# echo "STOP_PROMPT_COMMAND=$PROMPT_COMMAND"
# echo "BC=$BC"
# echo "STOPTIME0"
# echo "BASHPID=$BASHPID"
# echo "STATS_STOP"
# return
# date +%s.%N
# echo "STOP"
# trap 'stats_start' DEBUG
# return
TIMER_END=$(get_time)
TIMER_START_S=${TIMER_START:0:10}
TIMER_START_NS=${TIMER_START:11:9}
TIMER_END_S=${TIMER_END:0:10}
TIMER_END_NS=${TIMER_END:11:9}
# echo "TIMER_START=$TIMER_START"
# echo "TIMER_START_S=$TIMER_START_S"
# echo "TIMER_START_NS=$TIMER_START_NS"
# echo "TIMER_END=$TIMER_END"
# echo "TIMER_END_S=$TIMER_END_S"
# echo "TIMER_END_NS=$TIMER_END_NS"
TIMER_S=$(($TIMER_END_S-$TIMER_START_S))
# echo "TIMER_S=$TIMER_S"
TIMER_END_NS="${TIMER_S}${TIMER_END_NS}"
# echo "TIMER_END_NS=$TIMER_END_NS"
TIMER_START_NS=$(trim_zeroes ${TIMER_START_NS})
TIMER_END_NS=$(trim_zeroes ${TIMER_END_NS})
# echo "TIMER_START_NS=$TIMER_START_NS"
# echo "TIMER_END_NS=$TIMER_END_NS"
TIMER_NS=$(( ${TIMER_END_NS} - ${TIMER_START_NS} ))
# echo "TIMER_NS=$TIMER_NS"
C=${BrightBlack:2:10}
LAST_POST_RESULT=$(printf "${C}%10s " $(print_time $TIMER_NS))
TIMER_START=""
}
#trap 'stats_start' DEBUG
#PROMPT_COMMAND=stats_stop
GIT_PROMPT_THEME=Single_line_NoExitState_openSUSE
GIT_PROMPT_SHOW_UPSTREAM=
LAST_POST_RESULT=" "
. {ENVDIR}/git/bash-git-prompt/gitprompt.sh
export EDITOR=vim
#. ~/git/fuzzy_bash_completion/fuzzy_bash_completion
#fuzzy_replace_filedir_xspec
#fuzzy_setup_for_command cd
#fuzzy_setup_for_command ls
#fuzzy_setup_for_command l
#fuzzy_setup_for_command ll
#fuzzy_setup_for_command vim &>/dev/null
#fuzzy_setup_for_command vi &>/dev/null
#fuzzy_setup_for_command git
# Setup fzf
# ---------
if [[ ! "$PATH" == *{ENVDIR}/git/fzf/bin* ]]; then
PATH="${PATH:+${PATH}:}{ENVDIR}/git/fzf/bin"
fi
# Auto-completion
# ---------------
source "{ENVDIR}/git/fzf/shell/completion.bash"
# Key bindings
# ------------
source "{ENVDIR}/git/fzf/shell/key-bindings.bash"
export PREVIEWLINES=500
# GIT heart FZF
# -------------
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 50% "$@" --border
}
gf() {
is_in_git_repo || return
git -c color.status=always status --short |
fzf-down -m --ansi --nth 2..,.. \
--inline-info --bind page-up:preview-up,page-down:preview-down \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500' |
cut -c4- | sed 's/.* -> //'
}
#--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$PREVIEWLINES |
gb() {
is_in_git_repo || return
git branch -a --color=always | grep -v '/HEAD\s' | sort |
fzf-down --ansi --multi --tac --preview-window right:70% \
--inline-info --bind page-up:preview-up,page-down:preview-down \
--preview 'git lol $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$PREVIEWLINES |
sed 's/^..//' | cut -d' ' -f1 |
sed 's#^remotes/##'
}
gt() {
is_in_git_repo || return
git tag --sort -version:refname |
fzf-down --multi --preview-window right:70% \
--inline-info --bind page-up:preview-up,page-down:preview-down \
--preview 'git show --color=always {} | head -'$PREVIEWLINES
}
#git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
gh() {
is_in_git_repo || return
git lola |
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
--header 'Press CTRL-S to toggle sort' \
--inline-info --bind page-up:preview-up,page-down:preview-down \
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always | head -'$PREVIEWLINES |
grep -o "[a-f0-9]\{7,\}"
}
#--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1} | head -'$PREVIEWLINES |
gr() {
is_in_git_repo || return
git remote -v | awk '{print $1 "\t" $2}' | uniq |
fzf-down --tac \
--inline-info --bind page-up:preview-up,page-down:preview-down \
--preview 'git lol {1} | head -'$PREVIEWLINES |
cut -d$'\t' -f1
}
case "$-" in
*i*)
bind '"\er": redraw-current-line'
bind '"\C-g\C-f": "$(gf)\e\C-e\er"'
bind '"\C-g\C-b": "$(gb)\e\C-e\er"'
bind '"\C-g\C-t": "$(gt)\e\C-e\er"'
bind '"\C-g\C-h": "$(gh)\e\C-e\er"'
bind '"\C-g\C-r": "$(gr)\e\C-e\er"'
bind "set menu-complete-display-prefix on"
bind "set show-all-if-ambiguous on"
bind 'TAB':menu-complete
esac
FZF_DEFAULT_OPTS="--inline-info --bind page-up:preview-up,page-down:preview-down --height=60% --preview 'fzf_preview ${PREVIEWLINES} "{}"'"
export GCC_COLORS="error=01;31:warning=01;35:note=01;36:range1=32:range2=94:locus=01:quote=01:fixit-insert=32:fixit-delete=31:diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32"
cdr() {
root=$(git rev-parse --show-toplevel)
cd "${root}"
}
function venv()
{
TENV=$1
if [[ -z "${TENV}" ]];
then
# just list
echo "Installed virtual environments:"
for e in ~/.venv/*;
do
if [[ -d "${e}" ]];
then
VNAME=$(basename ${e})
VER=$(${e}/bin/python3 --version)
echo -e "${VNAME}\t${VER}"
fi
done
else
ACTIVATE=~/".venv/${TENV}/bin/activate"
if [[ ! -f "${ACTIVATE}" ]];
then
echo "Unknown venv ${TENV}, creating with current python3"
python3 -m venv ~/".venv/${TENV}"
source "${ACTIVATE}"
else
source "${ACTIVATE}"
echo "Activated environment ${TENV}"
fi
fi
}
# vim: tabstop=4 shiftwidth=4 noexpandtab