diff --git a/.woodpecker.yml b/.woodpecker.yml index 5c6cf64..eb99650 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,11 +1,11 @@ steps: vendor: - image: golang:1.22 + image: golang:1.18 commands: - go mod vendor build: - image: golang:1.22 + image: golang:1.18 commands: - make - mkdir release diff --git a/Makefile b/Makefile index 864334d..47d140a 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,3 @@ linux-arm64: clean: rm -fr build/* 2>/dev/null || true - -tool-gofumpt: - which golangci-lint > /dev/null 2>&1 || go install mvdan.cc/gofumpt@latest - -fmt: tool-gofumpt - gofumpt -w --extra . diff --git a/README.md b/README.md index 218dbe6..5784b93 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Blocks compatible with [i3blocks](https://github.com/vivien/i3blocks). * `df` for `du` block * `xdg-open` for `du` block * `playerctl` for `spotify` block -* `pamixer` for `volume` block ## Installation @@ -102,7 +101,7 @@ markup=pango interval=3 [ip_eth0_ip6] -command=/path/to/ip -iface=eth0 -version=ip6 -name=Bar +command=/path/to/ip -iface=eth0 -version=ip4 -name=Bar format=json markup=pango interval=3 @@ -180,11 +179,9 @@ interval=3 Show volume. -Note: use `pamixer --list-sinks` - ``` [volume] -command=/path/to/volume -sinks="Default:alsa_output.pci-0000_00_1f.3.analog-stereo;Headset:bluez_output.00_1B_66_B6_87_05" +command=/path/to/volume -channel=Master format=json markup=pango interval=1 diff --git a/blocks/acpi/main.go b/blocks/acpi/main.go index 8ddc055..da5aedc 100644 --- a/blocks/acpi/main.go +++ b/blocks/acpi/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "github.com/enescakir/emoji" "github.com/xellio/tools/acpi" r "gitnet.fr/deblan/i3-blocks-go/rendering" @@ -14,6 +13,7 @@ import ( func main() { datas, err := acpi.Battery() + if err != nil { return } diff --git a/blocks/app/main.go b/blocks/app/main.go index f372121..873c9d4 100644 --- a/blocks/app/main.go +++ b/blocks/app/main.go @@ -3,11 +3,10 @@ package main import ( "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "os" "os/exec" "sync" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func runCmd(wg *sync.WaitGroup, value string) { diff --git a/blocks/date/main.go b/blocks/date/main.go index 6a8727a..257772b 100644 --- a/blocks/date/main.go +++ b/blocks/date/main.go @@ -3,11 +3,10 @@ package main import ( "flag" "fmt" - "time" - "github.com/enescakir/emoji" "github.com/itchyny/timefmt-go" r "gitnet.fr/deblan/i3-blocks-go/rendering" + "time" ) func main() { diff --git a/blocks/du/main.go b/blocks/du/main.go index 72e260b..27723eb 100644 --- a/blocks/du/main.go +++ b/blocks/du/main.go @@ -3,13 +3,12 @@ package main import ( "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "os" "os/exec" "strconv" "strings" "sync" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func DiskUsage(path string) int { diff --git a/blocks/ip/main.go b/blocks/ip/main.go index 319c506..1d0d551 100644 --- a/blocks/ip/main.go +++ b/blocks/ip/main.go @@ -3,13 +3,12 @@ package main import ( "flag" "fmt" + "github.com/atotto/clipboard" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "net" "os" "regexp" "strings" - - "github.com/atotto/clipboard" - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func main() { @@ -25,6 +24,7 @@ func main() { ) iface, err := net.InterfaceByName(*argIface) + if err != nil { return } diff --git a/blocks/ip_wan/main.go b/blocks/ip_wan/main.go index eee5cdf..1ff9df0 100644 --- a/blocks/ip_wan/main.go +++ b/blocks/ip_wan/main.go @@ -2,16 +2,16 @@ package main import ( "fmt" + "github.com/atotto/clipboard" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "io" "net/http" "os" - - "github.com/atotto/clipboard" - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func main() { resp, err := http.Get("https://api.ipify.org/") + if err != nil { return } diff --git a/blocks/prusa_telemetry/main.go b/blocks/prusa_telemetry/main.go index 0f3ea01..7898cef 100644 --- a/blocks/prusa_telemetry/main.go +++ b/blocks/prusa_telemetry/main.go @@ -4,13 +4,12 @@ import ( "encoding/json" "flag" "fmt" + "github.com/itchyny/timefmt-go" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "io" "net/http" "strconv" "time" - - "github.com/itchyny/timefmt-go" - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) type Telemetry struct { @@ -25,6 +24,7 @@ func main() { flag.Parse() resp, err := http.Get(*argApi) + if err != nil { return } diff --git a/blocks/ps/main.go b/blocks/ps/main.go index 5c59181..173484d 100644 --- a/blocks/ps/main.go +++ b/blocks/ps/main.go @@ -3,10 +3,9 @@ package main import ( "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "os/exec" "strings" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func ProcessExists(process string) bool { diff --git a/blocks/rss/main.go b/blocks/rss/main.go index c772e3f..9cf38b9 100644 --- a/blocks/rss/main.go +++ b/blocks/rss/main.go @@ -3,14 +3,13 @@ package main import ( "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "io" "net/http" "os" "os/exec" "strings" "sync" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) type Telemetry struct { @@ -42,6 +41,7 @@ func main() { } resp, err := http.Get(*argFeed) + if err != nil { return } diff --git a/blocks/spotify/main.go b/blocks/spotify/main.go index 166ede0..d2bae0e 100644 --- a/blocks/spotify/main.go +++ b/blocks/spotify/main.go @@ -2,10 +2,15 @@ package main import ( "fmt" - "os" - "os/exec" + sos" + "os/" "strings" + r "gitnet.fr/deblan/i3-blocks-gsrrindg + r "gitnet.fr/deblan/i3-blocks-gsrrindg + r "gitnet.fr/deblan/i3-blocks-gsrrindg + r "gitnet.fr/deblan/i3-blocks-gsrrindg + r "gitnet.fr/deblan/i3-blocks-gsrrindg r "gitnet.fr/deblan/i3-blocks-go/rendering" ) diff --git a/blocks/volume/main.go b/blocks/volume/main.go index aa746d3..289d87b 100644 --- a/blocks/volume/main.go +++ b/blocks/volume/main.go @@ -3,68 +3,46 @@ package main import ( "flag" "fmt" - "os/exec" - "strconv" - "strings" - r "gitnet.fr/deblan/i3-blocks-go/rendering" + "os/exec" + "regexp" + "strconv" ) -func Volume(id string) int { - output, _ := exec.Command("pamixer", "--sink", id, "--get-volume").Output() +func Volume(channel string) int { + output, _ := exec.Command("amixer", "get", channel).Output() - volume, _ := strconv.Atoi(strings.TrimSpace(string(output))) + regex, _ := regexp.Compile(`\[(\d+)%\]`) + data := regex.FindStringSubmatch(string(output)) + + volume, _ := strconv.Atoi(data[1]) return volume } func main() { - argSinks := flag.String("sinks", "", "list of sinks, eg: CUSTOM_NAME:SINK_VALUE;CUSTOM_NAME2:SINK_VALUE2") + argChannel := flag.String("channel", "Master", "the channel") flag.Parse() - sinks := strings.Split(*argSinks, ";") + volume := Volume(*argChannel) - var items []string + var symbole string - for _, sink := range sinks { - info := strings.Split(sink, ":") - - if len(info) != 2 { - continue - } - - name := info[0] - id := info[1] - volume := Volume(id) - - var symbole string - - if volume == 0 { - symbole = "\uf026" - } else if volume < 50 { - symbole = "\uf027" - } else { - symbole = "\uf028" - } - - label := r.TextWithPadding( - name, - r.FB{ - Foreground: r.Color("grey1"), - Background: r.Color("black2"), - }, - ) - - value := r.TextWithPadding(fmt.Sprintf("%d%% %s", volume, r.FontAwesome(symbole)), r.FB{ - Foreground: r.Color("grey1"), - Background: r.Color("black1"), - }) - - items = append(items, fmt.Sprintf("%s%s", label, value)) + if volume == 0 { + symbole = "\uf026" + } else if volume < 50 { + symbole = "\uf027" + } else { + symbole = "\uf028" } + value := r.TextWithPadding(fmt.Sprintf("%d%% %s", volume, r.FontAwesome(symbole)), r.FB{ + Foreground: r.Color("grey1"), + Background: r.Color("black1"), + }) + options := r.NewBlockOptions() - options.FullText = strings.Join(items, "") + options.FullText = value block := r.Block("volume", options) fmt.Println(block) diff --git a/blocks/weather/main.go b/blocks/weather/main.go index 3df828d..0784079 100644 --- a/blocks/weather/main.go +++ b/blocks/weather/main.go @@ -3,14 +3,13 @@ package main import ( "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "io" "net/http" "os" "os/exec" "strings" "sync" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func openBrowser(wg *sync.WaitGroup, url string) { @@ -35,6 +34,7 @@ func main() { } resp, err := http.Get(url) + if err != nil { return } diff --git a/blocks/wireguard/main.go b/blocks/wireguard/main.go index caf837a..6ad1056 100644 --- a/blocks/wireguard/main.go +++ b/blocks/wireguard/main.go @@ -3,12 +3,11 @@ package main import ( "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" "net" "os" "os/exec" "strings" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" ) func main() { diff --git a/blocks/workspace_apps/main.go b/blocks/workspace_apps/main.go index 56a8d79..9b348dc 100644 --- a/blocks/workspace_apps/main.go +++ b/blocks/workspace_apps/main.go @@ -2,14 +2,13 @@ package main import ( "encoding/json" - "flag" "fmt" + r "gitnet.fr/deblan/i3-blocks-go/rendering" + // "os" + "flag" "os/exec" "strconv" "strings" - - r "gitnet.fr/deblan/i3-blocks-go/rendering" - // "os" ) type WindowProperty struct { diff --git a/go.mod b/go.mod index 36633d0..413d5cb 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module gitnet.fr/deblan/i3-blocks-go -go 1.22 +go 1.18 require ( github.com/enescakir/emoji v1.0.0