Yet another zsh plug-in to receive notifications when long processes finish
Go to file
Bruno BELANYI 32f7c38016
ci/woodpecker/push/check Pipeline was successful Details
doc: fix typo
2024-02-15 16:36:41 +00:00
.woodpecker ci: add Woodpecker CI workflow 2023-08-13 15:23:14 +01:00
.envrc nix: add direnv integration 2023-08-13 15:23:14 +01:00
.gitignore git: add ignore file 2023-08-13 15:23:14 +01:00
LICENSE doc: add LICENSE 2023-08-13 15:24:33 +01:00
README.md doc: fix typo 2024-02-15 16:36:41 +00:00
done.plugin.zsh done: fix ignored command 2024-02-15 16:29:11 +00:00
flake.lock nix: add flake 2023-08-13 15:23:14 +01:00
flake.nix nix: bump to v0.1.1 2024-02-15 16:31:18 +00:00

README.md

zsh-done

This is a Zshell plug-in to automatically receive notifications after a long-running process ends.

Dependencies

  • If you want notifications with icons on macOS, install terminal-notifier.
  • If you are using swaywm, install jq.

Settings

Command duration threshold

DONE_MIN_CMD_DURATION=15 # Default: 5

Command deny-list regex

Uses grep -P (Perl syntax) to filter out commands that should never notify.

DONE_EXCLUDE='^\sgit (?!push|pull|fetch)' # Default: ''

Play a sound when sending notification

When using terminal-notifier, play a sound when sending the notification, otherwise ring the terminal bell.

DONE_NOTIFY_SOUND=1 # Default: 0

Notification levels

When using notify-send or notify-desktop, use a specific urgency level for your notifications.

DONE_NOTIFICATION_URGENCY_LEVEL=low # Default: normal
DONE_NOTIFICATION_URGENCY_LEVEL_FAILURE=normal # Default: critical

Do not show notification for visible windows (sway only)

DONE_SWAY_IGNORE_VISIBLE=1 # Default: 0

Allow sending notifications on non-graphical systems

This also requires you to define the done_send_notification function.

DONE_ALLOW_NONGRAPHICAL=1 # Default: 0

done_send_notification() {
    local exit_status="$1"
    local title="$2"
    local message="$3"
    # Use OSC-777 to send a notification (only with compatible terminals)
    echo -ne "\e]777;notify;$title;$message\e\\"
}

Customize the notification texts

You can define done_format_title and done_format_message to customize the title and message of your notifications.

done_format_title() {
    local exit_status="$1"
    local cmd_duration="$2"
    local last_command="$3"

    if [ "$exit_status" -eq 0 ]; then
        echo "SUCCESS (__done_humanize_duration "$cmd_duration")"
    else
        echo "FAIL (__done_humanize_duration "$cmd_duration")"
    fi
}

done_format_message() {
    local exit_status="$1"
    local cmd_duration="$2"
    local last_command="$3"

    printf '%s (%s)' "$last_command" "$exit_status"
}

More information and alternatives

This plug-in was largely inspired by the fish package of the same name, and steals much of the "is the shell focused" logic from it.

Unlike the fish plug-in, this one does not have support for Windows wired in.

Alternative plug-ins: