commit ee751ac304de54ea70b2873323eabdcb4cf2fed4 parent ff8c908802da2e76cdb161f6a47c260e4d9c9838 Author: Jacob R. Edwards <jacobouno@protonmail.com> Date: Tue, 20 Jul 2021 21:55:36 -0700 Output input verbatim if no shortcut matches in urls script Also rewrite in sh(1) (no need for -o pipefail). Diffstat:
| M | local/bin/.local/bin/urls | | | 29 | +++++++++++++---------------- |
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/local/bin/.local/bin/urls b/local/bin/.local/bin/urls @@ -1,24 +1,21 @@ -#!/bin/ksh -eu +#!/bin/sh # Copyright 2021 Jacob R. Edwards # License: GPLv3 # # urls -- url shortcut -set -o pipefail - -s="$1" - -get() { - grep -m1 "^$s " <"${XDG_CONFIG_HOME:-$HOME/.config}/urls" | cut -f2 +shortcut() { + grep -m1 "^$1 " <"${XDG_CONFIG_HOME:-$HOME/.config}/urls" | cut -f2 } -insert() ( - query=$(echo $* | sed -e 's/ /%20/g' -e 's_/_\\/_g') - sed "s/%/$query/g" -) - -shift -get "$s" | insert "$@" || { - printf 'urls: %s: Shortcut not found.\n' "$s" 1>&2 - exit 1 +insert() { + sed "s/%/$(echo $* | sed -e 's/ /%20/g' -e 's_/_\\/_g')/g" } + +format="$(shortcut "$1")" +if test -z "$format"; then + echo "$@" +else + shift + echo "$format" | insert "$@" +fi