File tree Expand file tree Collapse file tree 5 files changed +8
-25
lines changed Expand file tree Collapse file tree 5 files changed +8
-25
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ brew install inotify-tools
22
22
sudo pacman -S inotify-tools
23
23
```
24
24
25
-
26
25
## Example
27
26
28
27
[ Example] ( example/main.go )
Original file line number Diff line number Diff line change 1
1
package inotifywaitgo
2
2
3
3
import (
4
- "bufio"
5
4
"os/exec"
6
5
)
7
6
8
7
// CheckDependencies verifies if inotifywait is installed.
9
8
func checkDependencies () (bool , error ) {
10
- cmd := exec .Command ("bash" , "-c" , "which inotifywait" )
11
- stdout , err := cmd .StdoutPipe ()
9
+ path , err := exec .LookPath ("inotifywait" )
12
10
if err != nil {
13
11
return false , err
14
12
}
15
-
16
- if err := cmd .Start (); err != nil {
17
- return false , err
18
- }
19
-
20
- scanner := bufio .NewScanner (stdout )
21
- for scanner .Scan () {
22
- line := scanner .Text ()
23
- if line != "" {
24
- return true , nil
25
- }
13
+ if path != "" {
14
+ return true , nil
26
15
}
27
-
28
- if err := scanner .Err (); err != nil {
29
- return false , err
30
- }
31
-
32
16
return false , nil
33
17
}
Original file line number Diff line number Diff line change 6
6
"strings"
7
7
)
8
8
9
- func GenerateBashCommands (s * Settings ) ([]string , error ) {
9
+ func GenerateShellCommands (s * Settings ) ([]string , error ) {
10
10
if s .Options == nil {
11
11
return nil , errors .New (OPT_NIL )
12
12
}
Original file line number Diff line number Diff line change @@ -3,6 +3,6 @@ package inotifywaitgo
3
3
import "os/exec"
4
4
5
5
func killOthers () error {
6
- cmd := exec .Command ("bash " , "-c" , "pkill inotifywait"). Run ( )
7
- return cmd
6
+ cmd := exec .Command ("pkill " , "inotifywait" )
7
+ return cmd . Run ()
8
8
}
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ func WatchPath(s *Settings) {
29
29
killOthers ()
30
30
}
31
31
32
- // Generate bash command
33
- cmdString , err := GenerateBashCommands (s )
32
+ // Generate shell command
33
+ cmdString , err := GenerateShellCommands (s )
34
34
if err != nil {
35
35
s .ErrorChan <- err
36
36
return
You can’t perform that action at this time.
0 commit comments