config

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

commit d3df727d6d85944e9edb11071f924a73964f28a5
parent 264d503d94f00898e1f5f15eaecff98f011bf890
Author: Jacob R. Edwards <n/a>
Date:   Mon,  5 Dec 2022 17:43:57 -0600

Add history limiting option to xinput

While it now requires basic argument parsing, I believe it's a
feature very important to have, and not only does it allow limiting
history, but it allows setting a name (prompt) without recording
history (by setting the limit to 0).

Diffstat:
Mlocal/bin/bin/xinput | 44++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/local/bin/bin/xinput b/local/bin/bin/xinput @@ -1,7 +1,6 @@ #!/bin/sh # Copyright 2022 Jacob R. Edwards -# Get keyboard input through X, using dmenu, with history. -# usage: xinput name +# Get keyboard input through X using dmenu with history files xgetroot() { xwininfo -root | sed -En '/^xwininfo/ { @@ -9,15 +8,40 @@ xgetroot() { q }' } -dmenu() command dmenu -w $(xdotool getactivewindow 2>/dev/null || xgetroot) "$@" -data="${XDG_DATA_HOME:-"$HOME"/.share}"/xinput -if test $# -le 0; then +dmenu() { + command dmenu ${name:+-p "$name"} \ + -w $(xdotool getactivewindow 2>/dev/null || xgetroot) "$@" +} + +die() { + echo "$1" 1>&2 + exit 1 +} + +case "$1" in +(-l) + test "${2:?-l requires an argument}" -ge 0 || + die 'error: -l requires positive integer' + limit="$2" + shift 2 ;; +(-*) + die "usage: xinput [-l limit] name +$1: Invalid option" +esac + +datadir="${XDG_DATA_HOME:-"$HOME"/.share}"/xinput +name="$1" +file="$datadir"/"$name" + +if test "${limit:-1}" -eq 0 -o '!' "$name"; then dmenu < /dev/null else - name="$1" - mkdir -p "$data" - : >> "$data"/"$name" - awk '{x[NR]=$0}END{for(i=NR;i>0;--i)print(x[i])}' < "$data"/"$name" | - dmenu -p "$name" | tee -a "$data"/"$name" + mkdir -p "$datadir" + : >> "$file" + input="$(dmenu < "$file")" || + exit 1 + echo "$input" | sed "${limit:+${limit}q}" /dev/stdin "$file" | + bwrite "$file" + echo "$input" fi