dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 8aede9331b39404dc728a3b9d5261383061422db
parent 3301d035289760a4ed264e4a943479293eb21d90
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 10 Jun 2020 09:38:47 +0200

Remove version option and fix read from stdin

Diffstat:
M.local/bin/plumb | 40++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -1,29 +1,20 @@ #!/bin/sh -version=0.1 calendar="$HOME/.calendar/calendar" prefix="" show_help() { - echo "usage: ${0##*/} [OPTIONS] [FILE|URL]" - echo "will open FILE or URL" - echo "If no FILE or URL is specified, this program will expect them as stdin." + printf "usage: %s [OPTIONS] [FILE|URL ..]" "${0##*/}" + echo "will open FILE or URL." + echo "If no FILE or URL is specified, they are expected as stdin." echo echo "OPTIONS are one or more of the following:" echo " -h show this message" - echo " -v show version and license information" + echo " -v show verbose information" echo " -w do not end program before child processes are finished" - echo " -V show verbose information" echo " -- do not consider any following args as options" } -show_version() { - echo "${0##*/} version $version" - echo "Licensed under the ISC License" - echo "written by Anders Damsgaard, anders@adamsgaard.dk" - echo "https://src.adamsgaard.dk/dotfiles" -} - die() { printf 'error: %s\n' "$1" >&2 exit 1 @@ -120,10 +111,19 @@ handle_calendar_invite() { handle_target() { t="$1" + if [ "$verbose" = 1 ]; then + printf 'target: %s\n' "$t" + fi if [ -d "$t" ]; then + if [ "$verbose" = 1 ]; then + printf 'target is a directory\n' + fi termopen cd $t; $SHELL elif [ -e "$t" ]; then mime_type="$(file -ib "$t")" + if [ "$verbose" = 1 ]; then + printf 'target is a file with mime type "%s"\n' "$mime_type" + fi case "$mime_type" in image/svg*) detach inkscape "$t";; @@ -159,10 +159,11 @@ handle_target() { *) die "file type $mime_type is not supported" esac - exit $? - else + if [ "$verbose" = 1 ]; then + printf 'target is not a file\n' + fi if regeximatch "$t" "\.onion"; then prefix=torsocks else @@ -242,10 +243,6 @@ while :; do exit 0 ;; -v) - show_version - exit 0 - ;; - -V) verbose=1 ;; -w) @@ -265,10 +262,9 @@ while :; do done if [ $# -lt 1 ]; then - targets="$(cat)" - for f in "$targets"; do + while IFS='' read -r f || [ -n "$f" ]; do handle_target "$f" - done + done < "${1:-/dev/stdin}" else for f in "$@"; do handle_target "$f"