-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.shrc
259 lines (226 loc) · 5.62 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
# Generic shell initialization
# Can be sourced from .zshrc, .bashrc, .kshrc, etc.
kernel="$(uname)"
iscmd() {
command -v "$1" >/dev/null 2>&1
}
# Add directory to PATH if it exists and isn't already in PATH.
addtopath() {
[ ! -d $1 ] && return
echo "$PATH" | grep ":$1$" >/dev/null && return
echo "$PATH" | grep ":$1:" >/dev/null && return
export PATH=$PATH:$1
}
addtopath $HOME/bin
addtopath $HOME/.local/bin
addtopath $HOME/go/bin
addtopath $HOME/.cargo/bin
if [ -d /usr/local/plan9 ]; then
export PLAN9=/usr/local/plan9
elif [ -d $HOME/plan9 ]; then
export PLAN9=$HOME/plan9
fi
[ ! -z "$PLAN9" ] && addtopath $PLAN9/bin
# vis text editor installs as vise in *BSD userlands because there's a vis(1)
# utility in the base system
vis_exe='vis'
if [ "$kernel" = "Darwin" ] || [ "$kernel" = "FreeBSD" ] || [ "$kernel" = "OpenBSD" ]; then
vis_exe='vise'
if iscmd $vis_exe; then
alias visu='/usr/bin/vis'
alias vis='vise'
fi
fi
for e in nano-wrapper nano $vis_exe nvim vim vi mg jmacs godit; do
if iscmd $e; then
export EDITOR=$e
export VISUAL=$e
break
fi
done
if iscmd fzf; then
fzp() {
if [ $# -lt 1 ]; then
echo "fzp: must specify a program name" 1>&2
return 1
fi
program="$1"
shift
"$program" "$@" $(fzf -m)
}
fze() {
if [ -z "$VISUAL" ]; then
echo "fze: cannot open editor when VISUAL is unset"
return 1
fi
fzp "$VISUAL" "$@"
}
fi
# Modified commands
if [ "$kernel" != "OpenBSD" ]; then
alias grep='grep --color=auto'
fi
alias df='df -h'
alias du='du -h'
mkcd() {
if [ $# -eq 0 ]; then
echo "$0: missing operand" 1>&2
echo "usage: $0 directory" 1>&2
echo "mkdir and chdir into the given directory." 1>&2
return 1
fi
mkdir -p "$1"
cd "$1"
}
upcd() {
dir=""
for i in $(seq 1 $1); do
dir="../$dir"
done
[ -z "$dir" ] && dir="$PWD"
cd "$dir"
}
lk() {
if ! iscmd walk; then
echo "lk: walk must be installed" 1>&2
return 1
fi
cd "$(walk "$@")"
}
# ls
if [ "$kernel" = "OpenBSD" ]; then
alias ls='ls -hF'
else
alias ls='ls -hF --color=auto'
fi
alias lr='ls -R' # recursive ls
alias ll='ls -l' # detailed ls
alias la='ll -A' # detailed ls, including dotfiles
if [ "$kernel" = "Linux" ]; then
alias lx='ll -BX' # sort by extension
fi
alias lz='ll -rS' # sort by size
alias lt='ll -rt' # sort by date
# Safety features
alias cp='cp -i'
alias mv='mv -i'
if [ "$kernel" != "OpenBSD" ]; then
alias rm='rm -I'
alias ln='ln -i'
fi
if [ "$kernel" = "Linux" ]; then
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
fi
# Image viewing
if iscmd nsxiv; then
alias img='nsxiv'
elif iscmd sxiv; then
alias img='sxiv'
fi
# Screen capturing from terminal.
if iscmd maim; then
alias screencap_desktop='maim'
alias screencap_window='maim -st 9999999'
alias screencap_select='maim -s'
if iscmd xclip; then
alias clip_png='xclip -selection clipboard -t image/png'
fi
fi
# GNU Emacs
if iscmd emacs; then
alias ge='emacs -nw'
alias gec='emacsclient -n'
fi
# Shorter name for JOE's Emacs emulation
iscmd jmacs && alias jm='jmacs'
# Alias for lightweight Emacs-like editor
for e in godit-wrapper godit mg jmacs jed zile qemacs; do
if iscmd $e; then
alias em="$e"
break
fi
done
if iscmd nvim; then
alias vi='nvim'
alias vim='nvim'
elif iscmd vim; then
alias vi='vim'
fi
# new vi (aka nvi aka Berkeley vi) is commonly installed as ex/vi. Try to
# provide nex/nvi aliases for it.
if ! iscmd nex; then
# Prefer /usr/bin/ex if it exists since on BSD that's nvi whereas
# /usr/local/bin/ex would be vim (if installed). On Linux, there isn't
# a convenient and portable way of distinguishing nvi's ex from other
# implementations (e.g., vim's or Ancient Vi's) so don't try.
if [ -x '/usr/bin/ex' ]; then
alias nex='/usr/bin/ex'
elif iscmd ex; then
alias nex='ex'
fi
fi
! iscmd nvi && iscmd nex && alias nvi='nex -v'
if iscmd nano; then
# invoke nano via a wrapper script
# <https://github.com/ixtenu/script/blob/master/nano-wrapper>
iscmd nano-wrapper && alias nano='nano-wrapper'
# four letters is too many
! iscmd na && alias na='nano'
fi
if iscmd sam; then
# sam-wrapper isn't meant for plan9port sam.
if [ -z "$PLAN9" ] || [ "$(which sam)" != "$PLAN9/bin/sam" ]; then
# invoke sam via a wrapper script
# <https://github.com/ixtenu/script/blob/master/sam-wrapper>
iscmd sam-wrapper && alias sam='sam-wrapper'
fi
fi
[ -f "$HOME/.qed/env" ] && . "$HOME/.qed/env"
# Alias helix to hx on systems which install it as helix
if iscmd helix && ! iscmd hx; then
alias hx='helix'
fi
# textadept is much too long
iscmd textadept && ! iscmd ta && alias ta='textadept'
# allow running SciTE without typing uppercase letters
iscmd SciTE && ! iscmd scite && alias scite='SciTE'
# Debian/Ubuntu renamed fd to fdfind due to a naming conflict.
if iscmd fdfind && ! iscmd fd; then
alias fd='fdfind'
fi
# kitty's SSH wrapper.
if iscmd kitty; then
alias kssh='kitty +kitten ssh'
fi
# Consistent names for Sublime Text and Sublime Merge
if ! iscmd subl; then
if iscmd sublime_text; then
alias subl='sublime_text'
elif iscmd subl-text; then
alias subl='subl-text'
elif iscmd subl4; then
alias subl='subl4'
fi
fi
if ! iscmd subm; then
if iscmd sublime_merge; then
alias subm='sublime_merge'
elif iscmd subl-merge; then
alias subm='subl-merge'
elif iscmd smerge; then
alias subm='smerge'
fi
fi
# Alternate name for vscode
! iscmd code && iscmd code-oss && alias code='code-oss'
# Alias sudo to doas and vice versa if one is available and the other isn't.
if ! iscmd sudo && iscmd doas; then
if [ -f /etc/doas.conf ] || [ -f /usr/local/etc/doas.conf ]; then
alias sudo='doas'
fi
fi
if ! iscmd doas && iscmd sudo && [ -f /etc/sudoers ]; then
alias doas='sudo'
fi