sar
Idea for alternative to wk-j/vscode-save-and-run
I use vim, so I don't like .vscode, please contribute and feedback issues.
⚠ this idea is not perfect.
How many files can be watched at once?
There are OS-specific limits as to how many watches can be created:
Linux: /proc/sys/fs/inotify/max_user_watches contains the limit, reaching this limit results in a "no space left on device" error.
BSD / OSX: sysctl variables "kern.maxfiles" and "kern.maxfilesperproc", reaching these limits results in a "too many open files" error.
GitHub - fsnotify/fsnotify: Cross-platform file system notifications for Go.
$ go get github.com/kis9a/sar
Commands
$ sar
# example usage:
$ sar
$ sar -c ~/example/sar.toml
$ sar -d
# try:
$ git clone https://github.com/kis9a/sar
$ cd sar/
$ go install .
$ cd example
$ sar
Configuration
- -c someName # flag argument
- ./.sar.toml # current directory .sar.toml
- ./.sar.json # current directory .sar.toml
- ~/.sar.toml # home directory .sar.toml
- ~/.sar.json # home directory .sar.json
[[sar]]
base = "~/any/statics" # ~ mean home directory
[[sar.commands]]
match = "one/*.js"
cmd = "echo change one/*.js"
silent = true # don't output cmd execute log
[[sar]]
base = "${env.DOTFILES}"
hidden = true # watcher don't ignore .dot-directory/
[[sar.commands]]
match = "**vim"
cmd = "echo ${fileName}"
[[sar]]
base = "" # current directory
[[sar.commands]]
match = "**.html"
cmd = """echo cwd:\t ${cwd}
echo home: ${home}
echo filePath: ${filePath}
echo fileName: ${fileName}
echo fileBaseName: ${fileBaseName}
echo fileExtName: ${fileExtName}
echo fileDirPath: ${fileDirPath}
echo fileDirName: ${fileDirName}
echo base: ${base}
echo baseName: ${baseName}
echo ${env.HOME}
"""
[[sar.commands]]
match = ".sar.{toml,json}"
cmd = "echo refresh watcher config"
[[sar.commands]]
match = "**.go"
cmd = """
go build .
./${fileDirName}
"""
Match example
Match := func(match string, path string) bool {
g := glob.MustCompile(match, '/')
return g.Match(path)
}
Match("*.js", "a.js") // true
Match("{a,b,c}.js", "a.js") // true
Match("[a-c].js", "a.js") // true
Match("[!a-c].js", "d.js") // true
Match("**.js", "a/b.js") // true
Match("?????at.js", "12345at.js") // true
Match("*/*.js", "a/b.js") // true
Match("a/*.js", "a/b.js") // true
Match("a/**.js", "a/b.js") // true
Match("*.js", "a/b.js") // false
Match("{a,b,c}.js", "d.js") // false
Match("[a-c].js", "d.js") // false
Match("[1-8].js", "9.js") // false
Match("b/*.js", "a/b.js") // false
Match("a/**/*.js", "a/b.js") // false
Cmd Placeholder Tokens
- ${cwd} - current working directory
- ${home} - home directory.
- ${filePath} - matched file path.
- ${fileName} - matched file name.
- ${fileBaseName} - matched file base name.
- ${fileExtName} - matched file extension name.
- ${fileDirPath} - matched filepath directory path.
- ${fileDirName} - matched filepath directory name.
- ${base} - matched file base directory.
- ${baseName} - matched file base directory name.
Environment Variable Tokens
- ${env.ENVNAME} - os variables string
example:
- ${env.HOME}
- ${env.EDITOR}
License