From 240d35cba3b0b5c4f5975ae73b8be1e73fdf50df Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 27 Jul 2018 18:32:42 +0300 Subject: [PATCH] use notify-send if available Signed-off-by: fbt --- sx-open | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/sx-open b/sx-open index b9384f6..23155be 100755 --- a/sx-open +++ b/sx-open @@ -18,6 +18,18 @@ act() { return 0 } +notify() { + [[ $DISPLAY ]] || return 3 + [[ $notifier ]] || return 5 + + "${notifier[@]}" 'sx-open' "$@" +} + +error() { + printf '%s\n' "$*" >&2 + notify "$*" +} + # handle_target # 1: cmd failed # 3: no handler @@ -122,21 +134,27 @@ main() { # Treat file:// as local paths. [[ "$target" =~ ^file:(//)?(/.+) ]] && target=${BASH_REMATCH[2]} + # Figure out if we're in X and set $notifier if we are. + if [[ $DISPLAY ]]; then + # Do we have notify-send? + notifier=$(type -P 'notify-send') + fi + handle_target cmd_result "$target" case $? in (1) - printf 'Action failed with exit code: “%s”\n' "$cmd_result" >&2 + error "Action on “$target” failed with exit code: “$cmd_result”" return 4 ;; (2) - printf 'No such file or directory: “%s”\n' "$target" >&2 + error "No such file or directory: “$target”" return 2 ;; (3) - printf 'No handlers found for “%s”\n' "$target" >&2 + error "No handlers found for “$target”" return 3 ;; esac