-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_shrc
231 lines (201 loc) · 4.14 KB
/
dot_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
#!/bin/sh
if uname -r | grep -q microsoft; then
julie_fix_wsl_interop() {
if ! test -e ${WSL_INTEROP}; then
_pid="${PPID}"
while test -n "${_pid}"; do
if test -e "/run/WSL/${_pid}_interop"; then
export WSL_INTEROP="/run/WSL/${_pid}_interop"
break
fi
_pid=$(awk '$1 == "PPid:" { print $2 }' "/proc/${_pid}/status")
done
fi
}
julie_fix_wsl_interop
fi
has() {
command -v $1 > /dev/null
}
source_if_has() {
[ -s "${1}" ] && . "${1}"
}
set -o vi
export PATH="${HOME}/.local/bin${PATH:+:${PATH}}"
export HISTSIZE=1000
export SAVEHIST=1000
export BC_ENV_ARGS="${XDG_CONFIG_HOME}/bc"
export LESS="--mouse"
if has starship; then
case "${TTY}" in
/dev/tty[0-9])
export STARSHIP_CONFIG="${XDG_CONFIG_HOME}/starship_tty.toml"
;;
esac
fi
if has doas && ! has sudo; then
alias sudo=doas
elif has sudo && ! has doas; then
alias doas=sudo
fi
if has nvim; then
alias vim=nvim
export MANPAGER='nvim +Man!'
export MANWIDTH=100
export EDITOR=nvim
elif has vim; then
alias nvim=vim
export EDITOR=vim
elif has vi; then
alias nvim=vi
alias vim=vi
export EDITOR=vi
fi
if has eza; then
alias ls='eza'
alias ll='eza -lg --git'
alias la='eza -lag --git'
alias tree='eza -Tlag --git'
elif has exa; then
alias ls='exa'
alias ll='exa -lg --git'
alias la='exa -lag --git'
alias tree='exa -Tlag --git'
else
alias ll='ls -l'
alias la='ls -la'
fi
. "${HOME}/.aliases"
[ -r "${HOME}/.cargo/env" ] && . "${HOME}/.cargo/env"
if has swayidle && has zzz && has swayzzz; then
alias zzz=swayzzz
fi
if [ `id -u` != 0 ] && has doas; then
alias poweroff='doas poweroff'
alias reboot='doas reboot'
fi
if has apk; then
whichapk() {
if [ -f "${1}" ]; then
file="${1}"
else
file=`which "${1}"`
fi
apk info -W "${file}"
}
upgradeable=`apk list --upgradeable | wc -l`
[ "${upgradeable}" -gt 0 ] && printf "There are ${upgradeable} upgradeable apk packages.\n"
unset upgradeable
fi
if has brew; then
eval "$(brew shellenv)"
source_if_has "${HOMEBREW_PREFIX}/opt/nvm/nvm.sh"
elif [ `uname` = "Linux" ]; then
export NVM_DIR="${XDG_CONFIG_HOME}/nvm"
source_if_has "${NVM_DIR}/nvm.sh"
fi
if [ -n "$WAYLAND_DISPLAY" ] && has wl-copy && has wl-paste; then
clip() {
if [ -t 0 ]; then # stdin is TTY, we have no input
wl-paste
else
cat | wl-copy
fi
}
elif has pbcopy && has pbpaste; then
clip() {
if [ -t 0 ]; then # stdin is TTY, we have no input
pbpaste
else
cat | pbcopy
fi
}
fi
ii() {
if [ `uname` = "Darwin" ]; then
open "$@"
return
fi
if [ -d "$1" ] && has thunar; then
thunar "$@"
return
fi
if has xdg-open; then
xdg-open "$@" >/dev/null 2>&1 &
return
fi
echo >&2 "don't know how to ii"
return 1
}
catwhich() {
file=`which "${1}"` || return 1
cat "${file}"
}
select_git_branch() {
if ! has fzf; then
echo "fzf not available"
return 1
fi
git for-each-ref refs/heads \
--sort=-committerdate \
--format='%(refname:short)' \
| fzf ${1:+-q "$1"} | awk '{$1=$1};1'
}
select_git_commit() {
if ! has fzf; then
echo "fzf not available"
return 1
fi
PAGER= git log \
--color \
--max-count=200 \
| fzf --ansi ${1:+-q "$1"} | awk '{print $1}'
}
git_reset() {
case "$1" in
--soft|--hard)
local type="$1"
shift
;;
esac
local commit="$1"
if [ -z "${commit}" ]; then
commit=$(select_git_commit)
fi
while [ -n "${commit}" ]; do
if git reset $type "${commit}"; then
commit=
else
commit="$(select_git_commit "${commit}")"
fi
done
}
ga() {
local arg="${1:---all}"
git add $arg "$@"
}
gcm() {
git commit -m "$*"
}
gacm() {
git add --all && git commit -m "$*"
}
gacmp() {
git add --all && git commit -m "$*" && git push
}
gco() {
local branch="$1"
if [ -z "${branch}" ]; then
branch=$(select_git_branch)
fi
while [ -n "${branch}" ]; do
if git checkout "${branch}"; then
branch=
else
branch="$(select_git_branch "${branch}")"
fi
done
}
alias gres='git_reset'
alias ghard='git_reset --hard'
alias gsoft='git_reset --soft'