-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
204 lines (176 loc) · 6.99 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
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# if [ -f "$HOME/.profile" ]; then
# . "$HOME/.profile"
# fi
#--------------------------------------------------
# prompt
#---------------------------------------------------
__ps1() {
ExitCode=$(Ex=$?; [[ $Ex -ne 0 ]] && echo "[$Ex]")
Branch=$(git branch --show-current 2>/dev/null)
Root=$(git rev-parse --show-toplevel 2>/dev/null)
Root=${Root##*/}
# every sequence of color code (e.g `\e[31m`) must be wraped inside `\[ \]`
# so to be treaded as non-printing character. Otherwise the positoning of
# the cursor becomes faulty. In Readline's config file, `.inputrc`, this
# method doesn't work and we use `\1 \2` instead according to its manual.
errP='\[\e[1;31m\]$ExitCode\[\e[m\]'
[[ -n $Branch ]] && branchP='\[\e[0;31m\] $Branch\[\e[m\]' || branchP=""
[[ -n $Root ]] && rootP='\[\e[0;35m\]($Root)\[\e[m\]' || rootP=""
userP='\[\e[0;33m\]\u\[\e[m\]'
hostP='\[\e[0;29m\]\h\[\e[m\]'
suffixP='\[\e[1;32m\]$\[\e[m\]'
dircP='\[\e[0;32m\]\w\[\e[m\]'
# ╭─────╮
# │ box │
# ╰─────╯
PS1="$userP@$hostP $dircP$branchP $errP\n$suffixP "
}
PROMPT_COMMAND="__ps1"
#---------------------------------------------------
# exports
#---------------------------------------------------
# export TERM=xterm-256color
#---------------------------------------------------
# options
#---------------------------------------------------
set -o vi
shopt -s autocd
# expands '**' to recursive subdirectories
shopt -s globstar
# ignoreboth is shorthand for ignorespace and ignoredups
export HISTCONTROL=ignoredups:erasedups
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
# If set, the history list is appended to the file named by the value of the
# HISTFILE variable when the shell exits, rather than overwriting the file. (in
# order to prevent the issue of lossig bash session history when multiple
# instances are running)
shopt -s histappend
export HISTSIZE=-1
# Stupid!!!!
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [ "$DISPLAY" ]; then
activ_win_id=$(xprop -root _NET_ACTIVE_WINDOW)
activ_win_id=$(echo "$activ_win_id" | awk '{ activ_win_id=substr($0,41,9); print activ_win_id; }' )
[ "$activ_win_id" != "0x0" ] &&
xprop -id "$activ_win_id" -remove WM_NORMAL_HINTS
fi
fi
#---------------------------------------------------
# aliases
#---------------------------------------------------
#if [[ "$OSTYPE" == "msys" ]]; then
#fi
alias ls='ls --color=auto --classify'
alias la="ls -alh"
alias grep="grep --color=auto"
alias e="$EDITOR"
alias e.="$EDITOR ."
alias vi="$EDITOR"
alias dot="$HOME/dot"
alias note="$HOME/note"
alias enw="$EDITOR $HOME/note/en/words.md"
alias t="tmux a || tmux"
alias o="octave"
alias r="ranger"
alias gits="git status"
alias gitd="git diff"
alias gitds="git diff --staged"
alias gita="git add"
alias gitc="git commit"
alias gitb="git branch"
# alias gitll="git log --graph --format=format:'%C(yellow)%h%C(reset) - %C(green)%ar%C(reset) %C(blue)%an%C(reset)%C(bold red)%d%C(reset) - %s'"
alias gitll="git log --pretty=format:'%C(red)%h%C(reset) -%C(yellow)%d%C(reset) %s %C(bold blue) <%an>' --decorate --numstat --abbrev-commit"
# alias gitl="git log --graph --oneline"
alias gitl="git log --color --graph --pretty=format:'%C(auto)%h%d %s %C(black)%C(bold)%an, %ar' --abbrev-commit --decorate"
alias giti="git describe --abbrev=4 --dirty --always --tags"
#Pacman Shortcuts
alias pac-rm-cache="sudo pacman -Scc"
alias pac-rm-orphan="pacman -Qtdq | sudo pacman -Rns -"
alias pac-unlock="sudo rm /var/lib/pacman/db.lck"
alias pac-size="pacman -Qq | pacman -Qi - | egrep '(Size|Name[^s])' | sed -E 's/ ([KM])iB/\1/' | sed -z 's/\nInstalled/ /g' | perl -pe 's/(Name|Size) *: //g' | column -t | sort -hk2 -r | cat -n | tac"
alias pac-view="pacman -Slq | fzf --preview 'pacman -Si {}' --layout=reverse"
alias pac-file-of="pacman -Qo"
alias pac-check-integ="pacman -Qikk"
alias bf="WINEPREFIX=~/Games/skylords-reborn/ wine /home/s4/Games/skylords-reborn/drive_c/Program\ Files/BattleForge/BattleForge.exe"
alias yt-dlp-video='yt-dlp --cookies-from-browser firefox --proxy socks5://192.168.1.100:9909 -S "height:1080,aext"'
alias yt-dlp-audio='yt-dlp --cookies-from-browser firefox --proxy socks5://192.168.1.100:9909 -f "ba"'
alias ffmpeg-combine='ffmpeg -i "" -i "" out.mp4'
#---------------------------------------------------
# env
#---------------------------------------------------
# Arch
[[ -f "/usr/share/fzf/key-bindings.bash" ]] && . "/usr/share/fzf/key-bindings.bash"
# Debian
[[ -f "/usr/share/doc/fzf/examples/key-bindings.bash" ]] && . "/usr/share/doc/fzf/examples/key-bindings.bash"
# Manual
[[ -f "$HOME/.local/share/key-bindings.bash" ]] && . "$HOME/.local/share/key-bindings.bash"
#---------------------------------------------------
# completions
#---------------------------------------------------
complete -C vic vic
[[ -x $(command -v pomo) ]] && complete -C pomo pomo
# -----------------------------------------------
# --- functions ---
# -----------------------------------------------
# READLINE variable are only populated if the function is called by `bind -x`. The
# advantage of using READLINE stuff over normal functions is command history population
# and easy input usage.
vi-find() {
selection=$(find "${1:-.}" -name "*${READLINE_LINE:-*}*" \
-not -path "*/${2:-.}*/*" -type f 2>/dev/null |
fzf --preview 'highlight -O ansi -l {}')
if [[ -n $selection ]]; then
READLINE_LINE="$EDITOR $selection${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( ${#EDITOR} + 1 + ${#selection} ))
builtin bind '"\e@": accept-line'
else
builtin bind '"\e@": abort'
fi
}
vi-grep() {
# selection=$(grep --color=always -rni ${READLINE_LINE:-} 2>/dev/null |
# fzf --ansi |
# awk -F : '{print $1 " +" $2}')
selection=$(Rg | awk -F : '{print $1 " +" $2}')
if [[ -n $selection ]]; then
READLINE_LINE="$EDITOR $selection${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( ${#EDITOR} + 1 + ${#selection} ))
builtin bind '"\e@": accept-line'
else
builtin bind '"\e@": abort'
fi
}
fzf-rl() {
builtin eval "
builtin bind ' \
\"\e#\": $(
builtin bind -l | command fzf +m
) \
'
"
}
bind -x '"\exx": fzf-rl'
bind -m vi-insert '"\C-l": "\exx\e#"'
#---------------------------------------------------
# binds
#---------------------------------------------------
bind '"\M-al": accept-line'
bind '"\e@": end-of-line'
bind -x '"\ex1": vi-find'
bind -x '"\ex2": vi-find "" .git'
bind -x '"\ex3": vi-find ~/dot .git'
bind -x '"\ex4": vi-find ~/note .git'
bind -x '"\ex5": vi-grep'
# take in history from other shells
bind -x '"\C-h": history -n'
bind -m vi-insert '"\C-f": "\ex1\e@"'
bind -m vi-insert '"\ef": "\ex2\e@"'
bind -m vi-insert '"\C-e": "\ex3\e@"'
bind -m vi-insert '"\C-n": "\ex4\e@"'
bind -m vi-insert '"\C-g": "\ex5\e@"'
# TODO: Add a selector for all available executables