2019-06-05 16:10:43 -07:00
|
|
|
[ -e /etc/profile ] && emulate sh -c "source /etc/profile"
|
2019-06-13 03:48:02 -07:00
|
|
|
|
|
|
|
if [ "$SHLVL" -le 1 ] && [[ "$TERM" != screen* ]] && [[ "$TERM" != tmux* ]]
|
|
|
|
then
|
2019-06-05 16:10:03 -07:00
|
|
|
if which tmux >/dev/null 2>/dev/null; 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
|
2019-06-05 16:10:03 -07:00
|
|
|
echo "tmux died ($?), continuing..."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-06-08 01:46:40 -07:00
|
|
|
setopt extended_glob # required for various scripts in this file and otherwise
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2019-05-30 01:23:57 -07:00
|
|
|
local host="${(L)HOST}"
|
2013-06-28 05:22:14 -07:00
|
|
|
fpath=(~/sh $fpath)
|
|
|
|
|
|
|
|
function {
|
|
|
|
local f
|
|
|
|
for f in ~/sh/^([_.]*)(N^/:t); do
|
2019-05-30 01:23:57 -07:00
|
|
|
if [[ "$f" == fasd ]]; then
|
|
|
|
emulate sh -c "autoload -U $f"
|
|
|
|
else
|
|
|
|
autoload -Uz $f
|
|
|
|
fi
|
2013-06-28 05:22:14 -07:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
HISTFILE=~/.histfile
|
2017-08-04 20:41:36 -07:00
|
|
|
HISTSIZE=99999
|
|
|
|
SAVEHIST=99999
|
2013-06-28 05:22:14 -07:00
|
|
|
|
|
|
|
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
|
2014-11-12 20:36:15 -08:00
|
|
|
hist_ignore_space # don't push lines beginning with spaces
|
2013-06-28 05:22:14 -07:00
|
|
|
auto_cd # exec a dir to cd
|
2013-07-09 20:27:19 -07:00
|
|
|
auto_pushd # cd acts as pushd
|
2013-06-28 05:22:14 -07:00
|
|
|
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"
|
2013-07-01 02:22:36 -07:00
|
|
|
brace_ccl # for character ranges like {a-z}
|
2014-11-12 20:36:15 -08:00
|
|
|
ksh_typeset # treat `local x=$(cmd)` and `x=$(cmd)` the same
|
2013-06-28 05:22:14 -07:00
|
|
|
)
|
|
|
|
setopt "${opts[@]}"
|
|
|
|
}
|
|
|
|
|
2014-03-30 23:46:55 -07:00
|
|
|
autoload -U zmv
|
|
|
|
|
2013-11-06 01:17:04 -08:00
|
|
|
zmodload zsh/mathfunc
|
|
|
|
autoload -Uz zcalc
|
|
|
|
|
2013-07-09 20:27:19 -07:00
|
|
|
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
|
|
|
|
|
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/
|
|
|
|
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
|
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 '^[[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)
|
|
|
|
|
2021-01-12 16:40:03 -08:00
|
|
|
# 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
|
|
|
autoload edit-command-line
|
|
|
|
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
|
|
|
|
2015-04-06 12:12:06 -07:00
|
|
|
alias -g OMFG="1>/dev/null"
|
2013-06-28 05:22:14 -07:00
|
|
|
alias -g STFU="2>/dev/null"
|
2016-08-27 23:45:42 -07:00
|
|
|
alias -g WHOA='${whoa[@]}'
|
2017-05-03 01:45:46 -07:00
|
|
|
alias -g WELP='${welp[@]}'
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2016-10-10 08:40:26 -07:00
|
|
|
wipe() {
|
|
|
|
clear
|
|
|
|
clear # twice because mintty is weird
|
|
|
|
echo "\e[30m\e[107m"
|
|
|
|
printf "*%.0s" {1..$COLUMNS}
|
|
|
|
echo "\e[0m\n"
|
|
|
|
}
|
2016-09-12 02:17:35 -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
|
|
|
|
alias pl="print -l" # not in -shrc because this only makes sense with zsh
|
2017-01-30 15:36:23 -08:00
|
|
|
|
2021-07-04 05:13:18 -07:00
|
|
|
function tw() { # needs the "function" keyword or else zsh complains
|
2017-08-04 20:41:49 -07:00
|
|
|
twitch "$@" OMFG STFU &
|
|
|
|
}
|
|
|
|
|
2019-12-27 16:00:29 -08:00
|
|
|
sum() {
|
|
|
|
local sum=0
|
|
|
|
for i; do
|
|
|
|
sum=$((sum+i))
|
|
|
|
done
|
|
|
|
echo "$sum"
|
|
|
|
}
|
|
|
|
|
2015-04-06 17:10:48 -07:00
|
|
|
function {
|
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
|
|
|
|
|
|
|
|
[[ "$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%} "
|
2015-04-06 17:10:48 -07:00
|
|
|
}
|
2013-06-28 05:22:14 -07:00
|
|
|
|
2019-06-05 12:35:42 -07:00
|
|
|
TIMEFMT=$'\e[93m%*U/%*E cpu/real (%P), %MM mem:\e[36m %J\e[0m'
|
|
|
|
|
2013-06-28 05:22:14 -07:00
|
|
|
reload() {
|
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 ~
|
|
|
|
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
|
2013-06-28 05:22:14 -07:00
|
|
|
}
|
2013-06-29 11:47:01 -07:00
|
|
|
|
2019-05-30 01:23:57 -07:00
|
|
|
if [[ "$host" == "spectre" ]] || [[ "$host" == *"banshee" ]]; then
|
|
|
|
# via https://github.com/whjvenyl/fasd
|
2020-07-24 02:43:34 -07:00
|
|
|
# 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"
|
2019-05-30 01:23:57 -07:00
|
|
|
fi
|
2019-06-08 01:46:40 -07:00
|
|
|
|
2021-07-21 15:30:05 -07:00
|
|
|
baknow() { cp -ip "$1" "$1.$(now "$1").bak"; }
|
|
|
|
|
|
|
|
ff() { find "${1:-.}" -type f | fzy }
|
|
|
|
|
|
|
|
cutv() {
|
|
|
|
local nel="${1?missing length parameter}"
|
|
|
|
local f="${2?missing file parameter}"
|
|
|
|
local g="cut."${${f##*/}%.*}".mp4"
|
|
|
|
ffmpeg -hide_banner -i "$f" 2>&1 \
|
|
|
|
| grep Duration \
|
|
|
|
| grep -Eo '[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]' | awk -F: '{print (($1*60+$2)*60+$3)+$4/100}' | read len
|
|
|
|
[[ "$len" -gt 0 ]] || return 1
|
|
|
|
echo "$g"
|
|
|
|
ffmpeg \
|
|
|
|
-hide_banner -loglevel warning -stats -stats_period 5 \
|
|
|
|
-i "$f" -ss "$(((nel<len)*(len-nel)))" \
|
|
|
|
-sn -dn -metadata = -map_chapters -1 -movflags +faststart \
|
|
|
|
-ar 44100 -acodec libfdk_aac -b:a 256k -cutoff 20000 -af alimiter=level_in=2.5:level_out=0.9 \
|
|
|
|
-maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720 \
|
|
|
|
-threads 2 -y "$g" || return 1
|
|
|
|
# -maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720
|
|
|
|
# -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
local lsc= line=
|
|
|
|
< ~/.ls_colors | tr -d $'\r' | while read -r line; do
|
|
|
|
lsc+="$line:"
|
|
|
|
done
|
|
|
|
export LS_COLORS="$lsc"
|
|
|
|
}
|
2019-06-08 01:46:40 -07:00
|
|
|
|
2021-07-04 05:08:52 -07:00
|
|
|
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
|
|
|
|
|
2019-06-08 01:46:40 -07:00
|
|
|
source ~/.prezto-compinit
|