Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
210 additions
and
127 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cmd | ||
|
||
import "log" | ||
|
||
func logInfo(format string, v ...interface{}) { | ||
log.Printf(format, v...) | ||
} | ||
|
||
func logDebug(format string, v ...interface{}) { | ||
if verbose { | ||
log.Printf(format, v...) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
) | ||
|
||
const ignorePattern = `\.swp$|~$|^\.DS_Store$|^4913$` | ||
|
||
func createWatcher(dir string) (*fsnotify.Watcher, error) { | ||
watcher, err := fsnotify.NewWatcher() | ||
if err != nil { | ||
return watcher, err | ||
} | ||
logInfo("Watching %s/ for changes", dir) | ||
err = watcher.Add(dir) | ||
return watcher, err | ||
} | ||
|
||
func watch(done <-chan interface{}, errorChan chan<- error, reload chan<- bool, watcher *fsnotify.Watcher) { | ||
for { | ||
select { | ||
case event := <-watcher.Events: | ||
if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Create == fsnotify.Create { | ||
r := regexp.MustCompile(ignorePattern) | ||
if r.MatchString(event.Name) { | ||
logDebug("Debug [ignore]: `%s`", event.Name) | ||
} else { | ||
logInfo("Change detected in %s, refreshing", event.Name) | ||
reload <- true | ||
} | ||
} | ||
case err := <-watcher.Errors: | ||
errorChan <- err | ||
case <-done: | ||
return | ||
} | ||
} | ||
} |
Oops, something went wrong.