2021-10-29 06:03:39 -07:00
|
|
|
. ~/.prep # handle boring stuff like /etc/profile and $PATH
|
2019-06-13 03:48:02 -07:00
|
|
|
|
2021-07-29 00:37:35 -07:00
|
|
|
HISTFILE=~/.histfile
|
|
|
|
HISTSIZE=99999
|
|
|
|
SAVEHIST=99999
|
|
|
|
TIMEFMT=$'\e[93m%*U/%*E cpu/real (%P), %MM mem:\e[36m %J\e[0m'
|
|
|
|
DIRSTACKSIZE=24
|
|
|
|
|
2021-10-07 12:31:06 -07:00
|
|
|
setopt always_to_end # move cursor to end of word during completion
|
|
|
|
setopt append_history # share history...
|
|
|
|
setopt share_history # ...across sessions
|
2021-07-29 00:37:35 -07:00
|
|
|
setopt auto_cd # exec a dir to cd
|
|
|
|
setopt auto_list # Automatically list choices on ambiguous completion.
|
|
|
|
setopt auto_menu # Show completion menu on a successive tab press.
|
2021-10-07 12:31:06 -07:00
|
|
|
setopt auto_param_slash # add a trailing slash to directory completions
|
2021-07-29 00:37:35 -07:00
|
|
|
setopt auto_pushd # cd acts as pushd
|
|
|
|
setopt brace_ccl # for character ranges like {a-z}
|
|
|
|
setopt chase_links # cd into link resolves link
|
|
|
|
setopt check_jobs notify # automatic job reporting
|
|
|
|
setopt complete_aliases # allow original command completion within alias
|
|
|
|
setopt complete_in_word # enable tab completion from any characters in a word
|
|
|
|
setopt extended_glob # required for various scripts in this file and otherwise
|
|
|
|
setopt hist_expire_dups_first # sharing/appending will result in dups
|
|
|
|
setopt hist_ignore_dups # don't push lines identical to the previous
|
|
|
|
setopt hist_ignore_space # don't push lines beginning with spaces
|
2021-09-23 06:49:54 -07:00
|
|
|
setopt hist_reduce_blanks # trim superfluous spaces
|
2021-10-07 12:31:06 -07:00
|
|
|
setopt hist_save_no_dups
|
|
|
|
setopt hist_verify
|
2024-02-28 09:32:25 -08:00
|
|
|
setopt interactive_comments # allow #-comments in interactive shells
|
2021-07-29 00:37:35 -07:00
|
|
|
setopt ksh_typeset # treat `local x=$(cmd)` and `local x="$(cmd)"` the same
|
2021-10-01 06:04:30 -07:00
|
|
|
setopt menu_complete # autoselect the first completion entry
|
|
|
|
setopt no_beep # be quiet
|
2021-07-29 00:37:35 -07:00
|
|
|
setopt no_match # error on bad tab-complete
|
|
|
|
setopt path_dirs # Perform path search even on command names with slashes.
|
2024-07-06 04:51:13 -07:00
|
|
|
setopt prompt_cr prompt_sp # prevent truncated output from ruining shell prompts
|
2021-07-29 00:37:35 -07:00
|
|
|
setopt rc_quotes # 'it''s okay' becomes "it's okay"
|
|
|
|
unsetopt flow_control # Disable start/stop characters in shell editor.
|
2024-02-23 22:29:55 -08:00
|
|
|
unsetopt bang_hist # this does nothing but cause me grief (disables !s)
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-10-29 03:19:18 -07:00
|
|
|
function {
|
|
|
|
if [ "$SHLVL" -le 1 ] \
|
2022-04-12 04:15:15 -07:00
|
|
|
&& [ "${(L)HOST}" != spectre ] \
|
2021-10-29 03:19:18 -07:00
|
|
|
&& [ "${TERM#screen}" = "$TERM" ] \
|
|
|
|
&& [ "${TERM#tmux}" = "$TERM" ] \
|
2022-01-08 21:16:32 -08:00
|
|
|
&& [ -z "$ALACRITTY_LOG" ] \
|
2021-10-29 03:19:18 -07:00
|
|
|
&& (( $+commands[tmux] ))
|
|
|
|
then
|
2019-06-05 16:51:30 -07:00
|
|
|
# create a new session called "what" or attach if it already exists
|
2021-10-29 03:19:18 -07:00
|
|
|
local env=(LANG="en_US.UTF-8" TZ=":/etc/localtime")
|
|
|
|
local cmd=(tmux new -A -s what)
|
|
|
|
[ "${TTY#/dev/cons}" = "$TTY" ] || cmd=(script -qfec "$cmd" /dev/null)
|
|
|
|
env $env $cmd && exit
|
2021-07-29 00:37:35 -07:00
|
|
|
printf '\e[91m\ntmux died (%i), continuing...\n\e[0m\n' $?
|
2019-06-05 16:10:03 -07:00
|
|
|
fi
|
2021-10-29 03:19:18 -07:00
|
|
|
}
|
2019-06-05 16:10:03 -07:00
|
|
|
|
2021-07-29 00:37:35 -07:00
|
|
|
autoload -U zmv
|
|
|
|
autoload -U zrecompile
|
|
|
|
autoload -Uz zcalc
|
|
|
|
autoload edit-command-line
|
|
|
|
autoload history-search-end
|
|
|
|
zmodload zsh/mathfunc
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2021-09-25 00:33:25 -07:00
|
|
|
dummy() : ### @- return 0, ignoring arguments.
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2021-07-30 18:14:05 -07:00
|
|
|
dirprev() { ### @-
|
2021-07-30 17:57:08 -07:00
|
|
|
### rotate and change to the previous directory in the directory stack
|
|
|
|
### without consuming the prompt.
|
2013-07-09 20:27:19 -07:00
|
|
|
pushd -q +1
|
|
|
|
zle reset-prompt
|
|
|
|
precmd
|
|
|
|
}
|
2021-07-30 18:14:05 -07:00
|
|
|
dirnext() { ### @-
|
2021-07-30 17:57:08 -07:00
|
|
|
### rotate and change to the next directory in the directory stack
|
|
|
|
### without consuming the prompt.
|
2013-07-09 20:27:19 -07:00
|
|
|
pushd -q -0
|
|
|
|
zle reset-prompt
|
|
|
|
precmd
|
|
|
|
}
|
2021-07-30 18:14:05 -07:00
|
|
|
dirup() { ### @-
|
2021-07-30 17:57:08 -07:00
|
|
|
### change to the parent directory of the current working directory
|
|
|
|
### without consuming the prompt.
|
2013-07-09 20:27:19 -07:00
|
|
|
cd ..
|
|
|
|
zle reset-prompt
|
|
|
|
precmd
|
|
|
|
}
|
2021-07-30 18:14:05 -07:00
|
|
|
dirview() { ### @-
|
2021-07-30 17:57:08 -07:00
|
|
|
### use a fuzzy finder to select a recent directory in the directory stack
|
|
|
|
### and change to it without consuming the prompt.
|
2021-10-21 08:01:23 -07:00
|
|
|
local fuzzy="$(have fzy || print)"
|
2013-07-09 20:27:19 -07:00
|
|
|
print
|
2021-07-29 00:37:35 -07:00
|
|
|
if [ -n "$fuzzy" ]; then
|
|
|
|
local d="$(dirs -pl | awk '!seen[$0]++' | "$fuzzy")"
|
|
|
|
cd "$d"
|
|
|
|
else
|
|
|
|
# TODO: print under prompt if possible,
|
|
|
|
# truncate and columnize
|
|
|
|
dirs -v
|
|
|
|
fi
|
2013-07-09 20:27:19 -07:00
|
|
|
zle reset-prompt
|
2021-07-29 00:37:35 -07:00
|
|
|
precmd
|
2013-07-09 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
2021-09-22 20:12:28 -07:00
|
|
|
for x (dummy dirprev dirnext dirup dirview) zle -N $x
|
2013-07-09 20:27:19 -07:00
|
|
|
|
2024-06-17 20:57:25 -07:00
|
|
|
join-lines() {
|
|
|
|
BUFFER="${BUFFER//$'\n'/ }"
|
|
|
|
CURSOR="${#BUFFER}"
|
|
|
|
}
|
|
|
|
zle -N join-lines
|
|
|
|
|
2013-06-28 05:22:14 -07:00
|
|
|
bindkey -e # emacs-style keybinds
|
2015-03-05 12:08:52 -08:00
|
|
|
|
|
|
|
# oh thank god: http://blog.samsonis.me/2013/12/bash-like-history-search-functionality-for-zsh/
|
|
|
|
zle -N history-beginning-search-backward-end history-search-end
|
|
|
|
zle -N history-beginning-search-forward-end history-search-end
|
|
|
|
bindkey '^[[A' history-beginning-search-backward-end # up
|
|
|
|
bindkey '^[[B' history-beginning-search-forward-end # down
|
2015-03-30 21:42:01 -07:00
|
|
|
bindkey '^[OA' history-beginning-search-backward-end # up
|
|
|
|
bindkey '^[OB' history-beginning-search-forward-end # down
|
2015-03-05 12:08:52 -08:00
|
|
|
|
2020-06-25 08:13:16 -07:00
|
|
|
bindkey '^[[1;5D' emacs-backward-word # ctrl+left
|
|
|
|
bindkey '^[[1;5C' emacs-forward-word # ctrl+right
|
|
|
|
bindkey '^[[1;3D' dirprev # alt+left
|
|
|
|
bindkey '^[[1;3C' dirnext # alt+right
|
|
|
|
bindkey '^[[1;3A' dirup # alt+up
|
|
|
|
bindkey '^[[1;3B' dirview # alt+down
|
2013-06-28 05:22:14 -07:00
|
|
|
bindkey -s '^[s' '^Asudo ^E' # alt+s
|
2024-06-17 20:57:25 -07:00
|
|
|
bindkey '^[j' join-lines # alt+j
|
2021-09-23 06:49:54 -07:00
|
|
|
bindkey '^[[3~' delete-char # del
|
2021-09-22 20:12:28 -07:00
|
|
|
bindkey '^[[1~' beginning-of-line # home
|
|
|
|
bindkey '^[[4~' end-of-line # end
|
|
|
|
bindkey '^[[Z' reverse-menu-complete # shift+tab
|
|
|
|
|
|
|
|
# prevent erroneous inputs from inputting anything.
|
|
|
|
bindkey '^[[3;5~' dummy # ctrl+del
|
|
|
|
bindkey '^[[5;5~' dummy # ctrl+PgUp
|
|
|
|
bindkey '^[[6;5~' dummy # ctrl+PgDn
|
|
|
|
bindkey '^[[5;6~' dummy # ctrl+shift+PgUp
|
|
|
|
bindkey '^[[6;6~' dummy # ctrl+shift+PgDn
|
2021-10-06 19:26:20 -07:00
|
|
|
bindkey '^[[3;2~' dummy # shift+del
|
2021-09-22 20:12:28 -07:00
|
|
|
bindkey '^[[1;2F' dummy # shift+end, do nothing, already at bottom (tmux)
|
|
|
|
bindkey '^[[6;2~' dummy # shift+PgDn, do nothing, already at bottom (tmux)
|
|
|
|
bindkey '^[[2;3~' dummy # alt+ins
|
|
|
|
bindkey '^[[3;3~' dummy # alt+del
|
|
|
|
bindkey '^[[5;3~' dummy # alt+PgUp
|
|
|
|
bindkey '^[[6;3~' dummy # alt+PgDn
|
|
|
|
bindkey '^[[2;4~' dummy # alt+shift+ins
|
|
|
|
bindkey '^[[3;4~' dummy # alt+shift+del
|
|
|
|
bindkey '^[[1;4H' dummy # alt+shift+home
|
|
|
|
bindkey '^[[1;4F' dummy # alt+shift+end
|
|
|
|
bindkey '^[[5;4~' dummy # alt+shift+PgUp
|
|
|
|
bindkey '^[[6;4~' dummy # alt+shift+PgDn
|
|
|
|
bindkey '^[[1;6q' dummy # ctrl+shift+1
|
|
|
|
bindkey '^[[1;6s' dummy # ctrl+shift+3
|
|
|
|
bindkey '^[[1;6t' dummy # ctrl+shift+4
|
|
|
|
bindkey '^[[1;6u' dummy # ctrl+shift+5
|
|
|
|
bindkey '^[[1;6w' dummy # ctrl+shift+7
|
|
|
|
bindkey '^[[1;6x' dummy # ctrl+shift+8
|
|
|
|
bindkey '^[[1;6y' dummy # ctrl+shift+9
|
|
|
|
bindkey '^[[1;6l' dummy # ctrl+shift+comma
|
|
|
|
bindkey '^[[1;6n' dummy # ctrl+shift+period
|
|
|
|
bindkey '^[[1;7A' dummy # ctrl+alt+arrow
|
|
|
|
bindkey '^[[1;7B' dummy # ctrl+alt+arrow
|
|
|
|
bindkey '^[[1;7C' dummy # ctrl+alt+arrow
|
|
|
|
bindkey '^[[1;7D' dummy # ctrl+alt+arrow
|
|
|
|
bindkey '^[[1;8A' dummy # ctrl+alt+shift+arrow
|
|
|
|
bindkey '^[[1;8B' dummy # ctrl+alt+shift+arrow
|
|
|
|
bindkey '^[[1;8C' dummy # ctrl+alt+shift+arrow
|
|
|
|
bindkey '^[[1;8D' dummy # ctrl+alt+shift+arrow
|
2021-01-12 16:40:03 -08:00
|
|
|
|
2013-06-28 05:22:14 -07:00
|
|
|
zle -N edit-command-line # new widget of the same function name
|
|
|
|
bindkey '^Xe' edit-command-line # ctrl+x -> e
|
|
|
|
|
2024-02-24 08:20:02 -08:00
|
|
|
# these drive letters were once to counteract my overzealous zsh completions.
|
2021-09-25 04:04:41 -07:00
|
|
|
hash -d c="/c"
|
|
|
|
hash -d d="/d"
|
|
|
|
[ -d /media/chibi ] && hash -d e="/media/chibi" || hash -d e="/e"
|
|
|
|
hash -d s="/s"
|
|
|
|
|
|
|
|
if [ -n "$MSYSTEM" ]; then
|
|
|
|
hash -d cyg=~c/cygwin/home/$USER
|
|
|
|
hash -d msys=~c/msys64/home/$USER
|
|
|
|
hash -d win=~c/Users/$USER
|
|
|
|
hash -d py=~win/Dropbox/py
|
|
|
|
else
|
|
|
|
hash -d py=~/Dropbox/py
|
|
|
|
fi
|
|
|
|
|
2021-10-29 06:23:25 -07:00
|
|
|
. ~/.shrc
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2021-07-30 17:57:08 -07:00
|
|
|
alias -g OMFG="1>/dev/null" ### @ OMFG - silence stdout.
|
|
|
|
alias -g STFU="2>/dev/null" ### @ STFU - silence stderr.
|
2024-06-17 20:57:58 -07:00
|
|
|
alias -g SWAP="3>&1 1>&2 2>&3" ### @ SWAP - swap stdout and stderr. uses fd 3 as an intermediary.
|
2021-07-30 17:57:08 -07:00
|
|
|
alias -g WHOA='${whoa[@]}' ### @ WHOA - expand to several C/C++ flags to ease development.
|
2021-12-02 13:06:05 -08:00
|
|
|
alias -g WHEE='${whee[@]}' ### @ WHEE - WHOA but for C++ (specifically g++) only.
|
2021-07-30 17:57:08 -07:00
|
|
|
alias -g WELP='${welp[@]}' ### @ WELP - expand to C++ flags to enable a C++-as-C facade.
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2024-03-21 05:24:22 -07:00
|
|
|
unalias 0x0.st
|
|
|
|
0x0.st() oxo "$@" # zsh hates the alias i set in .shrc, so use this instead
|
2017-02-24 15:23:26 -08:00
|
|
|
alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path
|
2017-01-30 15:36:23 -08:00
|
|
|
|
2015-04-06 17:10:48 -07:00
|
|
|
function {
|
2021-07-30 17:57:08 -07:00
|
|
|
# initialize prompts.
|
|
|
|
|
2019-06-05 16:52:02 -07:00
|
|
|
# zsh adds a % symbol to newline-less output, so my bash prompt is overkill
|
|
|
|
# NOTE: i've started hardcoding escapes instead of relying on zsh
|
|
|
|
# because detecting terminal features is too troublesome.
|
2024-04-02 22:22:51 -07:00
|
|
|
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
|
|
|
|
local chset=$'\033\050B\017' # set G0 to USASCII charset and "shift-in" to it
|
|
|
|
local s=$'\033\133' # CSI
|
|
|
|
local e=m # SGR
|
|
|
|
local reset=$s$e
|
|
|
|
local curse=$s$'?25h' # show cursor (DECTCEM)
|
2019-06-05 16:52:02 -07:00
|
|
|
local good=42 # green
|
|
|
|
local bad=41 # red
|
|
|
|
|
2021-09-27 19:22:10 -07:00
|
|
|
case "${(L)HOST}" in
|
|
|
|
(neobanshee) good=46;; # cyan
|
|
|
|
(spectre) good=47;; # white
|
|
|
|
(wraith) good=43;; # yellow
|
|
|
|
(sabotage) good=45;; # magenta
|
|
|
|
esac
|
2019-06-05 16:52:02 -07:00
|
|
|
|
2024-07-12 01:31:02 -07:00
|
|
|
local t="${TERM%%-*}"
|
|
|
|
if [ "$t" = xterm ] || [ "$t" = screen ] || [ "$t" = tmux ]; then
|
|
|
|
# set window title
|
|
|
|
if [ "$t" = tmux ] # don't include host, tmux prepends it
|
|
|
|
then precmd() { print -Pn "\e]2;%~\a" }
|
|
|
|
else precmd() { print -Pn "\e]2;%M: %~\a" }
|
|
|
|
fi
|
|
|
|
elif [ "$t" = alacritty ]; then
|
|
|
|
# Alacritty-v0.13.2-portable.exe -t "MinGW x64" -e "usr/bin/env" PATH="/usr/local/sbin:/usr/local/bin:/usr/bin" MSYSTEM=MINGW64 TERM=alacritty shelly
|
|
|
|
precmd() {}
|
|
|
|
chset= # displays as U+263C for some reason
|
|
|
|
else
|
|
|
|
# act dumb
|
|
|
|
precmd() {}
|
|
|
|
PROMPT="%# "
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-04-02 22:22:51 -07:00
|
|
|
PROMPT="%{$chset$curse$reset$s%(?.$good.$bad);97$e%}%#%{$reset%} "
|
2015-04-06 17:10:48 -07:00
|
|
|
}
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2021-07-30 18:14:05 -07:00
|
|
|
reload() { ### @-
|
2021-07-30 17:57:08 -07:00
|
|
|
### reload zsh by wiping temp files, recompiling rc files,
|
|
|
|
### and replacing the current process with a new zsh process.
|
2021-07-29 00:37:35 -07:00
|
|
|
# initctl has a "reload" symlink, but i'm already too used to typing this.
|
|
|
|
# to remedy this, when args are passed, invoke initctl instead.
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
"${commands[reload]:?initctl is missing}" "$@"
|
2021-09-30 08:47:00 -07:00
|
|
|
return # preserves $?
|
2021-07-29 00:37:35 -07:00
|
|
|
fi
|
|
|
|
|
2024-07-21 21:57:03 -07:00
|
|
|
if [ -n "$HOME" ] && cd -- "$HOME"; then
|
2021-09-30 08:47:00 -07:00
|
|
|
# this doesn't seem to help with _vim_files errors, eh.
|
|
|
|
# you wanna rm .zcompdump first, then exit. that's why!
|
2021-07-29 00:37:35 -07:00
|
|
|
[ -f .zshrc ] && zrecompile -p .zshrc
|
|
|
|
[ -f .prezto-compinit ] && zrecompile -p .prezto-compinit
|
|
|
|
rm -f .zcompdump .zshrc.zwc.old .zcompdump.zwc.old
|
|
|
|
fi
|
2013-07-01 18:05:17 -07:00
|
|
|
exec zsh # reload shell, inheriting environment
|
2013-06-28 05:22:14 -07:00
|
|
|
}
|
2013-06-29 11:47:01 -07:00
|
|
|
|
2020-11-05 08:22:52 -08:00
|
|
|
# generated by dircolors with https://github.com/isene/LS_COLORS
|
2020-11-05 08:21:45 -08:00
|
|
|
function {
|
2021-07-30 17:57:08 -07:00
|
|
|
# initialize colors for ls.
|
2020-11-05 08:21:45 -08:00
|
|
|
local lsc= line=
|
2021-10-01 06:03:57 -07:00
|
|
|
while read -r line; do
|
|
|
|
# strip any unprintable, non-ascii characters.
|
|
|
|
line="${line##*[! -~]}"
|
|
|
|
line="${line%%[! -~]*}"
|
2020-11-05 08:21:45 -08:00
|
|
|
lsc+="$line:"
|
2021-10-01 06:03:57 -07:00
|
|
|
done < ~/.ls_colors
|
2020-11-05 08:21:45 -08:00
|
|
|
export LS_COLORS="$lsc"
|
|
|
|
}
|
2019-06-08 01:46:40 -07:00
|
|
|
|
2021-09-25 04:04:41 -07:00
|
|
|
function {
|
|
|
|
local x=
|
|
|
|
# deprecated `for` syntax; who cares?
|
|
|
|
for x in ack cd cp ebuild gcc gist grep ln man mkdir mv rm
|
2021-09-25 19:09:30 -07:00
|
|
|
alias $x="nocorrect ${aliases[$x][@]:-$x}"
|
2021-09-25 04:04:41 -07:00
|
|
|
for x in ai arith curl fc find ftp hex history let locate \
|
2024-02-23 22:30:21 -08:00
|
|
|
rsync scp sftp tw twitch wget yt yt-dlp ytdl ytg
|
2021-09-25 19:09:30 -07:00
|
|
|
alias $x="noglob ${aliases[$x][@]:-$x}"
|
2021-09-25 04:04:41 -07:00
|
|
|
}
|
2021-07-04 05:08:52 -07:00
|
|
|
|
2021-10-07 12:31:32 -07:00
|
|
|
#zmodload zsh/complist # need all this
|
|
|
|
#autoload -Uz compinit && compinit # just for compdef
|
|
|
|
#compdef wat=which
|
2021-10-01 06:04:30 -07:00
|
|
|
#. ~/.prezto-compinit
|
2021-10-07 12:31:32 -07:00
|
|
|
|
2024-02-24 08:20:02 -08:00
|
|
|
! [ -e ~/.lol ] || . ~/.lol
|