fixes
This commit is contained in:
		| @@ -1,18 +1,17 @@ | ||||
| MAX_TITLE_LENGTH=600 | ||||
|  | ||||
| get_windows_with_workspace() { | ||||
|     swaymsg -t get_tree | jq -r --arg max_len "$MAX_TITLE_LENGTH" ' | ||||
|         def get_workspace_name(node): | ||||
|             if node.type == "workspace" then node.name | ||||
|             elif node.parent then get_workspace_name(node.parent) | ||||
|             else "Unknown" end; | ||||
|     swaymsg -t get_tree | jq -r ' | ||||
|         def calc_ws_name(ws_name): | ||||
|             if ws_name == "__i3_scratch" then "_" | ||||
|             elif (ws_name | test("^[0-9]+:")) then (ws_name | sub("^[0-9]+:"; "")) | ||||
|             else ws_name | ||||
|             end; | ||||
|  | ||||
|         def get_windows(workspace_name): | ||||
|             if .type == "con" and .pid != null and (.name // "") != "" then | ||||
|             if (.type == "con" or .type == "floating_con") and .pid != null and (.name // "") != "" then | ||||
|                 { | ||||
|                     id: .id, | ||||
|                     name: .name, | ||||
|                     app_id: (.app_id // .window_properties.class // "Unknown"), | ||||
|                     name: .name | ascii_downcase, | ||||
|                     app_id: (.app_id // .window_properties.class // "unknown") | ascii_downcase, | ||||
|                     workspace: workspace_name, | ||||
|                     focused: .focused | ||||
|                 } | ||||
| @@ -20,37 +19,32 @@ get_windows_with_workspace() { | ||||
|             (.nodes[]? | get_windows(workspace_name)), | ||||
|             (.floating_nodes[]? | get_windows(workspace_name)); | ||||
|  | ||||
|         def get_workspaces: | ||||
|         def traverse_all: | ||||
|             if .type == "workspace" then | ||||
|                 . as $ws | .name as $ws_name | get_windows($ws_name) | ||||
|                 . as $ws | (.name | calc_ws_name(.)) as $ws_name | get_windows($ws_name) | ||||
|             else empty end, | ||||
|             (.nodes[]? | get_workspaces); | ||||
|             (.nodes[]? | traverse_all); | ||||
|  | ||||
|         get_workspaces | | ||||
|         traverse_all | | ||||
|         "\(.id)|\(.app_id)|\(.name)|\(.workspace)|\(.focused)" | ||||
|     ' | ||||
| } | ||||
| window_list=$(get_windows_with_workspace) | ||||
|  | ||||
| formatted_list=$(echo "$window_list" | while IFS='|' read -r id app_id name workspace focused; do | ||||
|     if [ ${#name} -gt $MAX_TITLE_LENGTH ]; then | ||||
|         truncated_name="${name:0:$((MAX_TITLE_LENGTH-3))}..." | ||||
|     else | ||||
|         truncated_name="$name" | ||||
|     fi | ||||
|     if [ "$focused" = "true" ]; then | ||||
|         indicator="> " | ||||
|     else | ||||
|         indicator="  " | ||||
|     fi | ||||
|  | ||||
|     printf "[%s/%s]%s %s: %s\n" "$workspace" "$id" "$indicator" "$app_id" "$truncated_name" | ||||
|     printf "%s%s%s %s %s\n" "$workspace" "$indicator" "$id" "$app_id" "$name" | ||||
| done) | ||||
|  | ||||
| selection=$(echo "$formatted_list" | bemenu --prompt "/" --index "$(echo "$formatted_list" | awk '/]>/ {print NR-1 ":" $0}')" ) | ||||
| selection=$(echo "$formatted_list" | bemenu --width-factor 100 --prompt "/" --index "$(echo "$formatted_list" | awk 'substr($0,2,1)==">" {print NR-1}')" ) | ||||
| [ -z "$selection" ] && exit 0 | ||||
|  | ||||
| window_id=$(echo "$selection" | sed 's/.*\/\([^]]*\)].*/\1/') | ||||
| window_id=$(echo "$selection" | sed -E 's/^...([0-9]+).*/\1/') | ||||
|  | ||||
| if [ -n "$window_id" ]; then | ||||
|     swaymsg "[con_id=\"$window_id\"] focus" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user