From 8512bb3ecb0e03e8d8f2d0e2c4ce08ca8f694475 Mon Sep 17 00:00:00 2001 From: Blallo Date: Thu, 30 Apr 2020 12:32:48 +0200 Subject: [PATCH] Added sway-screens function --- .zshrc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/.zshrc b/.zshrc index d47d5c2..c7f79e3 100644 --- a/.zshrc +++ b/.zshrc @@ -144,6 +144,85 @@ function reload_work_gpg { kill -9 $(ps aux|egrep "gpg-agent.*work"|grep -v grep|awk '{print $2}') } +function sway-screens { + local screens=$(swaymsg -t get_outputs -r) + local show_active + local show_inactive + local var_style="plain" + local active_screens=() + local inactive_screens=() + + while [ $# -ne 0 ]; do + case $1 in + -a|--active) + show_active=1 + ;; + -n|--inactive) + show_inactive=1 + ;; + -s|--style) + case $2 in + json) + var_style="json" + ;; + plain) + ;; + *) + echo "unknown style ${2}" + return 1 + ;; + esac + shift + ;; + esac + shift + done + + if [ "z${show_active}" != "z" ]; then + for s in $(echo $screens|jq -r '.[] | select(.active) | .name'); do + active_screens+=($s) + done + fi + + if [ "z${show_inactive}" != "z" ]; then + for s in $(echo $screens|jq -r '.[] | select(.active|not) | .name'); do + inactive_screens+=($s) + done + fi + + if [ "${var_style}" = "plain" ]; then + if [ ${#active_screens[@]} -gt 0 ]; then + echo "ACTIVE=${active_screens[@]}" + fi + if [ ${#inactive_screens[@]} -gt 0 ]; then + echo "INACTIVE=${inactive_screens[@]}" + fi + else + local active="" + for s in $active_screens; do + active+="\"$s\"," + done + active=${active%,} + + local inactive="" + for s in $inactive_screens; do + inactive+="\"$s\"," + done + inactive=${inactive%,} + + local content="" + if [ "z${show_active}" != "z" ]; then + content+="\"active\": [${active}]," + fi + if [ "z${show_inactive}" != "z" ]; then + content+="\"inactive\": [${inactive}]," + fi + content=${content%,} + + echo "{${content}}" | jq + fi +} + ## Custom completion # certo eval "$(_CERTO_COMPLETE=source_zsh certo)"