diff options
| author | Julian Hurst <julian.hurst92@gmail.com> | 2020-07-11 01:27:10 +0200 |
|---|---|---|
| committer | Julian Hurst <julian.hurst92@gmail.com> | 2020-07-11 01:27:10 +0200 |
| commit | c15493633d9dd660939ba26b633649f08e64cabd (patch) | |
| tree | 8f7b2710f52fb0289ad0529433f554eb3404c471 | |
| parent | 0fac42e5bcbe4550a17c10162d72ea44ffa5bcdb (diff) | |
| download | statusbar-c15493633d9dd660939ba26b633649f08e64cabd.tar.gz | |
Add hostname support
| -rw-r--r-- | statusbar.conf | 5 | ||||
| -rw-r--r-- | statusbar.go | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/statusbar.conf b/statusbar.conf index 5bbf600..f7ac5cb 100644 --- a/statusbar.conf +++ b/statusbar.conf @@ -1,8 +1,11 @@ # from left to right -sections = [ "music", "battery", "ip", "mounts", "clock" ] +sections = [ "music", "battery", "ip", "mounts", "hostname", "clock" ] delay = 10 separator = " | " +[hostname] +label = "hostname: " + [ip] label = "IP: " interfaces = [ "eno1" ] diff --git a/statusbar.go b/statusbar.go index 29d6846..cc810bd 100644 --- a/statusbar.go +++ b/statusbar.go @@ -36,6 +36,7 @@ type Config struct { Music MusicConfig Clock ClockConfig Battery BatteryConfig + Hostname HostnameConfig } type IPConfig struct { @@ -68,6 +69,10 @@ type BatteryConfig struct { SubLabel string `toml:"sublabel"` } +type HostnameConfig struct { + Label string +} + func diskSizes(config MountConfig) string { var b strings.Builder var statfs syscall.Statfs_t @@ -302,6 +307,17 @@ func buildBattery(config BatteryConfig) string { return b.String() } +func buildHostname(config HostnameConfig) string { + var b strings.Builder + b.WriteString(config.Label) + hostname, err := os.Hostname() + if err != nil { + panic(err) + } + b.WriteString(hostname) + return b.String() +} + func getDefaultConfigPath() string { return "/etc/statusbar.conf" } @@ -351,6 +367,8 @@ func main() { b.WriteString(buildMusic(config.Music)) case "battery": b.WriteString(buildBattery(config.Battery)) + case "hostname": + b.WriteString(buildHostname(config.Hostname)) default: } if i < len(config.Sections) - 1 { |
