From 2f6039abadc659c24200371bbc392ed238f875e5 Mon Sep 17 00:00:00 2001 From: lara Date: Wed, 23 Dec 2020 16:43:24 +0100 Subject: [PATCH] [bin] Update scripts to use lib functions --- bin/cliplumber | 22 +++++++--------------- bin/dragon | 9 +++++---- bin/playvideo | 7 +++++-- bin/shot | 18 +++++------------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/bin/cliplumber b/bin/cliplumber index d2d076f..fc4542b 100755 --- a/bin/cliplumber +++ b/bin/cliplumber @@ -1,22 +1,14 @@ #!/bin/sh +# Load helper functions +source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh" + # TODO: detect term or set it globally TERM_EMU="kitty" -die() { - notify-send "$@" - exit 1 -} - -check_exists() { - for c in $@; do - which "$c" > /dev/null 2>&1 || return 1 - done -} - -if ! which wl-paste > /dev/null 2>&1 && [ ! -z "$WAYLAND_DISPLAY" ]; then +if ! check_exists wl-paste && [ ! -z "$WAYLAND_DISPLAY" ]; then die "Wayland detected and wl-paste not found" -elif ! which xsel > /dev/null 2>&1 && [ -z "$WAYLAND_DISPLAY" ]; then +elif ! check_exists xsel && [ -z "$WAYLAND_DISPLAY" ]; then die "xsel not found" fi @@ -61,7 +53,7 @@ case "$choice" in path="$HOME/mus/$(printf "%s" "$choice" | cut -d " " -f 2-)" [ -d "$path" ] || mkdir -p "$path" cd "$path" || exit - youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s" "$urls" 2>&1 | grep 'ERROR:' | tee /dev/fd/2 | xargs -n1 -d "\n" notify-send + youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s" "$urls" 2>&1 | grep 'ERROR:' | notify_err ;; "crawl") path="$HOME/books/" @@ -70,7 +62,7 @@ case "$choice" in out="$(lncrawl --single --all --format epub --filename-only --suppress -s "$urls" | grep -vFe "Input is suppressed" -e "Namespace(")" errors="$(printf "%s" "$out" | grep -Fe " ❗ ")" if [ -n "$errors" ]; then - printf "%s" "$errors" | xargs -n1 -d "\n" notify-send + printf "%s" "$errors" | notify_err else printf "%s" "$out" | sed -ne '/^NOVEL: /s/NOVEL: \(.*\)/Successfully crawled "\1"/p' | xargs -0 -n1 notify-send fi diff --git a/bin/dragon b/bin/dragon index 7e2e777..452c2fd 100755 --- a/bin/dragon +++ b/bin/dragon @@ -3,8 +3,9 @@ # We use a script instead of an alias because we want this utility in our path, # usable from dmenu -if ! which dragon-drag-and-drop > /dev/null 2>&1; then - echo "Error: dragon-drag-and-drop isn't installed!" | tee /dev/fd/2 | xargs -n1 -d "\n" notify-send -fi +# Load helper functions +source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh" -dragon-drag-and-drop $* +assert_exists dragon-drag-and-drop + +dragon-drag-and-drop "$@" diff --git a/bin/playvideo b/bin/playvideo index c7e0a3c..f637fe3 100755 --- a/bin/playvideo +++ b/bin/playvideo @@ -1,7 +1,10 @@ #!/bin/sh -if [ "$1" = "-h" ] || [ "$#" -ne "1" ]; then - >&2 echo "Usage: $0 " +# Load helper functions +source "$(dirname "$(rreadlink "$0")")/../lib/utils.sh" + +if [ "$1" = "-h" ] || [ "$#" -lt "1" ]; then + >&2 echo "Usage: $0 [-l]