aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-20 20:42:28 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-20 21:36:46 +0200
commit9f9385e091a925ecf1d711daece1740138d12d59 (patch)
tree5340cf50e4ae1e80442dd7960aa2f19cd6f0ffb0
parent854c2b61a045b1f9804ed9c44da3ed10a2e3ec2f (diff)
Added READMEv0.1.0main
-rw-r--r--README.md37
-rw-r--r--main.go16
2 files changed, 44 insertions, 9 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7dd4fb4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# Installation
+```sh
+git clone https://git.spacehb.net/wbr
+cd wbr
+go install .
+```
+
+# Example
+Run `./build.sh` whenever a file ending with '.c' or '.h' is modified:
+```sh
+wbr -r './build.sh' -s '.c,.h'
+```
+Run a c file from the `src/` directory whenever it is modified:
+```sh
+wbr -b 'tcc -run' -p src/
+```
+Compile a c file with `common.c` and run it.
+```sh
+wbr -b 'gcc -Wall -Werror common.c' -r './a.out' -s '.c'
+```
+
+# Usage
+```txt
+Usage of wbr:
+ -b string
+ Command to run for building, it will pass the file modified as argument to it
+ -p string
+ Path to watch for files (default ".")
+ -r string
+ Command for running after build
+ -s string
+ Filter watched files by suffix, specify multiple by separating with ','
+ -v Show wbr version
+```
+
+## Pro tip:
+- use `set -x` in your build scripts
diff --git a/main.go b/main.go
index 2dcec31..276654f 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,4 @@
-// wbr will run a build command and a run command on file system changes. This is so you can
-// build&run on save.
-// You specify a build command and run command as flags and optionally you can filter by extension.
+// Run a command whenever a file is modified.
package main
@@ -29,8 +27,8 @@ var (
BuildCommand []string
// Command run after build
RunCommand []string
- // Command will only run on files that have the Extensions extension
- Extensions []string
+ // Command will only run on files that have the Suffixes extension
+ Suffixes []string
// Layout for timestamp of command
DateLayout string = "15:04:05"
// Version tag for wbr
@@ -50,7 +48,7 @@ func GetVersion() string {
func CompileRun(fileName string) {
found := false
- for _, Ext := range Extensions {
+ for _, Ext := range Suffixes {
if strings.HasSuffix(fileName, Ext) {
found = true
break
@@ -130,9 +128,9 @@ func main() {
}
defer watcher.Close()
- bc := flag.String("b", "", "Command to run for building")
+ bc := flag.String("b", "", "Command to run for building, it will pass the file modified as argument to it")
rc := flag.String("r", "", "Command for running after build")
- e := flag.String("e", "", "Filter watched files by suffix")
+ s := flag.String("s", "", "Filter watched files by suffix, specify multiple by separating with ','")
p := flag.String("p", ".", "Path to watch for files")
v := flag.Bool("v", false, "Show wbr version")
flag.Parse()
@@ -144,7 +142,7 @@ func main() {
BuildCommand = strings.Split(*bc, " ")
RunCommand = strings.Split(*rc, " ")
- Extensions = strings.Split(*e, ",")
+ Suffixes = strings.Split(*s, ",")
Path = *p
fmt.Printf("[%s watching '%s'%s]\n", Cyan, Path, Reset)