diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32d43c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin.sysusage diff --git a/cmd/monitor/main.go b/cmd/monitor/main.go index 7a58f27..be2c946 100644 --- a/cmd/monitor/main.go +++ b/cmd/monitor/main.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "os" + "runtime" "strings" "time" @@ -11,39 +12,6 @@ import ( "github.com/shirou/gopsutil/v3/mem" ) -func isSupported() bool { - goos := os.Getenv("TMUX_SYSUSAGE_GOOS") // Debug/Override optional - if goos == "" { - goos = detectGOOS() - } - switch goos { - case "darwin": - return true - case "linux": - id := linuxID() - return id == "ubuntu" || id == "arch" - default: - return false - } -} - -func detectGOOS() string { - // runtime.GOOS vermeiden, um Import minimal zu halten? Es ist Standard—nutzen wir. - // (Minimale Imports sind nice-to-have, aber runtime ist winzig.) - // Wir nehmen ihn doch, weil zuverlässig. - // → Ein einzelner Import mehr ist ok. - return runtimeGOOS() -} - -//go:noinline -func runtimeGOOS() string { - // kleiner Trick: getrennt, damit der Compiler runtime nicht inlined—irrelevant, aber clean. - return getGOOS() -} - -//go:linkname getGOOS runtime.GOOS -func getGOOS() string - func linuxID() string { f, err := os.Open("/etc/os-release") if err != nil { @@ -62,12 +30,22 @@ func linuxID() string { return "" } +func isSupported() bool { + switch runtime.GOOS { + case "darwin": + return true + case "linux": + id := linuxID() + return id == "ubuntu" || id == "arch" + default: + return false + } +} + func main() { if !isSupported() { - // Keine Ausgabe auf nicht unterstützten Systemen return } - // Kurze CPU-Stichprobe values, err := cpu.Percent(400*time.Millisecond, false) if err != nil || len(values) == 0 { return @@ -76,7 +54,6 @@ func main() { if err != nil { return } - // Kompakte tmux-Ausgabe fmt.Printf("CPU %.0f%% | RAM %.0f%%", values[0], vm.UsedPercent) } diff --git a/monitor b/monitor deleted file mode 100755 index a1c8845..0000000 Binary files a/monitor and /dev/null differ diff --git a/plugin.tmux b/plugin.tmux old mode 100644 new mode 100755 index 07c3894..01c8720 --- a/plugin.tmux +++ b/plugin.tmux @@ -1,12 +1,14 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# tmux bind-key T run-shell "$CURRENT_DIR/scripts/tmux_list_plugins.sh" + + # Binary bauen (still). Wenn go fehlt: überspringen -run-shell "cd '#{plugin_path}' && GO111MODULE=on go mod tidy >/dev/null 2>&1 || true" -run-shell "cd '#{plugin_path}' && GO111MODULE=on go build -ldflags='-s -w' -o bin.sysusage ./cmd/monitor >/dev/null 2>&1 || true" +tmux run-shell "cd $CURRENT_DIR && GO111MODULE=on go mod tidy >/dev/null 2>&1 || true" +tmux run-shell "cd $CURRENT_DIR && GO111MODULE=on go build -ldflags='-s -w' -o bin.sysusage ./cmd/monitor >/dev/null 2>&1 || true" # tmux-Variable setzen: #{sysusage} -set -g @sysusage_cmd '#{plugin_path}/bin.sysusage' -set -g status-interval 2 - -# Du kannst später im Theme einfach schreiben: -# set -g status-right "... #{sysusage} ..." -set -g -F @sysusage '#(@sysusage_cmd)' +tmux set -g @sysusage_cmd "$CURRENT_DIR/bin.sysusage" +tmux set -g status-interval 2