-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.shrc
351 lines (321 loc) · 9.73 KB
/
.shrc
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# ------ get host info -------------{{{
# Get hostname and OS
HNAME=`hostname -s`
UNAME=`uname`
#}}}
# ------ export variables ----------{{{
# Vim
export EDITOR=vim
# Git
export GIT_EDITOR=$EDITOR
export GIT_AUTHOR_NAME='Claude Becker'
export GIT_AUTHOR_EMAIL='becker@phys.ethz.ch'
export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL
# MacPorts
#export PATH=/opt/local/bin:/opt/local/sbin:$PATH
#export MANPATH=/opt/local/share/man:$MANPATH
# Scripts
export PATH=~/Scripts:/opt/homebrew/bin:$PATH
# gnu screen sockets directory
export SCREENDIR=$HOME/.sessions
# path for cd commands
#export CDPATH=.:$HOME
# locale setting
export LANG=en_US.UTF-8
#export LC_ALL=en_US.UTF-8
# grep options
export GREP_COLORS='ms=01;31:mc=01;31:sl=:cx=:fn=33:ln=32:bn=32:se=36'
# ISG bin path on Linux
if [[ "$UNAME" == "Linux" ]]; then
export PATH=/home/isg/bin:$PATH
fi
# Pipenv
export PIPENV_VENV_IN_PROJECT=1
# Bat
# curl -o ~/.config/bat/themes/tokyonight_night.tmTheme https://raw.githubusercontent.com/folke/tokyonight.nvim/refs/heads/main/extras/sublime/tokyonight_night.tmTheme
export BAT_THEME='tokyonight_night'
# Lazygit
export LG_CONFIG_FILE="$HOME/.dotfiles/lazygit.yml"
# less options
export LESS='--ignore-case --jump-target=.5'
#}}}
# ------ alias commands ------------{{{
alias grep='grep --color=auto'
alias ll='ls -hlF'
alias rebash='source ~/.bash_profile'
alias gvimtab='gvim --remote-tab-silent'
alias myrsync='rsync -rLptgoDvzuhX --rsync-path=/opt/local/bin/rsync --exclude ".DS_Store" --exclude ".*.swp" --delete'
alias rbenv_init='export PATH="$HOME/.rbenv/bin:$PATH";eval "$(rbenv init -)";export PATH="./bin:$PATH";unalias rbenv_init'
alias exa='exa -l --git --color-scale --group'
alias rg='rg -S --colors "line:fg:yellow" --colors "path:fg:green"'
alias ncdu='ncdu --color dark'
alias ccat='bat -pp'
alias tree='tree -F -I ".git|.venv" --hyperlink'
# use colordiff if it exists
if [ $(which colordiff) ]; then
alias diff='colordiff'
fi
# use gnu sort if it exists
if [ $(which gsort) ]; then
alias sort='gsort'
fi
#}}}
# ------ history hacks -------------{{{
# Use common history file for bash and zsh
export HISTFILE=$HOME/.bash_history
# Let history ignore certain commands
# - ignoreboth = ignorespace:ignoredups
# - ignorespace = ignore cmds starting with space
# - ignoredups = ignore sequential duplicate cmds
export HISTCONTROL=ignoreboth
# Number of commands to keep in history
export HISTFILESIZE=10000
export SAVEHIST=$HISTFILESIZE
# Number of commands to keep in history of current session
export HISTSIZE=10000
# Rem: history is read/written when logging in/out. To read manually:"history -n", to write "history -a". With the following, this is done for each command entered.
#export PROMPT_COMMAND="history -n; history -a"
#}}}
# ------ colorful ls ---------------{{{
# Colors using dir_colors for gls (macports:coreutils)
# add --hide=*~ to hide files ending in ~ (overriden by -a or -A)
# alternatively use -B which always hides *~ files
if [[ "$UNAME" == "Darwin" ]]; then
# use gnu ls if it exists
if [ $(which gls) ]; then
eval `gdircolors ~/.dir_colors`
alias ls='gls --color'
else
# else use lscolors (cf man ls)
export CLICOLOR=true
export LSCOLORS=gxdxcxcxbxegedbxbxdxdx
fi
fi
if [[ "$UNAME" == "Linux" ]]; then
eval `dircolors -b ~/.dir_colors`
alias ls='ls --color'
fi
#}}}
# ------ colorful manpages ---------{{{
# Attribute: # 00=none 01=bold 04=underline 05=blink 07=reverse 08=concealed
# Text: # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background: # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
export LESS_TERMCAP_mb=$'\E[01;31m' # blinking begin
export LESS_TERMCAP_md=$'\E[01;33m' # bold begin
export LESS_TERMCAP_me=$'\E[0m' # blinking end
export LESS_TERMCAP_se=$'\E[0m' # standout end
export LESS_TERMCAP_so=$'\E[01;44;33m' # standout begin
export LESS_TERMCAP_ue=$'\E[0m' # underline end
export LESS_TERMCAP_us=$'\E[04;32m' # underline begin
#}}}
# ------ custom functions ----------{{{
# ccat: colorized cat using pygments {{{
#ccat()
#{
# for iarg in $@
# do
# ext=${iarg##*.}
# # force md lexer on .markdown files
# if [ $ext == 'markdown' ]; then
# pygmentize -O "style=native" -f console256 -l md $iarg
# else
# pygmentize -O "style=native" -f console256 -g $iarg
# fi
# done
#}
#}}}
# pyclean: delete __pycache__ and *.pyc files {{{
pyclean()
{
find . \( -name '__pycache__' -o -name '*.pyc' \) -not -path './.venv/*' -delete
}
#}}}
# mitogen: set env variables to enable mitogen in ansible {{{
#mitogen()
#{
#export ANSIBLE_STRATEGY_PLUGINS=/usr/local/lib/python3.9/site-packages/ansible_mitogen/plugins/strategy
#export ANSIBLE_STRATEGY=mitogen_linear
#}
#}}}
# gvimscp: open remote files using bash tab completion {{{
gvimscp()
{
if [[ -z $1 ]]; then
echo "usage: gvimscp [[user@]host1:]file1 ... [[user@]host2:]file2"
return
fi
declare -a targs=()
for iarg in $@
do
# adapt syntax for vim
targ="scp://$(echo $iarg | sed -e 's@:/@//@' | sed -e 's@:@/@')"
targs=("${targs[@]}" $targ)
done
gvim ${targs[@]}
}
#}}}
# manv, mangv, mans: manpages hacks {{{
# Open manpage in vim/gvim
manv()
{
man $* | col -bx | vim -c ":set ft=man" -R -;
}
mangv()
{
man $* | col -bx | gvim -c ":set ft=man" -R -;
}
# Open perldoc in gvim
perldocgv()
{
perldoc $* | col -bx | gvim -c ":set ft=man" -R -;
}
# Convert man to ps and open in Skim
mans()
{
man -t "${1}"| open -f -a Skim
}
# Open all man pages in vim
#export MANPAGER='col -bx | vim -c ":set ft=man" -R -'
#}}}
# tcol: set iTerm terminal color {{{
set_term_color()
{
local HEX_FG=$1
local HEX_BG=$2
local TRANSPARENCY=$3
local FG_R=`echo $HEX_FG | sed 's/../0x&,/g' | /usr/bin/awk -F "," '{printf("%d",$1 * 257)}'`
local FG_G=`echo $HEX_FG | sed 's/../0x&,/g' | /usr/bin/awk -F "," '{printf("%d",$2 * 257)}'`
local FG_B=`echo $HEX_FG | sed 's/../0x&,/g' | /usr/bin/awk -F "," '{printf("%d",$3 * 257)}'`
local BG_R=`echo $HEX_BG | sed 's/../0x&,/g' | /usr/bin/awk -F "," '{printf("%d",$1 * 257)}'`
local BG_G=`echo $HEX_BG | sed 's/../0x&,/g' | /usr/bin/awk -F "," '{printf("%d",$2 * 257)}'`
local BG_B=`echo $HEX_BG | sed 's/../0x&,/g' | /usr/bin/awk -F "," '{printf("%d",$3 * 257)}'`
/usr/bin/osascript <<EOF
tell application "iTerm"
tell current session of first window
set foreground color to {$FG_R, $FG_G, $FG_B}
set background color to {$BG_R, $BG_G, $BG_B}
set transparency to "$TRANSPARENCY"
end tell
end tell
EOF
}
tcol()
{
case $1 in
R | r) set_term_color ffffff 1d0202 0.11 ;;
G | g) set_term_color ffffff 001303 0.11 ;;
B | b) set_term_color ffffff 0a0f24 0.11 ;;
K | k) set_term_color ffffff 000000 0.11 ;;
*) set_term_color ffffff 000000 0.11
esac
}
#}}}
# extract: unpack various types of archives {{{
extract()
{
if [ -f $1 ] ; then
case $1 in
*.zip) unzip $1 ;;
*.rar) unrar e $1 ;;
*.tar) tar xf $1 ;;
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.gz) gunzip $1 ;;
*.Z) uncompress $1 ;;
*) echo "Unrecognized archive type"
esac
else
echo "'$1' is not a valid file"
fi
}
#}}}
# cd: hack cd to allow more dots {{{
cd () {
if [[ "x$*" == "x..." ]]; then
cd ../..
elif [[ "x$*" == "x...." ]]; then
cd ../../..
elif [[ "x$*" == "x....." ]]; then
cd ../../..
elif [[ "x$*" == "x......" ]]; then
cd ../../../..
else
builtin cd "$@"
fi
}
#}}}
# cdf: change to folder opened in the frontmost Finder window {{{
cdf ()
{
currFolderPath=$(osascript <<" EOT"
tell application "Finder"
try
set currFolder to (folder of the front window as alias)
on error
set currFolder to (path to desktop folder as alias)
end try
POSIX path of currFolder
end tell
EOT
)
echo "--> $currFolderPath"
cd "$currFolderPath"
}
#}}}
# tab: open new tab in current path {{{
# source: oh-my-zsh plugin osx
tab()
{
local command="cd \\\"$PWD\\\""
(( $# > 0 )) && command="${command}; $*"
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[ "$the_app" == 'Terminal' ]] && {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
tell application "Terminal" to do script "${command}" in front window
end tell
EOF
}
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
launch session "Default Session"
set current_session to current session
tell current_session
write text "${command}"
end tell
end tell
end tell
EOF
}
}
#}}}
# settitle: set terminal title {{{
settitle()
{
if [[ $# -ne 0 ]]; then
echo -ne "\033]0;${*}\007"
else
echo -ne "\033]0;${USER}@`hostname -s`\007"
fi
}
# Set tab title to hostname (without domain) + command running (not compatible with NEW_PWD)
#export PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME%%.*}:\007"'
#}}}
#}}}
# ------ Vim Modeline --------------{{{
# vim: set foldmethod=marker ft=sh:
#}}}