Skip to content

Instantly share code, notes, and snippets.

@ondrasek
Created July 7, 2023 07:43
Show Gist options
  • Save ondrasek/cfb48eb0e46509033ac069bd8f5fec8d to your computer and use it in GitHub Desktop.
Save ondrasek/cfb48eb0e46509033ac069bd8f5fec8d to your computer and use it in GitHub Desktop.
xbar lima desktop
#!/usr/bin/env zsh
# <xbar.title>lima docker vm status</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Ondrej Krajicek</xbar.author>
# <xbar.author.github>ondrasek</xbar.author.github>
# <xbar.desc>Shows lima docker VM status and CPU usage, with the option to start or stop it.</xbar.desc>
# <xbar.image></xbar.image>
# !xbar.dependencies>zsh</xbar.dependencies>
NAME=docker
VMNAME=VirtualMachine # Virtual Machine Service on MacOS
LIMACTL=/opt/homebrew/bin/limactl
CPUTHR=5.0
STATUS=${$($LIMACTL list $NAME --format="{{.Status}}")##*( )}
VMTYPE=${$($LIMACTL list $NAME --format="{{.VMType}}")##*( )}
CPU=$(ps -p $(pgrep $VMNAME) -o %cpu | tail -n 1)
if (( $CPU <= $CPUTHR )); then
CPU=""
else
CPU=$CPU"%"
fi
if [[ $STATUS == *Running* ]]; then
echo $NAME "($VMTYPE)$CPU"
else
echo X
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment