diff --git a/README.md b/README.md index 8b3861a..aa98cac 100644 --- a/README.md +++ b/README.md @@ -36,19 +36,19 @@ app Show the time using given format and run `gnome-calendar` when clicked. ``` -date "%H:%M:%S %d/%m/%Y" +date -format="%H:%M:%S %d/%m/%Y" ``` Show mount point usage and warns with limits and colors. ``` -du +du -block= -name= -mount-point= -limit-warning= -limit-danger= ``` Show the IP of the given iface. ``` -ip +ip -iface= -version= -name= ``` Show the public IP. @@ -60,19 +60,19 @@ ip_wan Show the telemetry using Prusa Printer API. ``` -prusa_telemetry http:///api/telemetry +prusa_telemetry -api=http://1.2.3.4/api/telemetry ``` Show a message when the given process is running (use `preg -f`). ``` -ps +ps -process= -message= ``` Show indicator of RSS. ``` -rss +rss -block= -feed= -website= -empty-color= -non-empty-color= ``` Show current song played (spotify). @@ -84,13 +84,13 @@ spotify Show volume. ``` -volume +volume -channel= ``` Toggler for wireguard. ``` -wireguard +wireguard -iface= -name= ``` Add a blocks that represent opened apps to create a task bar. diff --git a/blocks/app/main.go b/blocks/app/main.go index b471134..873c9d4 100644 --- a/blocks/app/main.go +++ b/blocks/app/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" r "gitnet.fr/deblan/i3-blocks-go/rendering" "os" @@ -17,18 +18,25 @@ func runCmd(wg *sync.WaitGroup, value string) { func main() { var wg sync.WaitGroup - if os.Getenv("BLOCK_BUTTON") == "1" { + argBlockName := flag.String("block", "app", "block name") + argName := flag.String("name", "", "name of the app") + argCommand := flag.String("cmd", "", "command to run on click") + argBgColor := flag.String("bg-color", "#333333", "background color") + argFbColor := flag.String("fg-color", "#ffffff", "foreground color") + flag.Parse() + + if os.Getenv("BLOCK_BUTTON") == "1" && *argCommand != "" { wg.Add(1) - go runCmd(&wg, os.Args[5]) + go runCmd(&wg, *argCommand) } options := r.NewBlockOptions() - options.FullText = r.TextWithPadding(os.Args[2], r.FB{ - Background: os.Args[3], - Foreground: os.Args[4], + options.FullText = r.TextWithPadding(*argName, r.FB{ + Background: *argBgColor, + Foreground: *argFbColor, }) - block := r.Block(os.Args[1], options) + block := r.Block(*argBlockName, options) fmt.Println(block) wg.Wait() } diff --git a/blocks/date/main.go b/blocks/date/main.go index 8b622bc..4ad0cf0 100644 --- a/blocks/date/main.go +++ b/blocks/date/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "github.com/enescakir/emoji" "github.com/itchyny/timefmt-go" @@ -18,7 +19,9 @@ func runCalendar(wg *sync.WaitGroup) { } func main() { - argFormat := os.Args[1] + argFormat := flag.String("format", "%H:%M:%S %m-%d-%Y", "time format") + flag.Parse() + now := time.Now() var wg sync.WaitGroup @@ -29,7 +32,7 @@ func main() { } symbol := string(emoji.Calendar) - date := timefmt.Format(now, argFormat) + date := timefmt.Format(now, *argFormat) options := r.NewBlockOptions() options.FullText = r.TextWithRightPadding(fmt.Sprintf("%s %s", symbol, date), r.FB{ diff --git a/blocks/du/main.go b/blocks/du/main.go index 14e4f2f..27723eb 100644 --- a/blocks/du/main.go +++ b/blocks/du/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" r "gitnet.fr/deblan/i3-blocks-go/rendering" "os" @@ -27,32 +28,33 @@ func runFileExplorer(wg *sync.WaitGroup, path string) { } func main() { - argBlockName := os.Args[1] - argName := os.Args[2] - argPoint := os.Args[3] - argLimitWarning, _ := strconv.Atoi(os.Args[4]) - argLimitDanger, _ := strconv.Atoi(os.Args[5]) + argBlockName := flag.String("block", "du", "block name") + argName := flag.String("name", "du", "block name") + argMountPoint := flag.String("mount-point", "du", "block name") + argLimitWarning := flag.Int("limit-warning", 70, "limit for warning") + argLimitDanger := flag.Int("limit-danger", 90, "limit for danger") + flag.Parse() - used := DiskUsage(argPoint) + used := DiskUsage(*argMountPoint) fbUsed := r.FB{Background: r.Color("black1")} var wg sync.WaitGroup if os.Getenv("BLOCK_BUTTON") == "1" { wg.Add(1) - go runFileExplorer(&wg, fmt.Sprintf("file://%s", argPoint)) + go runFileExplorer(&wg, fmt.Sprintf("file://%s", *argMountPoint)) } - if used < argLimitWarning { + if used < *argLimitWarning { fbUsed.Foreground = r.Color("green") - } else if used < argLimitDanger { + } else if used < *argLimitDanger { fbUsed.Foreground = r.Color("orange") } else { fbUsed.Foreground = r.Color("red") } label := r.TextWithPadding( - argName, + *argName, r.FB{ Foreground: r.Color("grey1"), Background: r.Color("black2"), @@ -63,7 +65,7 @@ func main() { options := r.NewBlockOptions() options.FullText = fmt.Sprintf("%s%s", label, value) - block := r.Block(argBlockName, options) + block := r.Block(*argBlockName, options) fmt.Println(block) wg.Wait() diff --git a/blocks/ip/main.go b/blocks/ip/main.go index d737bdf..1d0d551 100644 --- a/blocks/ip/main.go +++ b/blocks/ip/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "github.com/atotto/clipboard" r "gitnet.fr/deblan/i3-blocks-go/rendering" @@ -11,21 +12,10 @@ import ( ) func main() { - argIface := os.Args[1] - argVersion := os.Args[2] - argName := os.Args[3] - - if argIface == "" { - argIface = "eth0" - } - - if argVersion == "" { - argVersion = "ip4" - } - - if argName == "" { - argName = argIface - } + argIface := flag.String("iface", "eth0", "the iface") + argVersion := flag.String("version", "ip4", "ip4 or ip6") + argName := flag.String("name", "eth0", "the name") + flag.Parse() var ( iface *net.Interface @@ -33,7 +23,7 @@ func main() { // ip net.IP ) - iface, err := net.InterfaceByName(argIface) + iface, err := net.InterfaceByName(*argIface) if err != nil { return @@ -47,9 +37,9 @@ func main() { if ip == "" { a := addr.String() - if argVersion == "ip4" && !strings.Contains(a, ":") { + if *argVersion == "ip4" && !strings.Contains(a, ":") { ip = a - } else if argVersion == "ip6" && strings.Contains(a, ":") && !strings.Contains(a, "fe80") { + } else if *argVersion == "ip6" && strings.Contains(a, ":") && !strings.Contains(a, "fe80") { ip = a } } @@ -67,7 +57,7 @@ func main() { } label := r.TextWithPadding( - argName, + *argName, r.FB{ Foreground: r.Color("grey1"), Background: r.Color("black2"), diff --git a/blocks/prusa_telemetry/main.go b/blocks/prusa_telemetry/main.go index 1971921..7898cef 100644 --- a/blocks/prusa_telemetry/main.go +++ b/blocks/prusa_telemetry/main.go @@ -2,12 +2,12 @@ package main import ( "encoding/json" + "flag" "fmt" "github.com/itchyny/timefmt-go" r "gitnet.fr/deblan/i3-blocks-go/rendering" "io" "net/http" - "os" "strconv" "time" ) @@ -20,7 +20,10 @@ type Telemetry struct { } func main() { - resp, err := http.Get(os.Args[2]) + argApi := flag.String("api", "", "the api url") + flag.Parse() + + resp, err := http.Get(*argApi) if err != nil { return @@ -62,7 +65,7 @@ func main() { options := r.NewBlockOptions() options.FullText = fmt.Sprintf("%s%s%s%s", progress, tempNozzle, tempBed, date) - block := r.Block(os.Args[1], options) + block := r.Block("prusa_telemetry", options) fmt.Println(block) } diff --git a/blocks/ps/main.go b/blocks/ps/main.go index 0797b82..173484d 100644 --- a/blocks/ps/main.go +++ b/blocks/ps/main.go @@ -1,9 +1,9 @@ package main import ( + "flag" "fmt" r "gitnet.fr/deblan/i3-blocks-go/rendering" - "os" "os/exec" "strings" ) @@ -17,14 +17,15 @@ func ProcessExists(process string) bool { } func main() { - argProcess := os.Args[1] - argName := os.Args[2] + argProcess := flag.String("process", "", "the process") + argMessage := flag.String("message", "", "the message") + flag.Parse() - if !ProcessExists(argProcess) { + if !ProcessExists(*argProcess) { return } - value := r.TextWithPadding(argName, r.FB{ + value := r.TextWithPadding(*argMessage, r.FB{ Foreground: r.Color("green"), Background: r.Color("black1"), }) diff --git a/blocks/rss/main.go b/blocks/rss/main.go index cd5fb4d..9cf38b9 100644 --- a/blocks/rss/main.go +++ b/blocks/rss/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" r "gitnet.fr/deblan/i3-blocks-go/rendering" "io" @@ -27,12 +28,19 @@ func openBrowser(wg *sync.WaitGroup, url string) { func main() { var wg sync.WaitGroup + argBlock := flag.String("block", "rss", "block name") + argFeed := flag.String("feed", "", "url of the feed") + argWebsite := flag.String("website", "", "website") + argEmptyColor := flag.String("empty-color", "#CCCCCC", "empty color") + argNonEmptyColor := flag.String("non-empty-color", "#B3FF6C", "when items color") + flag.Parse() + if os.Getenv("BLOCK_BUTTON") == "1" { wg.Add(1) - go openBrowser(&wg, os.Args[3]) + go openBrowser(&wg, *argWebsite) } - resp, err := http.Get(os.Args[2]) + resp, err := http.Get(*argFeed) if err != nil { return @@ -45,18 +53,18 @@ func main() { label := r.FontAwesome("\uf09e") fb := r.FB{ - Foreground: os.Args[4], + Foreground: *argEmptyColor, Background: r.Color("black2"), } if count > 0 { label = fmt.Sprintf("%s +%d", label, count) - fb.Foreground = os.Args[5] + fb.Foreground = *argNonEmptyColor } options := r.NewBlockOptions() options.FullText = r.TextWithPadding(label, fb) - block := r.Block(os.Args[1], options) + block := r.Block(*argBlock, options) fmt.Println(block) wg.Wait() diff --git a/blocks/volume/main.go b/blocks/volume/main.go index c81cfca..289d87b 100644 --- a/blocks/volume/main.go +++ b/blocks/volume/main.go @@ -1,9 +1,9 @@ package main import ( + "flag" "fmt" r "gitnet.fr/deblan/i3-blocks-go/rendering" - "os" "os/exec" "regexp" "strconv" @@ -21,9 +21,10 @@ func Volume(channel string) int { } func main() { - argChannel := os.Args[1] + argChannel := flag.String("channel", "Master", "the channel") + flag.Parse() - volume := Volume(argChannel) + volume := Volume(*argChannel) var symbole string diff --git a/blocks/wireguard/main.go b/blocks/wireguard/main.go index abd3fed..6ad1056 100644 --- a/blocks/wireguard/main.go +++ b/blocks/wireguard/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" r "gitnet.fr/deblan/i3-blocks-go/rendering" "net" @@ -10,8 +11,9 @@ import ( ) func main() { - argIface := os.Args[1] - argName := os.Args[2] + argIface := flag.String("iface", "wg0", "the iface") + argName := flag.String("name", "wg0", "the name") + flag.Parse() var ( iface *net.Interface @@ -20,7 +22,7 @@ func main() { var ip string - iface, err := net.InterfaceByName(argIface) + iface, err := net.InterfaceByName(*argIface) if err == nil { addrs, _ = iface.Addrs() @@ -42,11 +44,11 @@ func main() { if ip == "" { fb.Foreground = r.Color("grey1") fb.Background = r.Color("black3") - command = exec.Command("sudo", "wg-quick", "up", argIface) + command = exec.Command("sudo", "wg-quick", "up", *argIface) } else { fb.Foreground = r.Color("black1") fb.Background = r.Color("green") - command = exec.Command("sudo", "wg-quick", "down", argIface) + command = exec.Command("sudo", "wg-quick", "down", *argIface) } if os.Getenv("BLOCK_BUTTON") == "1" { @@ -54,8 +56,8 @@ func main() { } options := r.NewBlockOptions() - options.FullText = r.TextWithPadding(argName, fb) - block := r.Block(fmt.Sprintf("wireguard_%s", argIface), options) + options.FullText = r.TextWithPadding(*argName, fb) + block := r.Block(fmt.Sprintf("wireguard_%s", *argIface), options) fmt.Println(block) }