mirror of
https://github.com/notwa/rc
synced 2024-11-05 06:39:02 -08:00
214 lines
7.4 KiB
Bash
214 lines
7.4 KiB
Bash
[ -e /etc/profile ] && emulate sh -c "source /etc/profile"
|
|
|
|
if [ "$SHLVL" -le 1 ] && [[ "$TERM" != screen* ]] && [[ "$TERM" != tmux* ]]
|
|
then
|
|
if which tmux >/dev/null 2>/dev/null; then
|
|
# create a new session called "what" or attach if it already exists
|
|
LANG="en_US.UTF-8" TZ=":/etc/localtime" tmux new -A -s what && exit
|
|
echo "tmux died ($?), continuing..."
|
|
fi
|
|
fi
|
|
|
|
setopt extended_glob # required for various scripts in this file and otherwise
|
|
|
|
local host="${(L)HOST}"
|
|
fpath=(~/sh $fpath)
|
|
|
|
function {
|
|
local f
|
|
for f in ~/sh/^([_.]*)(N^/:t); do
|
|
if [[ "$f" == fasd ]]; then
|
|
emulate sh -c "autoload -U $f"
|
|
else
|
|
autoload -Uz $f
|
|
fi
|
|
done
|
|
}
|
|
|
|
HISTFILE=~/.histfile
|
|
HISTSIZE=99999
|
|
SAVEHIST=99999
|
|
|
|
function {
|
|
local -a opts
|
|
opts=( no_beep
|
|
append_history share_history # across sessions
|
|
hist_expire_dups_first # sharing/appending will result in dups
|
|
hist_ignore_dups # don't push lines identical to the previous
|
|
hist_ignore_space # don't push lines beginning with spaces
|
|
auto_cd # exec a dir to cd
|
|
auto_pushd # cd acts as pushd
|
|
no_match # error on bad tab-complete
|
|
check_jobs notify # automatic job reporting
|
|
chase_links # cd into link resolves link
|
|
complete_aliases # allow original command completion within alias
|
|
complete_in_word # enable tab completion when cursor between words
|
|
rc_quotes # 'you''re dumb' like "you're dumb"
|
|
brace_ccl # for character ranges like {a-z}
|
|
ksh_typeset # treat `local x=$(cmd)` and `x=$(cmd)` the same
|
|
)
|
|
setopt "${opts[@]}"
|
|
}
|
|
|
|
autoload -U zmv
|
|
|
|
zmodload zsh/mathfunc
|
|
autoload -Uz zcalc
|
|
|
|
DIRSTACKSIZE=24
|
|
dirprev() {
|
|
pushd -q +1
|
|
zle reset-prompt
|
|
precmd
|
|
}
|
|
dirnext() {
|
|
pushd -q -0
|
|
zle reset-prompt
|
|
precmd
|
|
}
|
|
dirup() {
|
|
cd ..
|
|
zle reset-prompt
|
|
precmd
|
|
}
|
|
dirview() {
|
|
# TODO: print under prompt if possible,
|
|
# truncate and columnize
|
|
print
|
|
dirs -v
|
|
zle reset-prompt
|
|
}
|
|
|
|
for x (dirprev dirnext dirup dirview) zle -N $x
|
|
|
|
bindkey -e # emacs-style keybinds
|
|
|
|
# oh thank god: http://blog.samsonis.me/2013/12/bash-like-history-search-functionality-for-zsh/
|
|
autoload history-search-end
|
|
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
|
|
bindkey '^[OA' history-beginning-search-backward-end # up
|
|
bindkey '^[OB' history-beginning-search-forward-end # down
|
|
|
|
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
|
|
bindkey -s '^[s' '^Asudo ^E' # alt+s
|
|
|
|
bindkey -s '^[[6;2~' '\a' # shift+PgDn, do nothing, already at bottom (tmux)
|
|
|
|
autoload edit-command-line
|
|
zle -N edit-command-line # new widget of the same function name
|
|
bindkey '^Xe' edit-command-line # ctrl+x -> e
|
|
|
|
. ~/.-shrc
|
|
|
|
alias -g OMFG="1>/dev/null"
|
|
alias -g STFU="2>/dev/null"
|
|
alias -g WHOA='${whoa[@]}'
|
|
alias -g WELP='${welp[@]}'
|
|
|
|
wipe() {
|
|
clear
|
|
clear # twice because mintty is weird
|
|
echo "\e[30m\e[107m"
|
|
printf "*%.0s" {1..$COLUMNS}
|
|
echo "\e[0m\n"
|
|
}
|
|
|
|
for x in ack cd cp ebuild gcc gist grep ln man mkdir mv rm
|
|
alias $x="nocorrect $x"
|
|
for x in arith hex curl fc find ftp history let locate rsync scp sftp wget twitch yt ytg ai
|
|
alias $x="noglob $x"
|
|
unset x
|
|
|
|
alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path
|
|
alias pl="print -l" # not in -shrc because this only makes sense with zsh
|
|
|
|
tw() {
|
|
twitch "$@" OMFG STFU &
|
|
}
|
|
|
|
sum() {
|
|
local sum=0
|
|
for i; do
|
|
sum=$((sum+i))
|
|
done
|
|
echo "$sum"
|
|
}
|
|
|
|
function {
|
|
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() {}
|
|
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
|
|
|
|
[[ "$host" == neobanshee ]] && good=46 # cyan
|
|
[[ "$host" == spectre ]] && good=47 # white
|
|
[[ "$host" == wraith ]] && good=43 # yellow
|
|
[[ "$host" == sabotage ]] && good=45 # magenta
|
|
|
|
# NOTE: i had ${s}10${e} here before, is it still necessary?
|
|
PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}97${e}%}%#%{$reset%} "
|
|
}
|
|
|
|
TIMEFMT=$'\e[93m%*U/%*E cpu/real (%P), %MM mem:\e[36m %J\e[0m'
|
|
|
|
reload() {
|
|
# this doesn't seem to help with _vim_files errors, eh.
|
|
# you wanna rm .zcompdump first, then exit. that's why!
|
|
cd ~
|
|
autoload -U zrecompile
|
|
[ -f .zshrc ] && zrecompile -p .zshrc
|
|
rm -f .zcompdump
|
|
[ -f .zshrc.zwc.old ] && rm -f .zshrc.zwc.old
|
|
[ -f .zcompdump.zwc.old ] && rm -f .zcompdump.zwc.old
|
|
exec zsh # reload shell, inheriting environment
|
|
}
|
|
|
|
if [[ "$host" == "spectre" ]] || [[ "$host" == *"banshee" ]]; then
|
|
# via https://github.com/whjvenyl/fasd
|
|
# if [ ! -s "$HOME/.fasd_init" ]; then
|
|
# # note that posix-alias defines aliases for the following:
|
|
# # a s d f sd sf z zz
|
|
# fasd --init \
|
|
# posix-alias \
|
|
# zsh-hook zsh-ccomp zsh-ccomp-install \
|
|
# zsh-wcomp zsh-wcomp-install \
|
|
# >| "$HOME/.fasd_init"
|
|
# fi
|
|
# source "$HOME/.fasd_init"
|
|
# alias v="f -e $EDITOR"
|
|
fi
|
|
|
|
# generated by dircolors:
|
|
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
|
|
|
|
source ~/.prezto-compinit
|