Example #1
0
func main() {

	notify = notificator.New(notificator.Options{
		DefaultIcon: "icon/default.png",
		AppName:     "My test App",
	})

	notify.PushWithIcon("title", "text", "/home/user/icon.png")
}
Example #2
0
func main() {
	fmt.Println("Autoexec v1.1")
	io.WriteString(os.Stdout, "\033]0;Autoexec\007")

	if help || cmd == "" || suffix == "" {
		flag.PrintDefaults()
		return
	}
	fmt.Println(flag.Args())
	args = flag.Args()

	notifier = notificator.New(notificator.Options{
		AppName: "Autoexec",
	})

	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if path == "" {

		path, err = os.Getwd()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	} else {
		path, err = filepath.Abs(path)
		if err != nil {
			panic(err)
		}
		fmt.Println("Path: ", path)
	}

	filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			fmt.Println("Error", err)
			return err
		}

		if info.IsDir() && !strings.HasPrefix(path, ".") {
			matches, err := filepath.Glob(path + "/*" + suffix)
			if err != nil {
				panic(err)
			}
			if len(matches) > 0 {
				if verbose {
					fmt.Println("Adding  ", path)
				}
				watcher.Add(path)
			} else {
				if verbose {
					fmt.Println("Skipping", path)
				}
			}
			return nil
		}

		return nil
	})

	defer watcher.Close()

	signal := make(chan struct{})

	// start our worker routine
	go startExec(signal, cmd, args)

	fmt.Println("Monitoring", path, suffix)

	for {
		select {
		case ev := <-watcher.Events:
			if strings.HasSuffix(ev.Name, suffix) {
				if verbose {
					fmt.Printf("[%d] %v\n", time.Now().UnixNano(), ev.Name)
				}
				signal <- struct{}{}
			}

		case err := <-watcher.Errors:
			fmt.Println(err)
		}
	}
}