dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

.zshrc.local (9057B)


      1## completion
      2source ~/.local/share/zsh/site-functions/_trt && compdef _trt trt
      3
      4## alias
      5alias sv="doas /usr/bin/sv"
      6alias vsv="doas /usr/bin/vsv"
      7alias gpg="/usr/bin/gpg2"
      8alias speak="/usr/bin/trans -b -speak -no-translate -no-init"
      9alias zh-TW="/usr/bin/trans -shell -brief -theme random :zh-TW -no-init"
     10
     11## plugins
     12. /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
     13. /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
     14. /usr/share/zsh/site-functions/skim-key-bindings.zsh
     15#. $HOME/.local/share/grc/grc.zsh
     16
     17if [ ! -z ${DISPLAY+x} ] ; then
     18	. /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme
     19	. $HOME/.p10k.zsh
     20        POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir rbenv vcs)
     21	ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=240'
     22	#ZSH_HIGHLIGHT_STYLES[suffix-alias]='fg=blue,underline'
     23	#ZSH_HIGHLIGHT_STYLES[precommand]='fg=blue,underline'
     24	#ZSH_HIGHLIGHT_STYLES[arg0]='fg=blue'
     25	#ZSH_HIGHLIGHT_STYLES[comment]='fg=239'
     26	ZSH_HIGHLIGHT_STYLES[suffix-alias]=fg=32,underline
     27	ZSH_HIGHLIGHT_STYLES[precommand]=fg=32,underline
     28	ZSH_HIGHLIGHT_STYLES[arg0]=fg=32 # 26
     29	ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=38'
     30	ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=38'
     31	ZSH_HIGHLIGHT_STYLES[default]='fg=38'
     32	ZSH_HIGHLIGHT_STYLES[single-quoted-argument-unclosed]='fg=red'
     33	ZSH_HIGHLIGHT_STYLES[double-quoted-argument-unclosed]='fg=red'
     34fi
     35
     36## functions
     37# speedtest
     38speedtest-socks-connection() {
     39	local URL="https://www.google.com/generate_204"
     40	echo 'http_code\ttime_appconnect\ttime_connect\ttime_namelookup\ttime_total'
     41	repeat 12 curl \
     42		-x socks5h://127.0.0.1:1080 --output /dev/null --silent \
     43		--write-out '%{http_code}\t\t%{time_appconnect}\t%{time_connect}\t%{time_namelookup}\t%{time_total}\n' \
     44		$URL
     45}
     46speedtest-socks-speed() {
     47	curl \
     48		-x socks5h://127.0.0.1:1080 --silent \
     49		-o/dev/null --write-out '%{speed_download}' \
     50		http://speedtest-sgp1.digitalocean.com/10mb.test \
     51		| numfmt --to=iec-i --suffix=B/s
     52}
     53speedtest-connection() {
     54	#echo 'http_code\ttime_appconnect\ttime_connect\ttime_namelookup\ttime_total'
     55	#repeat 7 curl --output /dev/null --silent --write-out '%{http_code}\t\t%{time_appconnect}\t%{time_connect}\t%{time_namelookup}\t%{time_pretransfer}\t\t%{time_redirect}\t%{time_starttransfer}\t\t%{time_total}\n' https://connectivitycheck.gstatic.com/generate_204
     56	local time_seconds=$(curl -o/dev/null -sw '%{time_appconnect}' 'https://connectivitycheck.gstatic.com/generate_204')
     57	printf "%.0fms\n" $((time_seconds * 1000))
     58}
     59
     60# wordnet
     61wn() { while true; do dict -d wn $(read -e); done }
     62
     63# zsh-insulter
     64if [ -f /etc/zsh.command-not-found ]; then
     65	. /etc/zsh.command-not-found
     66fi
     67
     68# Xorg
     69x() { echo "which session?"; read && sx $HOME/.config/sx/sxrc $REPLY; }
     70
     71# memory usage
     72memu() {
     73	local CHECK=" $@"
     74	[ -z $1 ] || [ "${CHECK#* -}" != "$CHECK" ] && { echo "Usage: memu program [program...]"; return 1; }
     75	local PIDS=$(pidof "$@")
     76	test -z "$PIDS" && return 0
     77	echo "$PIDS" \
     78		| xargs -I{} ps -p "{}" -o size,vsize,rss,cmd \
     79		| awk 'NR==1; NR>1 {print $1"K", $2"Ki", $3"K", $4}' \
     80		| numfmt --header --field 1,3 --from=si --to=si --suffix=B --format %.1f \
     81		| numfmt --header --field 2 --from=iec-i --to=iec-i --suffix=B --format %.1f \
     82		| sort -hk3,3 \
     83		| column -t -R1,2,3 \
     84		| GREP_COLORS='mt=1;94' egrep --color=always '.*SIZE.*VSZ.*RSS.*CMD.*|$' \
     85		| GREP_COLORS='mt=1;32' egrep --color=always "KB|KiB|$" \
     86		| GREP_COLORS='mt=0;33' egrep --color=always 'MB|MiB|$' \
     87		| GREP_COLORS='mt=1;31' egrep --color=always "GB|GiB|$"
     88}
     89ps_mem() {
     90	doas /usr/bin/ps_mem "$@" \
     91		| GREP_COLORS='mt=1;32' egrep --color=auto --color=always "KB|KiB|$" \
     92		| GREP_COLORS='mt=0;33' egrep --color=auto --color=always 'MB|MiB|$' \
     93		| GREP_COLORS='mt=1;31' egrep --color=auto --color=always "GB|GiB|$"
     94}
     95smem() {
     96	doas /usr/bin/smem -k "$@" \
     97		| GREP_COLORS='mt=1;32' egrep --color=auto --color=always "K |$" \
     98		| GREP_COLORS='mt=0;33' egrep --color=auto --color=always 'M |$' \
     99		| GREP_COLORS='mt=1;31' egrep --color=auto --color=always "G |$"
    100}
    101
    102# morse code, base64
    103mbt() {
    104	echo "morse code base64 enc/dec"
    105	local NUM_OUTPUT_COLOR=$(shuf -n1 <(echo 3; seq 5 6))
    106	while true; do
    107		read input"?$(tput bold)$(tput setf 1)> $(tput sgr0)"
    108		if [ -z $input ]; then
    109			local OUTPUT=$(xclip -selection clipboard -o | base64 -d | morse -d)
    110			echo "$(tput setf $NUM_OUTPUT_COLOR)${OUTPUT}$(tput sgr0)"
    111		else
    112			local OUTPUT=$(echo "$input" | morse -e | base64 -w0)
    113			echo "$OUTPUT" | xclip -selection clipboard
    114			echo "$(tput setf 2)${OUTPUT}$(tput sgr0)"
    115		fi
    116	done
    117}
    118mat() {
    119	if [ -z "$1" ]; then
    120		echo "convert text into audio file with morse code"
    121		read input"?> "
    122		[ -z "$input" ] \
    123			&& { echo "NO INPUT"; return 0; } \
    124			|| echo $input \
    125			| cwwav -o/tmp/cw.wav -f650 -w20 2>/dev/null
    126		opusenc --quiet /tmp/cw.wav cw_$(date -u +%FT%TZ).opus \
    127			&& echo $_
    128	else
    129		[ ! -f "$1" ] \
    130			&& { echo "\"$1\" not found"; exit 0; } \
    131			|| sox $1 -esigned-integer -b16 -r 22050 -t raw - 2>/dev/null \
    132			| multimon-ng -q -t raw -a MORSE_CW -
    133	fi
    134	rm -f /tmp/cw.wav
    135}
    136
    137# xbps
    138#git -C ~/.cache/xlocate.git ls-tree --full-tree -r --name-only HEAD | rev | sed 's/_/ /; s/-/ /' | rev | column -t -R3 | sk --inline-info --layout=reverse-list --preview="git -C \"$HOME/.cache/xlocate.git\" show master:$(echo {1}-{2}_{3})" --preview-window=up:50% -m
    139fxls() {
    140	local HEADER="[Enter] Print selected [TAB] Toggle selection [ALT-F] View file [ALT-I] Info [ALT+H] Homepage"
    141	local REPO="$HOME/.cache/xlocate.git"
    142	git -C "$REPO" ls-tree --full-tree -r --name-only HEAD | rev | sed 's/_/ /; s/-/ /' | rev | column -t -R3 \
    143		| sk --inline-info \
    144			--prompt "pkg > " \
    145			--layout=reverse-list \
    146			--preview="git -C \"$REPO\" show master:$(echo {1}-{2}_{3})" \
    147			--preview-window=up:50% \
    148			-m \
    149			--bind "alt-f:execute[ git -C \"$REPO\" show master:$(echo {1}-{2}_{3}) | sk --layout=reverse-list --prompt '{1} > ' ]" \
    150			--bind "alt-i:execute[ xbps-query -v -R {1} | sk --layout=reverse-list --prompt '{1} > ' ]" \
    151			--bind 'alt-h:execute-silent[ xdg-open "$(xbps-query -p homepage -R {1})" & ]' \
    152			${1:+--query "$@"}
    153}
    154
    155# stagit viewer
    156sgview() {
    157	[ -z "$1" ] \
    158		&& local URL=$(read -e "?URL: ") \
    159		|| local URL=$1
    160	curl --progress-bar "$URL" \
    161		| sed -n 's|^<a href="#.*" class="line" id=".*">.*</a>||p' \
    162		| recode html..ascii \
    163		| bat -n
    164}
    165
    166# termbin, fiche
    167tb() {
    168	[ "$1" = "-i" ] && { local DATA=$(bash -i |& tee /dev/tty); echo "$DATA" | ansifilter | tb; return 0; }
    169	[ -z "$1" ] || { cat "$1" | tb; return 0; }
    170	zmodload zsh/net/tcp; ztcp ezup.dev 9999; cat >&$REPLY; cat <&$REPLY | tee >(xclip -selection clipboard); ztcp -c $REPLY
    171}
    172
    173# logpaste.com
    174logpaste() {
    175	[ -s "$1" ] && { curl -F "_=@$@" http://logpaste.com; return 0; }
    176	curl -F '_=<-' http://logpaste.com
    177}
    178
    179# gnuplot for lists of date in format of $(date +%F)
    180# sed -n 's/^: //p' ~/.zsh_history | cut -d: -f1 | xargs -L1 -I{} date +%F -d @{} | showplot
    181# xbps-query -m | xargs -L1 xbps-query -p install-date | awk '{print $1}' | showplot
    182# find ~/Downloads -type f 2>/dev/null | xargs -I{} stat -c %y '{}' 2>/dev/null | showplot
    183# tail -n+2 dump.csv | awk -F';' '{print $NF}' | showplot -c
    184showplot() {
    185	zmodload zsh/datetime
    186	local DATA=("${(@f)$(sort /dev/stdin)}")
    187	local PFDAY=$(date -u -d "${DATA[1]} -1 day" +%F) # previous day of the first day
    188	local NLDAY=$(date -u -d "${DATA[-1]} +1 day" +%F) # next day of the last day
    189	local FDATE="${FDATE:-$PFDAY}"
    190	local LDATE="${LDATE:-$NLDAY}"
    191	local DURATION=$(( ( $(strftime -r %Y-%m-%d $LDATE) - $(strftime -r %Y-%m-%d $FDATE) ) / 86400 ))
    192	case "$1" in
    193		"-x")	local TYPE="set terminal x11"										;;
    194		"-p")	local TYPE="set terminal png size 960,720"								;;
    195		"-d")	local TYPE="set terminal png size 960,720; set output '| feh -'"					;;
    196		"-c")	local TYPE="set terminal png size 960,720; set output '| xclip -selection clipboard -t image/png'"	;;
    197		*)	local TYPE="set terminal dumb size 150,45; set autoscale"						;;
    198	esac
    199	printf '%s\n' "${DATA[@]}" | uniq -c | awk '{print $2,$1}' | gnuplot -background white -p -e "
    200		$TYPE;
    201		set xdata time;
    202		set timefmt '%Y-%m-%d';
    203		set xrange ['$FDATE':'$LDATE'];
    204		plot '-' using 1:2 with lines title '${#DATA[@]} items | $FDATE + ${DURATION}d = $LDATE'
    205		"
    206}
    207
    208# https://unix.stackexchange.com/a/49066
    209zlibd() (printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - "$@" | gzip -dc)
    210
    211# Gentoo emerge history
    212mergelop() { qlop -c -M | sort -hrk2 | sed -r 's/:| average| for| merges| merge//g' | awk '$2 < 86400 { cmd = "date -u +%T -d@" $2; print $1, ((cmd | getline res)>0)? res : $2, $3; close(cmd) }' | column -t | sk --no-sort; }
    213
    214ocr() {
    215	grim -g "$(slurp)" - | tesseract - - 2>/dev/null
    216}
    217
    218day_of_week() {
    219	# https://stackoverflow.com/a/36389289/15763223
    220	rtc_timestamp=$(</sys/class/rtc/rtc0/since_epoch)
    221	rtc_date=$(</sys/class/rtc/rtc0/date)
    222	dow=$(((rtc_timestamp/86400+4)%7))
    223	week=(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
    224	echo "${rtc_date} ${week[@]:${dow}:1}"
    225}
    226
    227calculator() { while true; do bc <<<"scale=3; $(read -e)"; done }
    228
    229gtree() { git ls-files $1 | tree --fromfile }