config

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

commit e371bfddee630f242313e6d36d5c541c2e4af78a
parent b00b720b0d23cdcc978729b8ea254e740ce86d1e
Author: Jacob R. Edwards <n/a>
Date:   Sun,  4 Dec 2022 20:50:37 -0600

Add a read mode to the tag script

When in this mode, it will display the contents of the given tagfiles
instead of append names from the standard input to them.

Diffstat:
Mlocal/bin/bin/tag | 64++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 44 insertions(+), 20 deletions(-)

diff --git a/local/bin/bin/tag b/local/bin/bin/tag @@ -2,19 +2,23 @@ # Copyright 2022 Jacob R. Edwards # Filesystem tagging system # -# Each name from the standard input (made relative the current -# directory or base (set with -b)) is appended to the given tagfiles -# if they don't contain them already. Tagfiles are paths relative -# to the current directory unless a tag directory is given (-t). +# In write mode, each name from the standard input (made relative to +# the current directory or base (set with -b)) is appended to the +# given tagfiles if they don't contain them already. Tagfiles are +# paths relative to the current directory unless a tag directory is +# given (-t). # -# In automatic mode (-a), both the tag and base directories are -# filled in automatically. To find the tag directory, the directory -# 'tags' is recursively searched for in each parent directory. The -# base directory is generated by getting the parent directory of the -# tags directory. +# Given the automatic flag (-a), the script attempts to resolve the +# tags and base directories if they are not set. If base is defined, +# tags is gotten using that--otherwise the 'tags' directory is searched +# for in every parent directory of the current directory. The base +# is generated by getting the dirname(1) of the tags directory. # -# Raw mode (-r) does not alter input in any way and is suitable for -# tagging things other than files. +# In raw mode (-r), the tagged information is not altered in any way +# and is suitable for tagging things other than files. +# +# In read mode (-p), names are not read from the standard input and +# instead the given tagfiles are printed. error() { echo "error: $1" 1>&2 @@ -25,7 +29,7 @@ usage() { { test $# -gt 0 && echo "error: $1" - echo 'usage: tag [-ar] [-b base] [-t tags] tagfile [...]' + echo 'usage: tag [-arp] [-b base] [-t tags] tagfile [...]' } 1>&2 exit 1 } @@ -41,22 +45,33 @@ findtags() { echo "$dir"/tags } +base() ( + test "$base" && + cd "$base" + "$@" +) + rebase() ( - root | (test "$base" && cd "$base"; unroot) | awk '{ + root | base unroot | awk '{ if (/^\//) printf "Unable to rebase '%s' (passing as is)\n", $0 > "/dev/stderr" print }' ) -add() ( +tags() ( test "$tags" && - cd "$tags" - addnotin "$@" + cd "$tags" + "$@" ) +add() { + tags addnotin "$@" +} + auto=false raw=false +read=false while test $# -gt 0 do case "$1" in @@ -64,6 +79,8 @@ do auto=true ;; (-r) raw=true ;; + (-p) + read=true ;; (-b) base="$2" shift ;; @@ -99,9 +116,16 @@ then base="$(dirname "$tags")" fi -if $raw -then - add "$@" +if $read; then + if $raw; then + tags cat "$@" + else + tags cat "$@" | base root + fi else - rebase | add "$@" + if $raw; then + add "$@" + else + rebase | add "$@" + fi fi