commit 31c36d4b6f76ad203216e921b2887a0b5fcb5ad1 parent c1188490a85ebd2eb38465f27c7c1c6925da326d Author: Jacob R. Edwards <jacobouno@protonmail.com> Date: Mon, 13 Sep 2021 14:37:43 -0700 Revise url shortcut scripts - Now urls gives an error instead of echoing back the search when unable to find the shortcut. - Single quotes are now allowed with xurls as it no longer uses xargs(1) Diffstat:
| M | local/bin/bin/urls | | | 23 | +++++++++++++---------- |
| M | local/bin/bin/xurls | | | 2 | +- |
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/local/bin/bin/urls b/local/bin/bin/urls @@ -1,21 +1,24 @@ -#!/bin/sh +#!/bin/ksh # Copyright 2021 Jacob R. Edwards # License: GPLv3 # # urls -- url shortcut -shortcut() { +set -o pipefail + +error() { + echo "$1" 1>&2 + exit 1 +} + +find() { grep -m1 "^$1 " <"${XDG_CONFIG_HOME:-$HOME/.config}/urls" | cut -f2 } insert() { - sed "s/%/$(echo $* | sed -e 's/ /%20/g' -e 's_/_\\/_g')/g" + sed "s/%/$(printf '%s%%20' $* | sed -e 's!/!\\/!g' -e 's/%20$//')/" } -format="$(shortcut "$1")" -if test -z "$format"; then - echo "$@" -else - shift - echo "$format" | insert "$@" -fi +shortcut="$1" +shift +{ find "$shortcut" || error "$shortcut: Not found"; } | insert "$@" diff --git a/local/bin/bin/xurls b/local/bin/bin/xurls @@ -4,4 +4,4 @@ # # xurls -- X11 url shortcut -dmenu -w $(pfw) -p url "$@" </dev/null | xargs urls | xgrab +urls $(dmenu -w $(pfw) -p search "$@" </dev/null) | xgrab