The Barista Logo

barista

An i3status alternative in golang

Download sample-bar Download i3status example View on GitHub

Shell

godoc
import "barista.run/modules/shell"

Show the output of a shell command on the bar: shell.New("sh", "-c", "whoami").
Show the last line of output from a long-running shell command: shell.Tail("dmesg").

Configuration

Examples

8 chrome procs

Show a count of chrome processes, refreshed every second:

chromeCount := shell.New("pgrep", "-c", "chrome").
	Every(time.Second).
	Output(func(count string) bar.Output {
		return outputs.Textf("%s chrome procs", count)
	})
(22m15s ago) wlp60s0: associated

Show the last line of dmesg output, with human readable time deltas:

var dmesgFormat = regexp.MustCompile(`^\[([0-9\.]+)\] (.*)$`)
dmesg := shell.Tail("dmesg", "-w").Output(func(line string) bar.Output {
	res := dmesgFormat.FindStringSubmatch(line) // res[1] = time, res[2] = message
	timeOfMsg, _ := strconv.ParseFloat(res[1], 64)
	outLine := res[2]
	if len(outLine) > 20 {
		outLine = outLine[0:19] + "…"
	}

	return outputs.Repeat(func(time.Time) bar.Output {
		uptimeStr, _ := ioutil.ReadFile("/proc/uptime") // uptimeStr = "$uptime $cputime"
		timeNow, _ := strconv.ParseFloat(strings.Split(string(uptimeStr), " ")[0], 64)
		delta := time.Duration(uint64(timeNow-timeOfMsg)) * time.Second
		return outputs.Textf("(%v ago) %s", delta, outLine)
	}).Every(time.Second)
})