Colima

Controls the Colima container runtime

Image preview of Colima plugin.

colima.10s.sh

Edit
Open on GitHub
#!/usr/bin/env bash

# <xbar.title>Colima</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Bill Havanki</xbar.author>
# <xbar.author.github>bhavanki</xbar.author.github>
# <xbar.desc>Controls the Colima container runtime</xbar.desc>
# <xbar.image>https://i.imgur.com/jnM0aMI.png</xbar.image>
# <xbar.dependencies>bash,docker,colima</xbar.dependencies>
# <xbar.abouturl>https://github.com/abiosoft/colima</xbar.abouturl>
# <xbar.var>number(MEMORY=2): Memory in GiB</xbar.var>

PATH=/usr/local/bin:$PATH
COLIMA=$(command -v colima)
DOCKER=$(command -v docker)

# https://en.wikipedia.org/wiki/Magdalena_rat
RAT_ICON=iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAYAAAAehFoBAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAlmVYSWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSATEAAgAAABEAAABah2kABAAAAAEAAABsAAAAAAAAAJAAAAABAAAAkAAAAAF3d3cuaW5rc2NhcGUub3JnAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAALKADAAQAAAABAAAALAAAAABAa5naAAAACXBIWXMAABYlAAAWJQFJUiTwAAADCGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aW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Qo+egFakDdOzdXrPWMTjjEJ/B2HqtJth+TFcXhftpRYJuRoOfCXYVas/CLGT7KzRAj0ctr/v+CP1S5nfSPgSVJTF1//GzPY3QifOgGDbg6F2EzQ9QH1morp7y+ahddLRNkp/Sz8vfr/AHCM1qBRSex/mQyno1ZaFUKuNRW4NM4AnYa3BlCSZHo6dkJhH0MymK7SZ6vlhxnIVGDXKQfny+045No/eqqOYLODuwDRttx63soKDjOz/tvWO4l0V3wlRuUMA5t5eUYFOFQYuOM+d5zvuwjn4Pb/HU6ZpmOPAMJ6ncCPs7YOPytrF9xPjc3tftAP/OEqliM5p5quuZPQbmWyPHY0Zr4Xsp0sW4Xqr7C6AZ7IL5oM5VgqiPBHcSklQ226X9/mJ9LCYN4mW4GR4H/aAWboOZWW2vsLR0J/zucGy1B513phcEruFa4symab74/cvAKm2H/j3WBc+5f+Wmmia20FX2N6H9K5lz/KjRW0kzWAI3wWuh2Aa3wq+gVfW/NpdDocw/a/L7r71JuGM5OnR7UJ6dMLlUy0nlUhvbWpdhDzl+HtMdRda/0hxfCl+FqWLdeqNsgAZqtT1CP8NaxwpJF7J1LrJar903Efk0nILT0M/QWXrJHHk/y1RgLTI/PKzuj9Cf8PdhGwau7pXweuj3b42fGCwrAiu0Bfpe7Ib6Ox/eCYPH6Wwog2Npb4NXQNfvHQnaWcgLZWZdcDErZrIyCdLtfY9M0vqh7lG7AVolq/YY/BK6gx/BGsczuBfuge7Yg9CEhoaBtG8Jx8rb8PyZpOzCdQjdpdVwPXQ3tDHx2k7ZUlgjenU89fzY/Tp4A0qC9gfBYgT6+FeRYAxkrl0yQJNLgo4XsViBxQr8FyrwN+Wv0E/7UWGlAAAAAElFTkSuQmCC


icon=$RAT_ICON
running=2
if [[ -n $COLIMA ]]; then
  colima_status=$("$COLIMA" status 2>&1)
  if [[ $colima_status =~ "colima is running" ]]; then
    icon=$RAT_ICON_ON
    running=0
  elif [[ $colima_status =~ "colima is not running" ]]; then
    icon=$RAT_ICON_OFF
    running=1
  fi
fi

echo "| templateImage=${icon}"
echo '---'
if [[ -z $COLIMA ]]; then
  echo "Colima not found"
  exit
fi
# Set custom mounts with --mount /path/to/mount
echo -n 'Start Colima | shell="'"$COLIMA"'" param1=start param2=--memory param3='"$MEMORY"' terminal=true'
if (( running == 0 )); then
  echo " disabled=true"
else
  echo
fi
echo -n 'Stop Colima | shell="'"$COLIMA"'" param1=stop terminal=true'
if (( running == 1 )); then
  echo " disabled=true"
else
  echo
fi

if (( running == 0 )); then
  containers=()
  while IFS= read -r line; do
    containers+=( "$line" )
  done < <("$DOCKER" ps --format '{{.Names}} {{.ID}}' | sort)

  echo "Containers"
  if (( ${#containers[@]} == 0 )); then
    echo "-- none"
  else
    for c in "${containers[@]}"; do
      echo -n "-- ${c}"
      if [[ -n $DOCKER ]]; then
        echo '| shell="'"$DOCKER"'" param1=logs param2="'"${c##* }"'" param3="-f" terminal=true'
      fi
    done
  fi
fi

echo "$("$COLIMA" version | grep 'colima version') | disabled=true"