-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 965 Bytes
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"os/exec"
"runtime"
)
// THANKS: https://stackoverflow.com/a/22896706
func clear(osName string) {
if osName == "windows" {
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
} else {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
}
}
var Version = ""
func main() {
useClear := flag.Bool("c", false, "clear terminal before every run")
useVersion := flag.Bool("v", false, "version")
flag.Parse()
if *useVersion {
fmt.Println(Version)
os.Exit(0)
}
commands := flag.Args()
if len(commands) == 0 {
log.Fatal("a command is required")
}
command := commands[0]
args := flag.Args()[1:]
buf := bufio.NewReader(os.Stdin)
for {
if *useClear {
clear(runtime.GOOS)
}
cmd := exec.Command(command, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
_ = cmd.Run()
_, _ = buf.ReadBytes('\n')
}
}