config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 9712969be799967ddd4b2cc9475158d1268bb757
parent 6309bafbf435f3e8f449df03ac84d35a1dfebf5d
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed,  9 Sep 2020 20:26:20 -0700

Improve efficiency and structure

call programs once for each operation instead of once for each file.

Diffstat:
Msxiv/.config/sxiv/exec/key-handler | 44+++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/sxiv/.config/sxiv/exec/key-handler b/sxiv/.config/sxiv/exec/key-handler @@ -1,32 +1,38 @@ #!/usr/bin/env dash # sxiv key handler -set -e +set -eu +IFS=" +" + +err() { echo "`basename $0`: $*" 1>&2 ;} +out() { notify-send "$@"; echo "$@" ;} +load() { stdin="$(cat -)" ;} +last() { stdin="$(tail -n1 /dev/stdin)" ;} +#next() { read stdin ;} + +# yes(1) hangs the program. +mvnc() { while true; do echo n; done | mv -i $@ ;} -# confirm via dmenu if it hasn't been already. confirm() { - if [ -z $answer ]; then - answer=$(printf "no\nyes" | dmenu) && [ "$answer" = "yes" ] - fi + [ "`echo "no\nyes" | dmenu`" = "yes" ] && return 0; + return 1; } -# link image to wallpaper and invoke xwallpaper on it. -set_wallpaper() +setbg() { ln -f "$1" "$XDG_CONFIG_HOME/wallpaper" xwallpaper --zoom "$1" } -while read file; do - case "$1" - in - "C-w") set_wallpaper "$file";; - "C-m") [ -z "$dest" ] && dest=`fsmenu -td`; mv "$file" "$dest";; - "C-c") [ -z "$dest" ] && dest=`fsmenu -td`; cp "$file" "$dest";; - "C-x") confirm && rm "$file" || exit 2;; - *) echo "error: sxiv.key-handler: key unbound '$1'" 1>&2; exit 2;; - esac - notify-send "$1 $file" - echo "$1 $file" -done +case $1 +in + C-w) last; setbg $stdin;; + C-m) d=`fsmenu -td` || exit 1; load; mvnc $stdin $d;; + C-x) confirm || exit 1; load; rm $stdin;; + *) err "'$1': Keybind does not exist."; exit 1;; +esac + +stdin="$(echo "$stdin" | sed "s/^/$1: /")" +out "$stdin"