-
Notifications
You must be signed in to change notification settings - Fork 0
/
myrc
253 lines (217 loc) · 6.85 KB
/
myrc
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
#!/bin/bash
#personal bashrc configuration
###DEFAULT BEHAVIOR {{{1
#ignore commands which less than two character and others trivial
HISTIGNORE="?:??:l[als]:to *:pwd:clear:exit:&"
#ignoreboth(^space and consecutive duplicates), remove duplicates
HISTCONTROL=ignoreboth:erasedups
#save and reload the history after each command finishes
#this could change index of commands in .bash_history
if [ -z "${PROMPT_COMMAND}" ]; then
PROMPT_COMMAND="history -a; history -c; history -r;"
else
PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
fi
#enable star globbing
[ $BASH_VERSINFO -ge 4 ] && shopt -s globstar
#use default language (en) as output
export LC_MESSAGES=C
#disable legacy feature of terminal emulator Software Flow Control
#prevent accidentally pressing c-s/c-q
#check interactive shell before enable foreward-search
[[ $- == *i* ]] && stty -ixon
#colors for file and folder in terminal
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
# default editor
export EDITOR=vim
#less option
export LESS="-RMj.5"
# using zeal for docsets if dasht exists
if type "dasht" &> /dev/null; then
export DASHT_DOCSETS_DIR="$HOME/.local/share/Zeal/Zeal/docsets"
fi
#using ccache instead of gcc
[[ $PATH != *"/usr/lib/ccache"* ]] && [[ -d /usr/lib/ccache ]] && export PATH=/usr/lib/ccache/:${PATH}
# add local bin
[[ $PATH != *"$HOME/.local/bin"* ]] && [[ -d $HOME/.local/bin ]] && export PATH=${PATH}:$HOME/.local/bin
#}}}1
###ALIASES {{{1
# up dir
alias 2.='cd ../../'
alias 3.='cd ../../../'
alias 4.='cd ../../../..'
# custom ls
alias l='ls -aCF'
alias la='ls -laAh' #long list all
alias ll='ls -lFh' #long list without .
alias lo='ls -lFhtr' #List by modified time in reverse order
# vim abbreviations
#original
alias v='vim'
alias g='gvim --remote-silent'
#run with fzf
alias vi='vim $(fzf)'
alias gv='gvim --remote-silent $(fzf)'
#todo: gerneral cd to switch between source and build
#echo ${PWD%build*} delete all from left of match
#echo ${PWD#*build} delete all from right of match
alias ..='test -d ${PWD%build*}${PWD#*build} && cd ${PWD%build*}${PWD#*build}'
#silver search
if type ag &> /dev/null; then
alias ag="ag --noheading --nobreak -S -p $HOME/.ignore \
--color-match '01;31' \
--color-path '36' \
--color-line-number '32'"
fi
#ripper grep
if type rg &> /dev/null; then
alias rg="rg --no-heading -S --colors 'path:fg:cyan'"
fi
#gnu grep
GREP_OPTIONS="-I --color=auto --exclude-dir={.cvs,.git,.svn,.vscode,build} --exclude=*{.jpg,.png,.tags}"
alias grep="grep $GREP_OPTIONS"
alias fgrep="fgrep $GREP_OPTIONS"
alias egrep="egrep $GREP_OPTIONS"
unset GREP_OPTIONS
#ctags
#see $HOME/.ctags for default parameter configuration
if type ctags &> /dev/null; then
alias tags='ctags -R -f ./.tags .'
fi
#tree
if type tree &> /dev/null; then
alias tree="tree -CAFa -I 'CVS|.git|.svn|.vscode' --dirsfirst"
fi
#start tmux with colourful xterm and force it assuming term supported 256colour
if type tmux &> /dev/null; then
alias tmux='TERM=xterm-256color tmux -2'
fi
#mc colorscheme located unter ~/.local/share/mc/skins
#themes: asterisk, blue, bluemoon, dark, darkened, gotar, nicedark, solarized,...
case "$KONSOLE_PROFILE_NAME" in
DarkPastels) mc_color=gotar;;
Solarized) mc_color=solarized;;
*) mc_color=default;;
esac
if type mc &> /dev/null; then
alias mc='mc -S $mc_color'
fi
#}}}1
###FUNCTIONS {{{1
#remove duplicated entries in PATH
dedupPATH() {
#{{{2
if [ -n "$PATH" ]; then
old_PATH=$PATH:; PATH=
while [ -n "$old_PATH" ]; do
x=${old_PATH%%:*} # the first remaining entry
case $PATH: in
*:"$x":*) ;; # already there
*) PATH=$PATH:$x;; # not there yet
esac
old_PATH=${old_PATH#*:}
done
PATH=${PATH#:}; unset old_PATH x
fi
}
#}}}2
git-ctags() {
#{{{2
#read project root dir from git
local dir=$(git rev-parse --show-toplevel)
#return if not found (in .git or outside cvs)
[ -z $dir ] && return
#execute 'git init' if hooks was not copied (from local template)
#note: directory changing and init are done in subshell (...)
[ -f "${dir}/.git/hooks/ctags" ] || ( cd $dir && git init )
#call ctags
eval "${dir}/.git/hooks/ctags"
}
#}}}2
mc-color() {
#{{{2
if [ ! "$#" -eq 1 ]
then
echo "Usage:mc-color param"
echo "param: gotar, nicedark, blue, bluemoon, dark, modarin256, solarized, asterisk"
else
mc_color="$1"
mc
fi
}
#}}}2
#change cwd to last visited one after exiting
ranger() {
#{{{2
local tmp dir
tmp="$(mktemp -t "ranger_cd.XXXXXXXXXX")"
command ranger --choosedir="$tmp" -- "${@:-$PWD}"
if dir="$(cat -- "$tmp")" && [ -n "$dir" ] && [ "$dir" != "$PWD" ]; then
cd -- "$dir" || exit
fi
command rm -f -- "$tmp"
}
#}}}2
#switch term colorscheme
term-color() {
#{{{2
if [ ! "$#" -eq 1 ]
then
echo "Usage: term-color param"
echo "param: Linux, BlackOnWhite, WhiteOnBlack, BlueOnBlack, GreenOnBlack, DarkPastels, Solarized, SolarizedLight..."
else
# fix problem with konsoleprofile in tmux
if [[ -z "$TMUX" ]]
then
konsoleprofile "colors=$1"
else
printf '\033Ptmux;\033\033]50;%s\007\033\\' "colors=$1"
fi
export KONSOLE_PROFILE_NAME=$1
fi
}
#}}}2
#}}}1
###COMPLETION {{{1
##node & npm (load: 0.21s)
#if type node &>/dev/null && type npm &>/dev/null; then
# [[ $PATH != *"npm-global"* ]] && [[ -d ~/.npm-global ]] && export PATH=${PATH}:${HOME}/.npm-global
# eval "$(npm completion)"
#fi
#
## correct previous console command with $fuck (load: 0.13s)
#if type "thefuck" &> /dev/null; then
# eval "$(thefuck --alias)"
#fi
#
## correct previous console command with $fuck (load: 0.12s)
#if type "tmuxp" &> /dev/null; then
# eval "$(_TMUXP_COMPLETE=source tmuxp)"
#fi
#
##tldr (load: 0.07s)
#if command -v tldr &> /dev/null; then
# complete -W "$(tldr 2>/dev/null --list)" tldr
#fi
#}}}1
###SOURCING {{{1
# load fuzzy finder
[ -f $HOME/.fzf.bash ] && source $HOME/.fzf.bash
# load it's command snippets
[ -f $HOME/.fzf_cmd ] && source $HOME/.fzf_cmd
if [ -d "$HOME/.bash-git-prompt" ]; then
GIT_PROMPT_THEME=Ubuntu_Simple
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_IGNORE_SUBMODULES=1
GIT_PROMPT_TIMEOUT=0.5
source ~/.bash-git-prompt/gitprompt.sh
fi
#enable some extra features
[ -f ~/.autojump/etc/profile.d/autojump.sh ] && source ~/.autojump/etc/profile.d/autojump.sh
[ -f ~/.apparix.bash ] && source ~/.apparix.bash #bookmark directories
[ -f ~/.git-completion.bash ] && source ~/.git-completion.bash #git specific completion
[ -f ~/.tmux-completion.bash ] && source ~/.tmux-completion.bash #tmux specific completion
#}}}1
# vim:foldmethod=marker:foldlevel=1