swaybar_info/README.md
Stephen Seo 7bba60e323 Impl 0.1.5 of swaybar_info
Implemented `--netdev_width=<width>` which sets the minimum width of the netdev
byte/KiB/MiB text displays.

Implemented `--netgraph_max_bytes=<bytes>` which displays a graph in text using
Unicode "Block Elements" symbols. The `<bytes>` argument determines the maximum
amount of bytes that will determine which block-character is printed on the
interval. The graph is always 10 characters wide, and the right side is the
most-recent side. Note that this always checks against the maximum of either
download or upload rates. For example, if `<bytes>` is set to 1024, and 128
bytes were downloaded and 512 bytes were uploaded in an interval, the "Lower
Half Block" Unicode symbol will be emitted (exactly half).

SwaybarObject was changed to use an `Option<String>` instead of an `Option<u16>`
for `min_width`.
2022-10-18 21:04:28 +09:00

4.2 KiB

swaybar_info

swaybar_info crates.io version badge swaybar_info license badge

swaybar_info preview image

About

swaybar_info is a program to be utilized by swaybar that is used by the Sway tiling Wayland compositor.

Changes in What Version

See the Changelog.md for details.

Help Text

Usage:
  -h | --help                                       Prints help
  --netdev=<device_name>                            Check network traffic on specified device
  --netdev_width=<width>                            Sets the min-width of the netdev output (default 10)
  --netgraph_max_bytes=<bytes>                      Enable "graph" output when polling network traffic
  --interval-sec=<seconds>                          Output at intervals of <seconds> (default 5)
  --acpi-builtin                                    Use "acpi -b" built-in fetching (battery info, with color)
  --regex-cmd=<cmd>[SPLIT]<args...>[SPLIT]<regex>   Use an output of a command as a metric
  --time-format=<date format string>                Set the format string for the date

Usage

# build the "release" build of the program
cargo build --release
# put the "release" build somewhere to be used by swaybar
cp ./target/release/swaybar_info ~/.config/sway/

# Alternatively, get it from crates.io/
cargo install swaybar_info
# The `swaybar_info` binary should be placed in $HOME/.cargo/bin/

Put the following in your ~/.config/sway/config (assuming the binary is at $HOME/.config/sway/swaybar_info):

bar {
    position top
    # Set --netdev=<device> such that <device> is the network device you
    # want to monitor. You can omit --netdev=<device>, but that will also
    # cause the program to omit network traffic stats.
    status_command $HOME/.config/sway/swaybar_info --netdev=enp7s0

    # A "built-in" for "acpi -b" is available, and can be activated with the
    # --acpi-builtin flag:

    #status_command $HOME/.config/sway/swaybar_info --acpi-builtin

    # One can use the "--regex-cmd=<cmd>[SPLIT]<args...>[SPLIT]<regex>" option like so:

    #status_command $HOME/.config/sway/swaybar_info --regex-cmd="acpi[SPLIT]-b[SPLIT][0-9]+%.*"

    # This example gets battery info into the bar.
    # Multiple args should be separated with "[SPLIT]".
    # Note that the <args...> portion is optional.


    # The following uses 24 hour time
    #status_command $HOME/.config/sway/swaybar_info --time-format="%Y-%m-%d %R:%S"
}

Advanced Usage of --regex-cmd

If the regex provided to swaybar_info has two captures, the first capture will be used as the text to be displayed, and the second capture will be expected to be the color string (such as FFFFFF for white, or 44FF44 for a lighter green).

For example, if the script invoked with --regex-cmd has output like the following:

MPD Title | MPD Album | playingCOLORSPLIT44FF44

That sometimes becomes:

MPD is not running

Then this text can be parsed with a regex like:

status_command $HOME/.config/sway/swaybar_info \
'--regex-cmd=$HOME/scripts/mpc/mpcCommand.sh[SPLIT]simple[SPLIT]^\(.\*?\)\(?:COLORSPLIT\([A-F0-9]{6}\)\)?$'

Note that some characters like * or ( had to be escaped because they are being passed verbatim to a shell.

If only one capture is used in the regex string, then that capture will be used for the output text, and the color will be left unspecified (usually defaulting to white).

For a reference of what kind of regex is supported, see this page.

Dependencies

Uses serde_json, serde, chrono, and regex.