Skip to content

Instantly share code, notes, and snippets.

@Kalabasa
Forked from ashwin/long-command-notification.sh
Last active December 29, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kalabasa/7678513 to your computer and use it in GitHub Desktop.
Save Kalabasa/7678513 to your computer and use it in GitHub Desktop.
long-notify.fish
function long-notify
### Notify on long command completion
# https://gist.github.com/Kalabasa/7678513#file-long-command-notification-sh
# Using fish version 2.1.1-1052-gf03d90e
# Forked from
# https://gist.github.com/ashwin/5891060#file-long-command-notification-sh
set -g MINIMUM_TIME 10
set -g EXCLUDED_COMMANDS nano vim edit sudoedit ssh top
# Check if var is set
if set -q CMD_DURATION
set -g time_ms (echo $CMD_DURATION | awk 'BEGIN { FS="." } ; { print $1 }')
set -g time_sec (math $time_ms/1000)
# Check if long duration
if test $time_sec -gt $MINIMUM_TIME
# Get command string
set -g cmd (history | head -n 1 | sed "s/\n*\$//")
# Check if excluded
set -g prog (echo $cmd | awk '{ print $1 }')
for c in $EXCLUDED_COMMANDS
if test $prog = $c
set -e cmd
break
end
end
if set -q cmd
# Format time
set -g time_min 0
set -g time_hour 0
set -g time_day 0
if test $time_sec -ge 60
set -g time_min (math $time_sec/60)
set -g time_sec (math $time_sec - $time_min \* 60)
end
if test $time_min -ge 60
set -g time_hour (math $time_min/60)
set -g time_min (math $time_min - $time_hour \* 60)
end
if test $time_hour -ge 24
set -g time_day (math $time_hour/24)
set -g time_hour (math $time_hour - $time_day \* 24)
end
set -g time ""
if test $time_day -gt 0
set -g time $time$time_day"d "
else if test $time_hour -gt 0
set -g time $time$time_hour"h "
if test $time_min -gt 0
set -g time $time$time_min"m"
end
else
if test $time_min -gt 0
set -g time $time$time_min"m "
end
if test $time_sec -gt 0
set -g time $time$time_sec"s "
end
end
# Notify
notify-send -i terminal "$cmd" "Finished in $time" -t 4000
end
end
end
return 0
end
@Kalabasa
Copy link
Author

Notification Title/Summary is wrong due to fish-shell/fish-shell#984

@Kalabasa
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment