-
Notifications
You must be signed in to change notification settings - Fork 0
/
.yashrc
411 lines (356 loc) · 11.9 KB
/
.yashrc
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
##### Dther's Yashrc #####
# Set environmental variables
export TERMCMD='st -e '
export TERMINAL='st'
export VISUAL='vi'
export EDITOR=$VISUAL
export _JAVA_AWT_WM_NONREPARENTING=1
export XDG_CONFIG_HOME="$HOME/.config/"
export INPUTRC='~/.inputrc'
export ELVISBG="dark"
export CHROME_EXECUTABLE='brave'
export TASHK_DIR="$HOME/docs/todo/"
export QT_QPA_PLATFORMTHEME="gtk2"
export QT_STYLE_OVERRIDE="gtk2"
export GTK_THEME="FlatColor:dark"
# Home clean up.
# TODO: MOVE THIS TO ANOTHER FILE. IN $XDG_CONFIG_HOME, IDEALLY.
alias cataclysm="cataclysm --configdir $XDG_CONFIG_HOME/.config/cataclysm-dda"
alias cmines="cmines -s $XDG_CONFIG_HOME/cminesrc"
alias crawl="crawl -dir $XDG_CONFIG_HOME/crawl"
alias abook="abook -C $XDG_CONFIG_HOME/abook/abookrc --datafile $XDG_DATA_HOME/abook/addressbook"
## Aliases ##
# system commands
alias ls='ls --color=auto'
alias pacman='pacman --color auto'
alias yay='yay --color auto'
alias info='info --vi-keys'
# for interacting with the git bare repository
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
config config status.showUntrackedFiles no
# rlwrapping
# Man, how did I go this long without finding this???
alias tclsh='rlwrap tclsh'
alias tashk='rlwrap -N tashk'
### Program Specific Aliases ###
# the testing grounds
alias h='habitctl'
# because screw limited passes, man.
# If it takes you more passes than 999 you suck at solitaire
alias ttysolitaire='ttysolitaire --no-background-color -p 999'
# terminal aesthetic B-)
alias angband='angband -mgcu'
# tashk aliases
export TASHK_LS_PREFILTER="tashkcolor.sh"
alias todo="tashk"
alias waiting="tashk -f waiting.txt"
alias projects="tashk -f projects.txt"
alias maybe="tashk -f maybe.txt"
# imagine using nano
alias nano="echo How about naNO && sleep 0.5 && vim"
# Run stuff
pfetch
tashk ls -p tashkcolor.sh
echo "---"
when --prefilter=m4 --future=7
#### From Common Yashrc ####
# enable bash-like extended expansion
set --brace-expand
# don't implicitly expand non-existent variables to empty strings
# Hmmm don't know if I like this either
set --no-unset
# if yash is built with command history enabled...
if command --identify --builtin-command history >/dev/null; then
# don't save commands starting with a space in history
set --hist-space
# prevent clearing history by accident
history()
if [ -t 0 ] && (
for arg do
case "${arg}" in
(-[drsw]?* | --*=*) ;;
(-*c*) exit;;
esac
done
false
) then
printf 'history: seems you are trying to clear the whole history.\n' >&2
printf 'are you sure? (yes/no) ' >&2
case "$(head -n 1)" in
([Yy]*) command history "$@";;
(*) printf 'history: cancelled.\n' >&2;;
esac
else
command history "$@"
fi
fi
# if yash is built with line-editing enabled...
if command --identify --builtin-command bindkey >/dev/null; then
# print job status update ASAP, but only while line-editing
set --notify-le
# some terminfo data are broken; meta flags have to be ignored for UTF-8
set --le-no-conv-meta
# enable command line prediction
set --le-predict
# most users are more familiar with emacs mode than vi mode
if [ -o vi ]; then
set --emacs
fi
# some useful key bindings
bindkey --emacs '\^N' beginning-search-forward
bindkey --emacs '\^O' clear-candidates
bindkey --emacs '\^P' beginning-search-backward
bindkey --emacs '\N' complete-next-column
bindkey --emacs '\P' complete-prev-column
# key bindings for vi mode, some of which are from emacs mode
bindkey --vi-insert '\^A' beginning-of-line
bindkey --vi-insert '\^B' backward-char
bindkey --vi-insert '\^D' eof-or-delete
bindkey --vi-insert '\#' eof-or-delete
bindkey --vi-insert '\^E' end-of-line
bindkey --vi-insert '\^F' forward-char
bindkey --vi-insert '\^K' forward-kill-line
bindkey --vi-insert '\^N' beginning-search-forward
bindkey --vi-insert '\^O' clear-candidates
bindkey --vi-insert '\^P' beginning-search-backward
bindkey --vi-insert '\^U' backward-kill-line
bindkey --vi-insert '\$' backward-kill-line
bindkey --vi-insert '\^W' backward-delete-viword
bindkey --vi-insert '\^Y' put-left
bindkey --vi-insert '\N' complete-next-column
bindkey --vi-insert '\P' complete-prev-column
bindkey --vi-command '\^N' beginning-search-forward
bindkey --vi-command '\^P' beginning-search-backward
fi
# some useful shortcuts
alias -- -='cd -'
alias la='ls -a' ll='ls -l' lla='ll -a'
alias r='fc -s'
# avoid removing/overwriting existing files by accident
cp() if [ -t 0 ]; then command cp -i "$@"; else command cp "$@"; fi
mv() if [ -t 0 ]; then command mv -i "$@"; else command mv "$@"; fi
#rm() if [ -t 0 ]; then command rm -i "$@"; else command rm "$@"; fi
# dash is faster-ish
#sh() { yash --posix "$@"; }
yash() { command yash "$@"; }
# By re-defining 'yash' using the 'command' built-in, the 'jobs' built-in
# prints a command name that exposes the arguments like
# 'yash --posix -n foo.sh' rather than a command name that hides the
# arguments like 'yash --posix "${@}"'. This applies to the 'yash' command
# invoked via the 'sh' function.
# ensure job control works as expected
case $- in (*m*)
trap - TSTP TTIN TTOU
esac
# avoid removing existing crontab by accident
crontab()
if [ -t 0 ] && (
for arg do
case "${arg}" in
(-*r*) exit;;
esac
done
false
) then
printf 'crontab: seems you are trying to clear your crontab.\n' >&2
printf 'are you sure? (yes/no) ' >&2
case "$(head -n 1)" in
([Yy]*) command crontab "$@";;
(*) printf 'crontab: cancelled.\n' >&2;;
esac
else
command crontab "$@"
fi
# an alias that opens a file
if command --identify xdg-open >/dev/null 2>&1; then
alias o='xdg-open'
elif command --identify cygstart >/dev/null 2>&1; then
alias o='cygstart'
elif [ "$(uname)" = Darwin ] 2>/dev/null; then
alias o='open'
fi
# define some basic variables if missing
: ${PAGER:=less} ${EDITOR:=vi} ${FCEDIT:=$EDITOR}
: ${LOGNAME:=$(logname)} ${HOSTNAME:=$(uname -n)}
# disable confusing treatment of arguments in the echo command
: ${ECHO_STYLE:=RAW}
# variables needed for command history
# FIXME: I find the default command history behaviour annoying, even after
# months of use.
# Yash has a strange habit of mangling its own history file when it's used
# by more than one process.
# I should change it to:
# - be per-process
# - clean up after itself (possibly through the use of aliasing exit
# or trapping SIGTERM)
# - OR have a cronjob that auto cleans up yash_history when it gets too big
# - ehhh... but that feels like too much effort...
# - Maybe have it do a quick check for processes that aren't running anymore?
# - I don't friggin know.
#HISTDIR=$HOME/.local/share/yash_hist/
#[ -d "$HISTDIR" ] || mkdir "$HISTDIR"
HISTFILE=
#HISTFILE=$HOME/.local/share/yash_history HISTSIZE=5000
# HISTRMDUP makes prediction less accurate
# HISTRMDUP=500
# default mail check interval is too long
# Also, who uses spoolfiles???
# TODO: See if I can make this check all my inboxes...
MAILPATH=$HOME/.local/share/mail/dther/INBOX/new/%"New dther mail":$HOME/.local/share/mail/outlook/Inbox/new/%"New outlook mail":$HOME/.local/share/mail/uq/INBOX/new/%"New uq mail"
MAILCHECK=0
# emulate bash's $SHLVL
if [ "${_old_shlvl+set}" != set ]; then
_old_shlvl=${SHLVL-}
fi
SHLVL=$((_old_shlvl+1)) 2>/dev/null || SHLVL=1
export SHLVL
# initialize event handlers
COMMAND_NOT_FOUND_HANDLER=()
PROMPT_COMMAND=()
YASH_AFTER_CD=()
# define prompt
if [ -n "${SSH_CONNECTION-}" ]; then
_hc='\fy.' # yellow hostname for SSH remote
else
_hc='\fg.' # green hostname for local
fi
if [ "$(id -u)" -eq 0 ]; then
_uc='\fr.' # red username for root
_2c='\fr.' # red PS2 for root
else
_uc=$_hc _hc= # same username color as hostname for non-root user
_2c= # PS2 in normal color for non-root user
fi
# The main prompt ($YASH_PS1) contains the username, hostname, working
# directory, last exit status (only if non-zero), and $SHLVL (only if
# non-one).
YASH_PS1=$_uc'${LOGNAME}'$_hc'@${HOSTNAME%%.*}\fd. '\
'${${${PWD:/~/\~}##*/}:-$PWD} ${{?:/0/}:+\\fr.$?\\fd. }${{SHLVL-0}:/1}\$ '
YASH_PS1R='\fc.${_vcs_info}'
YASH_PS1S='\fo.'
YASH_PS2=$_2c'> '
#YASH_PS2R=
YASH_PS2S=$YASH_PS1S
YASH_PS4='\fm.+ '
YASH_PS4S='\fmo.'
unset _hc _uc _2c
# No escape sequences allowed in the POSIXly-correct mode.
PS1='${LOGNAME}@${HOSTNAME%%.*} '$PS1
# find escape sequence to change terminal window title
# TODO: I don't know if i want this -dther
case "$TERM" in
(xterm|xterm[+-]*|gnome|gnome[+-]*|putty|putty[+-]*|cygwin)
_tsl='\033];' _fsl='\a' ;;
(*)
_tsl=$( (tput tsl 0; echo) 2>/dev/null |
sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g')
_fsl=$( (tput fsl ; echo) 2>/dev/null |
sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g') ;;
esac
# if terminal window title can be changed...
if [ "$_tsl" ] && [ "$_fsl" ]; then
# set terminal window title on each prompt
_set_term_title()
if [ -t 2 ]; then
printf "$_tsl"'%s@%s:%s'"$_fsl" "${LOGNAME}" "${HOSTNAME%%.*}" \
"${${PWD:/$HOME/\~}/#$HOME\//\~\/}" >&2
fi
PROMPT_COMMAND=("$PROMPT_COMMAND" '_set_term_title')
# reset window title when changing host or user
ssh() {
if [ -t 2 ]; then printf "$_tsl"'ssh %s'"$_fsl" "$*" >&2; fi
command ssh "$@"
}
su() {
if [ -t 2 ]; then printf "$_tsl"'su %s'"$_fsl" "$*" >&2; fi
command su "$@"
}
sudo() {
if [ -t 2 ]; then printf "$_tsl"'sudo %s'"$_fsl" "$*" >&2; fi
command sudo "$@"
}
fi
# define function that updates $_vcs_info and $_vcs_root
_update_vcs_info() {
typeset type branch
{
read --raw-mode type
read --raw-mode _vcs_root
read --raw-mode branch
} <(
exec 2>/dev/null
typeset COMMAND_NOT_FOUND_HANDLER=
while true; do
if [ -e .git ] || [ . -ef "${GIT_WORK_TREE-}" ]; then
printf 'git\n%s\n' "${GIT_WORK_TREE:-$PWD}"
git branch --no-color | sed -n '/^\*/s/^..//p'
exit
elif [ -d .hg ]; then
printf 'hg\n%s\n' "$PWD"
exec cat .hg/branch
elif [ -d .svn ]; then
printf 'svn\n'
_vcs_root=$(svn info --show-item=wc-root)
printf '%s\n' "$_vcs_root"
path=$(svn info --show-item=relative-url)
case $path in
(*/branches/*)
printf '%s\n' "${${path#*/branches/}%%/*}"
esac
exit
fi
if [ / -ef . ] || [ . -ef .. ]; then
exit
fi
cd -P ..
done
)
case "$type#$branch" in
(hg#default) _vcs_info='hg';;
(git#master) _vcs_info='git';;
(*# ) _vcs_info="$type";;
(* ) _vcs_info="$type@$branch";;
esac
}
# update $_vcs_info on each prompt
PROMPT_COMMAND=("$PROMPT_COMMAND" '_update_vcs_info')
# these aliases choose a version controlling program for the current directory
alias _vcs='${${_vcs_info:?not in a version-controlled directory}%%@*}'
alias ci='_vcs commit'
alias co='_vcs checkout'
alias di='_vcs diff'
alias log='_vcs log'
alias st='_vcs status'
alias up='_vcs update'
# when a directory name is entered as a command, treat as "cd"
_autocd()
if [ -d "$1" ]; then
HANDLED=true
cd -- "$@"
break -i
fi
COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_autocd "$@"')
# treat command names starting with % as "fg"
_autofg()
if [ $# -eq 1 ]; then
case $1 in (%*)
HANDLED=true
fg "$1"
break -i
esac
fi
COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_autofg "$@"')
# print file type when executing non-executable files
_file_type()
if [ -e "$1" ] && ! [ -d "$1" ]; then
file -- "$1"
fi
COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_file_type "$@"')
# Custom prompt?
#promptred="$(tput setaf 1)"
#promptblue="$(tput setaf 4)"
#promptyellow="$(tput setaf 3)"
#promptcyan="$(tput setaf 6)"
#promptclear="$(tput sgr0)"
#YASH_PS1="\$(date +%H%M) $promptclear""$promptred"'['"$promptyellow""\$USER""$promptclear"'@'"$promptblue""${HOSTNAME:-$(hostname)}""$promptclear"':'"$promptcyan"'${${${PWD:/~/\~}##*/}:-$PWD}'"$promptred"']'"$promptclear"'$ '
# vim: set et sw=2 sts=2 tw=78 ft=sh: