config

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

commit 943d79a221979f91e424ea7790564c41c37f21ad
parent bfc5f8dcbcc37748cc0a1e76e2912d21416278d2
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Tue, 29 Dec 2020 11:16:54 -0800

Use rc(1) for sxiv key-handler

Diffstat:
Mmodules/sxiv/.config/sxiv/exec/key-handler | 58+++++++++++++++++++++-------------------------------------
1 file changed, 21 insertions(+), 37 deletions(-)

diff --git a/modules/sxiv/.config/sxiv/exec/key-handler b/modules/sxiv/.config/sxiv/exec/key-handler @@ -1,43 +1,27 @@ -#!/usr/bin/env dash +#!/usr/local/bin/rc -e # sxiv key handler -set -eu -IFS=" -" +pn = `{ basename $0 } +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() -{ - [ "`echo "no\nyes" | dmenu`" = "yes" ] && return 0; - return 1; +fn warn { { printf '%s: ' $pn; printf $* } >[2=1] } +fn err { warn $*; exit 1 } +fn yes { test `{ printf 'n\ny\n' | dmenu } '=' 'y' } +fn cw { + f = $XDG_CONFIG_HOME^/wallpaper + cp -f $1 $f + bgs -z $f } -setbg() -{ - local f="${XDG_CONFIG_HOME:?unset}/wallpaper" - if [ "farbfeld" = `dd if=$1 bs=8 count=1 of=/dev/stdout 2>/dev/null` ]; then - ff2jpg < "$1" > "$f" - else - ln -f "$1" "$f" - fi - xwallpaper --zoom "$f" +buf = `{ cat - } +switch ($1) { +case 'C-w' + cw $buf($#buf); +case 'C-m' + mv $buf `{ fsmenu -t -d } +case 'C-x' + yes && rm $buf +case * + err '%s: Command does not exist.\n' $1; } - -case $1 -in - C-w) last; setbg $stdin;; - C-m) d=`fsmenu -t d` || 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"