config

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

commit cf8b6714654dbc40cbc877abd3ea66a1c138c582
parent c79f483bef8bd155f94dec1bf284b67c89081d09
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Mon,  5 Apr 2021 20:12:09 -0700

Make the bwrite shell function into a script

It's a little too complex for the shell functions; they should be
trivial.

Diffstat:
Alocal/bin/.local/bin/bwrite | 18++++++++++++++++++
Mlocal/shell/.local/share/shell/etc | 5-----
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/local/bin/.local/bin/bwrite b/local/bin/.local/bin/bwrite @@ -0,0 +1,18 @@ +#!/bin/sh -e +# Copyright 2021 Jacob R. Edwards +# License: GPLv3 +# +# bwrite -- buffered write +# +# The bwrite utility copies all it's input into a temporary file +# before moving it to the destination file. In this way you may +# easily replace the contents of a file with a processed varient +# such as in sh(1) with the following which adds 1 to each line: +# +# $ awk '{ print ++$0 }' <x | bwrite x + +dir="$(basename "$@")" +tmp="$(mktemp "$dir/bwrite-XXXXXXXXXX")" +trap "rm -f $tmp" 0 +cat >"$tmp" +mv "$tmp" "$@" diff --git a/local/shell/.local/share/shell/etc b/local/shell/.local/share/shell/etc @@ -1,8 +1,3 @@ # shell functions fed() (cd "${XDG_DATA_HOME:-$HOME/.local/share}/feed" && feed "$@") -bwrite() ( - tmp="$(mktemp "$(dirname "$1")/bwrite-XXXXXXXXXX")" - cat >"$tmp" - mv "$tmp" "$1" -)