config

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

commit 40a93a63a38d6e1991dbba2f4db56dab34900f95
parent 568846730636e289f58841433a241109814eaf65
Author: Jacob R. Edwards <n/a>
Date:   Tue, 29 Nov 2022 17:45:03 -0600

Fix the buf script's show command's summmary

It's suppost to display only one line, appending ' [...]' if there
are more. But in the previous version, with only one line, nothing
would be displayed.

Diffstat:
Mlocal/bin/bin/buf | 29++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/local/bin/bin/buf b/local/bin/bin/buf @@ -9,16 +9,19 @@ # # name (get|set) sh(1) command to get or set # -# A caveat to external buffers is that they cannot be dynamic. For -# example, tmux maintains multiple buffers, yet only the default -# one can reasonably be used with this script. This COULD and MAY -# be changed in the future. # If no buffer is specified, $XDG_CONFIG_HOME/bufs/default is # read to determine the default buffer to use. # There is currently no way of removing buffers (since I would # only implement it for internal buffers, I'm not sure I want to # add the feature). +# ____--___-___---__--_---_--_---_------_--________-----__--______--------_ +# The idea is to give arguments to the shell fragment in $config/external, +# each one being a further restriction (for example tmux could be +# 'tmux show-buffer -b "$1"', and running tmux/buffer1 would set +# $1 to buffer1. +# --------______----_____----__________----------______---__----_------____--- + bufs=/tmp/bufs/$(id -u) config="${XDG_CONFIG_HOME:-"$HOME"/.config}"/buf @@ -52,19 +55,21 @@ external() { }' < "$config"/external } -getbuf() { +getbuf() ( + IFS=/ cat "$bufs/$1" 2>/dev/null || - sh -c "$(external get "$1")" -} + sh -c "$(external get "$1")" "$@" +) -setbuf() { +setbuf() ( if set="$(external set "$1" 2>/dev/null)" then - sh -c "$set" + IFS=/ + sh -c "$set" "$@" else cat > "$bufs/$1" fi -} +) swap() { swap="$(mktemp "$bufs"/swapXXXXXX)" @@ -79,6 +84,8 @@ swap() { default() cat "$config"/default +summerize() awk 'NR>1{printf " [...]"; exit}{printf "%s", $0}END{printf "\n"}' + set -eu mkdir -p "$bufs" @@ -90,7 +97,7 @@ case "$#$com" in ([01]brief|[01]show) for buf in $(buffers "$@") do - echo "$buf" = "$(getbuf "$buf" | sed -n '1h; 2{ g; s/$/ [...]/p; q; }')" + echo "$buf" = "$(getbuf "$buf" | summerize)" done ;; ([01]get)