This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / workspace-manager / workspace-on-new.sh
1.7 kB 57 lines
1#!/usr/bin/env bash 2# Called by workspace-manager-daemon when entering a workspace for the first time. 3# Shows a rofi menu to restore saved session or start fresh. 4# Arguments: $1 = workspace name 5 6set -euo pipefail 7 8WORKSPACES_DIR="${HOME}/workspaces" 9WS_NAME="$1" 10CONFIG_FILE="${WORKSPACES_DIR}/${WS_NAME}.json" 11 12# No config file — nothing to restore, proceed silently 13if [ ! -f "$CONFIG_FILE" ]; then 14 exit 0 15fi 16 17config=$(cat "$CONFIG_FILE") 18 19directory=$(echo "$config" | jq -r '.directory // empty') 20on_create=$(echo "$config" | jq -r '.on_create // []') 21layout=$(echo "$config" | jq -r '.layout // []') 22 23on_create_count=$(echo "$on_create" | jq 'length') 24layout_count=$(echo "$layout" | jq 'length') 25 26# Nothing meaningful in config — proceed silently 27if [ "$on_create_count" -eq 0 ] && [ "$layout_count" -eq 0 ] && [ -z "$directory" ]; then 28 exit 0 29fi 30 31# Build preview of what can be restored 32preview="" 33if [ -n "$directory" ]; then 34 preview="Directory: ${directory}\n" 35fi 36if [ "$on_create_count" -gt 0 ]; then 37 cmds=$(echo "$on_create" | jq -r '.[]' | sed 's/^/ /') 38 preview="${preview}Commands (${on_create_count}):\n${cmds}\n" 39fi 40if [ "$layout_count" -gt 0 ]; then 41 apps=$(echo "$layout" | jq -r '.[].app_id // .[].class // "unknown"' | sort -u | sed 's/^/ /') 42 preview="${preview}Saved windows (${layout_count}):\n${apps}\n" 43fi 44 45choice=$(echo -e "Restore session\nNew session" | \ 46 rofi -dmenu -p "Workspace: ${WS_NAME}" -mesg "$(echo -e "$preview")") 47 48case "$choice" in 49 "Restore session") 50 # Exit 0 — daemon will run on_create, Firefox will restore tabs 51 exit 0 52 ;; 53 "New session"|"") 54 # Exit 1 — daemon will skip on_create, Firefox won't restore tabs 55 exit 1 56 ;; 57esac