/
.bashrc
211 lines (177 loc) · 5.07 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
#!/bin/bash
shopt -s globstar
HISTSIZE=8192 HISTFILESIZE=32000
HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
alias l="less"
alias s="sudo"
alias se="sudoedit"
alias v="nvim"
alias sp="sed -r 's/([^:]*:[^:]*:)/\1\t/'"
alias m="sudo mount"
alias um="sudo umount"
mkcd() { mkdir -p "$1" && cd "$1"; }
cdr() { cd $(git rev-parse --show-toplevel); }
cdc() {
local ref=${1:-HEAD}
# cd into the repo root first
cd $(git rev-parse --show-toplevel)
# cd into the directory containing all the changes
cd $(git diff-tree --no-commit-id --name-only -r $ref | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D')
}
pgr() { ps aux | grep -v grep | grep -iE "$@"; }
# alias rg="rg --no-heading --max-columns=150 --max-columns-preview"
source /usr/share/fzf/key-bindings.bash
source /usr/share/fzf/completion.bash
_completion_loader git
galias() {
alias $1="git ${3:-$2}"
__git_complete $1 _git_$2
}
galias gad add
galias gbi bisect
galias gbr branch
galias gcm commit
galias gcp cherry_pick "cherry-pick"
galias gdf diff
galias glo log "-c core.pager='less -p \"^commit \"' log"
galias glop log "-c core.pager='less -p \"^commit \"' log -p --format=fuller --stat"
galias gmr merge
galias gpl pull "pull --stat"
galias gps push
galias gpsf push "push --force-with-lease"
galias grb rebase
galias grs reset
galias grsh reset "reset --hard"
galias grt remote
galias grv revert
galias gsh show
galias gsm submodule
galias gst stash "-c core.pager='less -p ^stash' stash"
galias gw switch
galias gr restore
gwm() { gw "$@" $(git-default-branch); }
gdfm() { gdf "$@" $(git-default-branch); }
grbm() { grb "$@" $(git-default-branch); }
__git_complete gbrd _git_branch
alias gclo="git clone"
alias grbc="git rebase --continue"
alias ggc="git gc --prune=all"
alias ggr="git grep -InE"
alias spc="sudo pacman"
alias ssi="pacman -Sii"
ssq() { pacman -Qs "$@" | sed -n 's_local/__p'; }
alias srm="spc -Rns"
alias sim="spc -S --needed"
alias mksrcinfo="makepkg --printsrcinfo >.SRCINFO"
alias sc="sudo systemctl"
alias scu="systemctl --user"
alias jc="journalctl"
alias ls="ls -F"
alias ll="ls -lhiF"
alias la="ls -alhiF"
alias lt="ls -Alhrt"
alias zs="sudo -E $SHELL"
alias rr="rm -rf"
alias cd.="cd .."
alias cd..="cd ../.."
alias cd...="cd ../../.."
wgo1() { PATH=/usr/lib/go/bin:${PATH} "$@"; }
wgo() {
local gocmd=go${1}
shift
PATH=$(${gocmd} env GOROOT)/bin:${PATH} "$@"
}
alias gg="go get"
alias ggn="go generate"
alias gb="go build -v"
alias gi="go install -v"
alias gt="go test"
alias gts="go test -vet=off -short -timeout 10s"
alias gf="go test -run=- -vet=off -fuzz"
gstr() {
if [[ $# == 0 || $1 == help ]]; then
echo "gstr [stress flags] ./test [test flags]"
return
fi
echo "go test -c -vet=off -o test && stress $@"
go test -c -vet=off -o test && stress "$@"
}
gcov() {
go test -coverpkg=./... "$@" -coverprofile=/tmp/c
go tool cover -html=/tmp/c
}
alias gtoolcmp='go build -toolexec "toolstash -cmp" -a -v std cmd'
gim() { goimports -l -w ${@:-*.go}; }
gfm() { gofumpt -l -w ${@:-*.go}; }
sfm() { shfmt -s -l -w ${@:-.}; }
alias ssm="pacman -Ss"
alias ssk="yay -Ss"
syu() {
echo " -- yay --"
yay -Syu || return 1
echo " -- flatpak --"
flatpak update || return 1
echo " -- fwupdmgr --"
sudo fwupdmgr refresh || return 1
sudo fwupdmgr get-updates || true # no updates is code 1
}
alias gca="gcm -a"
alias gcam="gcm -a --amend"
alias gcle="git clean -dffx"
alias gdfs="gdf --stat"
alias gdfc="gdf --cached"
alias gdfo="gdf ORIG_HEAD"
alias gdfu="gdf @{u}"
alias gfe="git fetch -v -p"
alias gfea="git fetch -v -p --all"
alias glopo="glop --reverse ORIG_HEAD.."
alias glopu="glop --reverse ..@{u}"
alias glos="glo --stat"
alias grbi="grb -i"
alias grbia="grb -i --autosquash"
alias grmc="git rm --cached"
alias gs="git status -sb"
alias gso="git status -sbuno"
alias gss="git status -sb --ignored"
alias gsmf="gsm foreach --recursive"
alias gsmu="gsm update --init --recursive"
alias gsmfc="gsmf 'git clean -dffx && git reset --hard' && gcle && grsh"
git-default-branch-fix() { git remote set-head origin -a; }
git-default-branch() { git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'; }
git-file-sizes() { git ls-files -z | xargs -0 du -b | sort -n; }
gfork() {
gh repo fork --remote --remote-name mvdan
}
gmrc() { git push origin -o merge_request.create "$@"; }
alias gml="git-codereview mail"
alias ssh="TERM=xterm ssh"
alias rsv="rsync -avh --info=progress2"
alias clb='curl -F "clbin=<-" https://clbin.com'
alias bat='bat --pretty=false'
alias unr='arc unarchive'
case $TERM in
linux* | cons*) ;;
*) PS1="\[\033]0;\w\007\]" ;;
esac
export PS1+='\$ '
# https://codeberg.org/dnkl/foot/wiki#user-content-shell-integration
osc7_cwd() {
local strlen=${#PWD}
local encoded=""
local pos c o
for (( pos=0; pos<strlen; pos++ )); do
c=${PWD:$pos:1}
case "$c" in
[-/:_.!\'\(\)~[:alnum:]] ) o="${c}" ;;
* ) printf -v o '%%%02X' "'${c}" ;;
esac
encoded+="${o}"
done
printf '\e]7;file://%s%s\e\\' "${HOSTNAME}" "${encoded}"
}
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }osc7_cwd
prompt_marker() {
printf '\e]133;A\e\\'
}
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }prompt_marker