forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_watch.go
49 lines (37 loc) · 890 Bytes
/
cmd_watch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import "fmt"
var CmdWatch = &Cmd{
Name: "watch",
Desc: "Adds a path to the list that direnv watches for changes",
Args: []string{"[SHELL]", "PATH"},
Private: false,
Fn: watchCommand,
}
func watchCommand(env Env, args []string) (err error) {
var path, shellName string
args = args[1:]
if len(args) < 1 {
return fmt.Errorf("A path is required to add to the list of watches")
}
if len(args) >= 2 {
shellName = args[0]
args = args[1:]
} else {
shellName = "bash"
}
shell := DetectShell(shellName)
if shell == nil {
return fmt.Errorf("Unknown target shell '%s'", shellName)
}
path = args[0]
watches := NewFileTimes()
watchString, ok := env[DIRENV_WATCHES]
if ok {
watches.Unmarshal(watchString)
}
watches.Update(path)
e := make(ShellExport)
e.Add(DIRENV_WATCHES, watches.Marshal())
fmt.Printf(shell.Export(e))
return
}