From 145548c01a7d1ff49c239e9cd66e07d797c6a1dc Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 8 Feb 2020 20:18:16 +0100 Subject: [PATCH] Change ifinstalled script to exist Renamed ifinstalled to exist, moved it into base shell module. It can be called with just a command name to check for, or with an additional libnotify urgency level (low, normal, critical). If called with an urgency as the second argument, the user will be notified of the missing command with the corresponding urgency. --- scripts/.local/bin/ifinstalled | 4 ---- sh/.local/bin/exist | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) delete mode 100755 scripts/.local/bin/ifinstalled create mode 100755 sh/.local/bin/exist diff --git a/scripts/.local/bin/ifinstalled b/scripts/.local/bin/ifinstalled deleted file mode 100755 index 26c3b51..0000000 --- a/scripts/.local/bin/ifinstalled +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -# If $1 command is not available, error code and notify. - -command -v "$1" >/dev/null || { notify-send "📦 $1" "must be installed for this function." && exit 1 ;} diff --git a/sh/.local/bin/exist b/sh/.local/bin/exist new file mode 100755 index 0000000..397319e --- /dev/null +++ b/sh/.local/bin/exist @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +# check for existing implementations +# If $1 command is not available, error code +# If $2 is low, normal, urgent, also notify the user. (loud-mode) + +if command -v "$1" >/dev/null; then + exit 0 +else + if [ -n "$2" ]; then + if command -v notify-send >/dev/null; then + notify-send "📦 $1" --urgency="$2" "must be installed for this function." + else + printf "%s: 📦 %s must be installed for this function.\n" "$2" "$1" + fi + fi + exit 1 +fi