Skip to content

Commit

Permalink
Merge 56f7cea into e0078da
Browse files Browse the repository at this point in the history
  • Loading branch information
Shikkic committed Dec 18, 2016
2 parents e0078da + 56f7cea commit de6eb02
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Binary file added infra/gophrctl/gophr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions infra/gophrctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"gopkg.in/urfave/cli.v1"
)
Expand Down Expand Up @@ -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)
}
36 changes: 36 additions & 0 deletions infra/gophrctl/show_notification.go
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit de6eb02

Please sign in to comment.