diff options
| -rw-r--r-- | conf.d/00functions.fish | 10 | ||||
| -rw-r--r-- | conf.d/05gui.fish | 28 | ||||
| -rw-r--r-- | functions/alert.fish | 19 |
3 files changed, 40 insertions, 17 deletions
diff --git a/conf.d/00functions.fish b/conf.d/00functions.fish index f390b29..d1ad87b 100644 --- a/conf.d/00functions.fish +++ b/conf.d/00functions.fish @@ -34,3 +34,13 @@ function find_prog --description "Find one or more programs in \$PATH" end end end + +function ask --description "Ask a question answered by yes or no" + read -n 1 -f -P (set_color -o blue)"::"(set_color normal)" $argv[1] [y/N] " answer + switch $answer + case y Y + return 0 # yes + case '*' + return 1 # no + end +end diff --git a/conf.d/05gui.fish b/conf.d/05gui.fish index 68599ce..9fc0629 100644 --- a/conf.d/05gui.fish +++ b/conf.d/05gui.fish @@ -1,17 +1,17 @@ -if status is-interactive; and not fish_is_root_user +if not fish_is_root_user -if set -q WAYLAND_DISPLAY - alias_if wl-copy ccpy - alias_if wl-paste cpst - alias_if notify notify-send -else if set -q DISPLAY - alias_if xclip ccpy -i -selection clipboard - alias_if xclip cpst -o -selection clipboard - alias_if notify-send notify -else if test (uname) = 'Darwin' - alias_if pbcopy ccpy - alias_if pbpaste cpst - alias_if osascript notify -e -end + if set -q WAYLAND_DISPLAY + alias_if wl-copy ccpy + alias_if wl-paste cpst + alias_if notify-send notify + else if set -q DISPLAY + alias_if xclip ccpy -i -selection clipboard + alias_if xclip cpst -o -selection clipboard + alias_if notify-send notify + else if string match -q 'Darwin' (uname) + alias_if pbcopy ccpy + alias_if pbpaste cpst + alias_if osascript notify -e + end end diff --git a/functions/alert.fish b/functions/alert.fish index d4e17dc..6ab53cb 100644 --- a/functions/alert.fish +++ b/functions/alert.fish @@ -1,9 +1,22 @@ function alert --description 'Report status of command to desktop' + set -l cmd $argv + set -l cmd_str (string join ' ' $cmd) + set -l output (eval $cmd 2>&1) + set -l retval $status - if test $status -eq 0 - notify "✅ Done" (history | head -n1) + if functions -q notify + if test $retval -eq 0 + notify "✅ Done: $cmd_str" "$output" + else + notify "❌ Failed $cmd_str" "$output" + end else - notify "❌ Failed" (history | head -n1) + if test $retval -eq 0 + printf "✅ Done: %s\n%s\n" "$cmd_str" "$output" + else + printf "❌ Failed: %s\n%s\n" "$cmd_str" "$output" + end end + return $retval end |
