From 2d8c60e8e1c06f87686bbd999f359e27cb7cd0ef Mon Sep 17 00:00:00 2001 From: RhiobeT Date: Tue, 10 Mar 2020 15:58:05 +0100 Subject: [PATCH] Fix workspace renaming script We can just kindly ask for the current workspace :shrug: --- .config/sway/workspace-rename.sh | 52 ++++++++++++++------------------ 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/.config/sway/workspace-rename.sh b/.config/sway/workspace-rename.sh index 0d56f11..3c6d58e 100755 --- a/.config/sway/workspace-rename.sh +++ b/.config/sway/workspace-rename.sh @@ -1,36 +1,28 @@ -#!/bin/bash +#!/bin/sh -workspace_num=-1 -workspace_name="" +swaymsg -t subscribe -m '[ "window" ]' | while read -r event ; do + if [ "$(jq -r '.change' <<< $event)" = 'focus' ] ; then + current_workspace="$(swaymsg -t get_workspaces | jq -r '.[] | select(.focused)')" + workspace_num="$(jq -r '.num' <<< $current_workspace)" + workspace_name="$(jq -r '.name' <<< $current_workspace)" -swaymsg -t subscribe -m '[ "workspace", "window" ]' | while IFS= read -r event ; do - if [ "$(jq -r '.change' <<< $event)" == 'focus' ] ; then - if [ "$(jq -r '.container' <<< $event)" == 'null' ] ; then - # Workspace - workspace_num="$(jq -r '.current.num' <<< $event)" - workspace_name="$(jq -r '.current.name' <<< $event)" - elif [ workspace_num != -1 ] ; then - # Window - app_name="$(jq -r '.container.app_id' <<< $event)" - if [ $app_name == 'null' ] ; then - app_name="$(jq -r '.container.window_properties.instance' <<< $event)" - fi + app_name="$(jq -r '.container.app_id' <<< $event)" + if [ $app_name = 'null' ] ; then + app_name="$(jq -r '.container.window_properties.instance' <<< $event)" + fi - if [ "$app_name" == "kitty" ] ; then - app_name="" - elif [ "$app_name" == "chromium" ] ; then - app_name="" - elif [ "$app_name" == "discord" ] ; then - app_name="" - elif [ "$app_name" == "spotify" ] ; then - app_name="" - elif [ "$app_name" == "GEMOC Studio" ] ; then - app_name="" - fi + if [ "$app_name" = "kitty" ] ; then + app_name="" + elif [ "$app_name" = "chromium" ] ; then + app_name="" + elif [ "$app_name" = "discord" ] ; then + app_name="" + elif [ "$app_name" = "spotify" ] ; then + app_name="" + elif [ "$app_name" = "GEMOC Studio" ] ; then + app_name="" + fi - new_workspace_name="$workspace_num:$app_name" - swaymsg rename workspace "$workspace_name" to "$new_workspace_name" - workspace_name="$new_workspace_name" - fi + swaymsg rename workspace "$workspace_name" to "$workspace_num:$app_name" fi done