use flag instead os os.Args
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
c9665b33b3
commit
79fe14e059
16
README.md
16
README.md
|
@ -36,19 +36,19 @@ app <block_name> <name> <command> <background_color> <foreground_color>
|
|||
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 <block_name> <name> <mount_point> <limit_warning> <limit_danger>
|
||||
du -block=<block_name> -name=<name> -mount-point=<mount_point> -limit-warning=<limit_warning> -limit-danger=<limit_danger>
|
||||
```
|
||||
|
||||
Show the IP of the given iface.
|
||||
|
||||
```
|
||||
ip <iface> <ip4|ip6> <name>
|
||||
ip -iface=<iface> -version=<ip4|ip6> -name=<name>
|
||||
```
|
||||
|
||||
Show the public IP.
|
||||
|
@ -60,19 +60,19 @@ ip_wan
|
|||
Show the telemetry using Prusa Printer API.
|
||||
|
||||
```
|
||||
prusa_telemetry <block_name> http://<prusa_printer_ip>/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 <process> <message>
|
||||
ps -process=<process> -message=<message>
|
||||
```
|
||||
|
||||
Show indicator of RSS.
|
||||
|
||||
```
|
||||
rss <block_name> <feed_url> <feed_reader_url> <foreground_color_when_no_item> <foreground_color_when_items>
|
||||
rss -block=<block_name> -feed=<feed_url> -website=<feed_reader_url> -empty-color=<color> -non-empty-color=<color>
|
||||
```
|
||||
|
||||
Show current song played (spotify).
|
||||
|
@ -84,13 +84,13 @@ spotify
|
|||
Show volume.
|
||||
|
||||
```
|
||||
volume <channel>
|
||||
volume -channel=<channel>
|
||||
```
|
||||
|
||||
Toggler for wireguard.
|
||||
|
||||
```
|
||||
wireguard <iface> <name>
|
||||
wireguard -iface=<iface> -name=<name>
|
||||
```
|
||||
|
||||
Add a blocks that represent opened apps to create a task bar.
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
})
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue