Added sway-screens function

This commit is contained in:
Blallo 2020-04-30 12:32:48 +02:00
parent 8bb1fb8a3b
commit 8512bb3ecb
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

79
.zshrc
View file

@ -144,6 +144,85 @@ function reload_work_gpg {
kill -9 $(ps aux|egrep "gpg-agent.*work"|grep -v grep|awk '{print $2}') 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 ## Custom completion
# certo # certo
eval "$(_CERTO_COMPLETE=source_zsh certo)" eval "$(_CERTO_COMPLETE=source_zsh certo)"