From c95fbdbe05a428cdb78b016c6b6d81a4e02f3f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20=C5=BD=C3=A1k?= Date: Tue, 6 Aug 2024 14:47:42 +0200 Subject: [PATCH] added reading ignored commands from a file --- README.rst | 12 ++++++++++++ auto-notify.plugin.zsh | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.rst b/README.rst index a69648d..7f15ef8 100644 --- a/README.rst +++ b/README.rst @@ -151,6 +151,18 @@ a new array. # redefine what is ignored by auto-notify export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep") +Commands from the file auto-notify-ignored.txt are also also appended to the ``AUTO_NOTIFY_IGNORE`` variable. +This file is searched for in ``$ZDOTDIR``, or in your home dir if ``$ZDOTDIR`` isn't exported. +You might have to create it, it isn't there by default. +Each line in this file will be appended as one item (command) to the array. +If you wish to use custom location and/or name of the auto-notify-ignored.txt file, +then set ``AUTO_NOTIFY_IGNORE_FILE``` variable to your custom path. + +:: + + # set custom path to an ignore file + export AUTO_NOTIFY_IGNORE_FILE="${HOME}/Documents/my-custom-ignore.txt" + **Using a Whitelist to ignore commands** If you wish to use a whitelist approach instead of the default blacklist approach used by ``AUTO_NOTIFY_IGNORE``, diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 591a47e..dca7542 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -6,6 +6,9 @@ export AUTO_NOTIFY_VERSION="0.10.2" # Threshold in seconds for when to automatically show a notification [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && export AUTO_NOTIFY_THRESHOLD=10 +# Path to auto-notify-ignored.txt - file with ignored commands +[[ -z "$AUTO_NOTIFY_IGNORE_FILE" ]] && + export AUTO_NOTIFY_IGNORE_FILE="${ZDOTDIR:-$HOME}/auto-notify-ignored.txt" # List of commands/programs to ignore sending notifications for [[ -z "$AUTO_NOTIFY_IGNORE" ]] && @@ -24,6 +27,16 @@ export AUTO_NOTIFY_VERSION="0.10.2" 'nano' ) +# If AUTO_NOTIFY_WHITELIST isn't defined, read the file in AUTO_NOTIFY_IGNORE_FILE +# and append each line in that file to AUTO_NOTIFY_IGNORE array +if [[ -z "$AUTO_NOTIFY_WHITELIST" ]]; then + if [[ -e "$AUTO_NOTIFY_IGNORE_FILE" ]]; then + while IFS= read -r line; do + AUTO_NOTIFY_IGNORE+=("$line") + done < "$AUTO_NOTIFY_IGNORE_FILE" + fi +fi + function _auto_notify_format() { local MESSAGE="$1" local command="$2"