Created
May 23, 2015 13:21
-
-
Save dansondergaard/3103ebdfa375f6f524eb to your computer and use it in GitHub Desktop.
Notification when long-running process has completed (only for OS X and Fish 2.2b1-10 or newer).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ################# | |
| # notifications # | |
| ################# | |
| function __record_cmd_begin -d "Record time when command started." -e fish_preexec | |
| set -g cmd_begin_time (eval date +"%s") | |
| end | |
| function __record_cmd_end -d "Record time when command ended." -e fish_postexec | |
| set -g cmd_end_time (eval date +"%s") | |
| set -g cmd_duration (math "($cmd_end_time-$cmd_begin_time)") | |
| end | |
| set notification_warn_after 10 # sec | |
| function __notify_on_long_running_cmd -d "Show popup notification when long-running command has finished." -e fish_postexec | |
| set -l active_window_name (osascript -e \ | |
| "tell application \"System Events\" | |
| set frontApp to name of first application process whose frontmost is true | |
| end tell" | |
| ) | |
| if test "$active_window_name" != "Terminal" | |
| set -l command (echo $argv | cut -d ' ' -f 1) | |
| if test "$cmd_duration" -gt $notification_warn_after | |
| osascript -e "display notification \"$argv\" with title \"Command finished after $cmd_duration seconds!\"" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment