diff --git a/infra/gophrctl/gophr.png b/infra/gophrctl/gophr.png new file mode 100644 index 0000000..2e23406 Binary files /dev/null and b/infra/gophrctl/gophr.png differ diff --git a/infra/gophrctl/main.go b/infra/gophrctl/main.go index 8ef91a6..c51eb21 100644 --- a/infra/gophrctl/main.go +++ b/infra/gophrctl/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "time" "gopkg.in/urfave/cli.v1" ) @@ -294,6 +295,9 @@ func main() { }, } + // Before we finish defer a terminal alert for when our command is done. + defer showNotification(time.Now(), os.Args) + // Lastly, execute the command line application. app.Run(os.Args) } diff --git a/infra/gophrctl/show_notification.go b/infra/gophrctl/show_notification.go new file mode 100644 index 0000000..7760f69 --- /dev/null +++ b/infra/gophrctl/show_notification.go @@ -0,0 +1,36 @@ +package main + +import ( + "strings" + "time" + + gosxnotifier "github.com/deckarep/gosx-notifier" +) + +const ( + gophrTitle = "gophrctl finished running" + gophrAlertSound = gosxnotifier.Default + gophrAppIconPath = "./gophr.png" + notificationThresholdInSeconds = 10 +) + +func showNotification(startTime time.Time, args []string) { + // Calculate our time difference since initially running a command. + timeDiff := time.Since(startTime).Seconds() + // Determine if we should push an alert. + shouldAlert := timeDiff > notificationThresholdInSeconds + + // Only alert if the time thershold has been passed. + if shouldAlert { + // Create a notification. + note := &gosxnotifier.Notification{ + Title: gophrTitle, + Sound: gophrAlertSound, + Message: strings.Join(args, " "), + AppIcon: gophrAppIconPath, + } + + // Push notification to the terminal. + note.Push() + } +}