1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-20 02:43:23 -07:00
rc/home/zshrc

265 lines
9.3 KiB
Bash
Raw Normal View History

[ -e /etc/profile ] && emulate sh -c "source /etc/profile"
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
setopt always_to_end # Move cursor to the end of a completed word.
setopt append_history
setopt share_history # across sessions
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.
setopt auto_param_slash # If completed parameter is a directory, add a trailing slash.
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
setopt ksh_typeset # treat `local x=$(cmd)` and `local x="$(cmd)"` the same
setopt no_beep
setopt no_match # error on bad tab-complete
setopt path_dirs # Perform path search even on command names with slashes.
setopt rc_quotes # 'it''s okay' becomes "it's okay"
unsetopt flow_control # Disable start/stop characters in shell editor.
unsetopt menu_complete # Do not autoselect the first completion entry.
if [ "$SHLVL" -le 1 ] && [ "$TERM" = "${TERM#screen}" ] && [ "$TERM" = "${TERM#tmux}" ]; then
if (( $+commands[tmux] )); then
2019-06-05 16:51:30 -07:00
# create a new session called "what" or attach if it already exists
2019-06-05 20:53:38 -07:00
LANG="en_US.UTF-8" TZ=":/etc/localtime" tmux new -A -s what && 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
fi
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
function {
2021-07-29 00:37:35 -07:00
local a b
# combine everything matching "YES_ZSH" in ~/sh/ into ~/.sh,
# but only recompile the output if the sha1sum has changed.
2021-08-01 01:37:59 -07:00
[ -s ~/.sh.sha1 ] && read -r b _ < ~/.sh.sha1
2021-07-29 00:37:35 -07:00
( cd ~/sh \
&& print -l '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \
2021-07-29 00:37:35 -07:00
| cat - $(grep -lF 'YES_ZSH' *(.)) \
| tee ~/.sh \
) | sha1sum - \
| tee ~/.sh.sha1 \
2021-08-01 01:37:59 -07:00
| read -r a _
2021-07-29 00:37:35 -07:00
[ "$a" = "$b" ] && touch ~/.sh.zwc || zrecompile -p ~/.sh
2013-06-28 05:22:14 -07:00
}
dummy() { :; } ### @- return 0, ignoring arguments.
preload=dummy
2021-07-29 00:37:35 -07:00
. ~/.sh
unset preload
2013-06-28 05:22:14 -07:00
2021-07-29 00:37:35 -07:00
local fuzzy=`has fzy || print`
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.
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
}
for x (dirprev dirnext dirup dirview) zle -N $x
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
bindkey '^[[3~' delete-char # del
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
2019-06-05 16:08:55 -07:00
bindkey -s '^[[6;2~' '\a' # shift+PgDn, do nothing, already at bottom (tmux)
# these binds were meant to prevent erroneous inputs from
# inputting anything, but they don't work for some reason:
#bindkey -s '^[[3;5~' '\a' # ctrl+del
#bindkey -s '^[[5;5~' '\a' # ctrl+PgUp
#bindkey -s '^[[6;5~' '\a' # ctrl+PgDn
#bindkey -s '^[[5;6~' '\a' # ctrl+shift+PgUp
#bindkey -s '^[[6;6~' '\a' # ctrl+shift+PgDn
#bindkey -s '^[[2;3~' '\a' # alt+ins
#bindkey -s '^[[3;3~' '\a' # alt+del
#bindkey -s '^[[5;3~' '\a' # alt+PgUp
#bindkey -s '^[[6;3~' '\a' # alt+PgDn
#bindkey -s '^[[1;6q' '\a' # ctrl+shift+1
#bindkey -s '^[[1;6s' '\a' # ctrl+shift+3
#bindkey -s '^[[1;6t' '\a' # ctrl+shift+4
#bindkey -s '^[[1;6u' '\a' # ctrl+shift+5
#bindkey -s '^[[1;6w' '\a' # ctrl+shift+7
#bindkey -s '^[[1;6x' '\a' # ctrl+shift+8
#bindkey -s '^[[1;6y' '\a' # ctrl+shift+9
#bindkey -s '^[[1;6l' '\a' # ctrl+shift+comma
#bindkey -s '^[[1;6n' '\a' # ctrl+shift+period
#bindkey -s '^[[1;7A' '\a' # ctrl+alt+arrow
#bindkey -s '^[[1;7B' '\a' # ctrl+alt+arrow
#bindkey -s '^[[1;7C' '\a' # ctrl+alt+arrow
#bindkey -s '^[[1;7D' '\a' # ctrl+alt+arrow
#bindkey -s '^[[1;8A' '\a' # ctrl+alt+shift+arrow
#bindkey -s '^[[1;8B' '\a' # ctrl+alt+shift+arrow
#bindkey -s '^[[1;8C' '\a' # ctrl+alt+shift+arrow
#bindkey -s '^[[1;8D' '\a' # ctrl+alt+shift+arrow
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
2014-03-14 17:04:46 -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.
alias -g WHOA='${whoa[@]}' ### @ WHOA - expand to several C/C++ flags to ease development.
alias -g WELP='${welp[@]}' ### @ WELP - expand to C++ flags to enable a C++-as-C facade.
2013-06-28 05:22:14 -07:00
2017-02-24 15:23:26 -08:00
alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path
2021-07-30 17:57:08 -07:00
# not in -shrc because this only makes sense with zsh:
alias pl="print -l" ### @ pl - print each argument on its own line.
2017-01-30 15:36:23 -08:00
2021-07-30 17:57:08 -07:00
# needs the "function" keyword or else zsh complains:
2021-07-30 18:14:05 -07:00
function tw() { ### @-
2021-07-30 17:57:08 -07:00
### invoke `twitch` as a job with both stdout and stderr silenced.
2017-08-04 20:41:49 -07:00
twitch "$@" OMFG STFU &
}
2021-07-29 00:37:35 -07:00
local host="${(L)HOST}"
2019-12-27 16:00:29 -08:00
2015-04-06 17:10:48 -07:00
function {
2021-07-30 17:57:08 -07:00
# initialize prompts.
2019-06-13 03:48:02 -07:00
local t="${TERM%%-*}"
if [ "$t" = xterm ] || [ "$t" = screen ] || [ "$t" = tmux ]; then
# set window title
if [ "$t" = tmux ]; then
# don't include host, tmux prepends it
precmd() { print -Pn "\e]2;%~\a" }
else
precmd() { print -Pn "\e]2;%M: %~\a" }
fi
else
# act dumb
precmd() {}
2019-06-05 16:52:02 -07:00
PROMPT="%# "
return
fi
# 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.
local s=$'\x1B\x5B' # start escape code
local e=m # end escape code
local reset="${s}0${e}"
local good=42 # green
local bad=41 # red
2021-07-29 00:37:35 -07:00
[ "$host" = neobanshee ] && good=46 # cyan
[ "$host" = spectre ] && good=47 # white
[ "$host" = wraith ] && good=43 # yellow
[ "$host" = sabotage ] && good=45 # magenta
2019-06-05 16:52:02 -07:00
# NOTE: i had ${s}10${e} here before, is it still necessary?
PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}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}" "$@"
return $?
fi
2019-05-30 01:25:49 -07:00
# this doesn't seem to help with _vim_files errors, eh.
# you wanna rm .zcompdump first, then exit. that's why!
2013-07-01 18:05:17 -07:00
cd ~
2021-07-29 00:37:35 -07:00
if [ $? -eq 0 ]; then
[ -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
2021-07-29 00:37:35 -07:00
#zmodload zsh/complist # need all this
#autoload -Uz compinit && compinit # just for compdef
#compdef wat=which
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=
< ~/.ls_colors | tr -d $'\r' | while read -r line; do
lsc+="$line:"
done
export LS_COLORS="$lsc"
}
for x in ack cd cp ebuild gcc gist grep ln man mkdir mv rm
alias $x="nocorrect $x"
for x in ai arith curl fc find ftp hex history let locate rsync scp sftp tw twitch wget youtube-dl yt ytg
alias $x="noglob $x"
unset x
2021-07-29 00:37:35 -07:00
. ~/.prezto-compinit
[ -e ~/.lol ] && . ~/.lol || touch ~/.lol