Skip to content

Instantly share code, notes, and snippets.

@jarun
Last active May 26, 2024 08:41
Show Gist options
  • Save jarun/4f7f3fba4618054d999463f242a4b5b9 to your computer and use it in GitHub Desktop.
Save jarun/4f7f3fba4618054d999463f242a4b5b9 to your computer and use it in GitHub Desktop.
notification on command completion (fish shell)

Instead of waiting for long commands to finish one can easily get notifications when they are complete. The following procdure shows how to set his in fish shell.

Requirements: fish shell, notify-send, xdotool

  • Add a new file vi ~/.config/fish/functions/noti.fish with the content below:
function fish_right_prompt
    if test $CMD_DURATION
        # Check if terminal window is hidden
        if test (xdotool getactivewindow) -ne $WINDOWID
            # Show notification if dration is more than 30 seconds
            if test $CMD_DURATION -gt 30000
                # Show duration of the last command in seconds
                set duration (echo "$CMD_DURATION 1000" | awk '{printf "%.3fs", $1 / $2}')
                notify-send (echo (history | head -1) returned $status after $duration)
            end
        end
    end
end
  • Add the following line at the end of ~/.config/fish/config.fish to source noti.fish:
. ~/.config/fish/functions/noti.fish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment