forked from
lass.pds.lassul.us/superconfig
This repository has no description
2.1 kB
90 lines
1#!/usr/bin/env bash
2# Workspace Manager CLI
3# Queries the workspace-manager-daemon for current workspace and directory info
4
5set -euo pipefail
6
7RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
8SOCKET_PATH="$RUNTIME_DIR/workspace-manager/socket"
9
10usage() {
11 echo "Usage: workspace-manager <command>"
12 echo ""
13 echo "Commands:"
14 echo " dir Print the directory for the current workspace"
15 echo " workspace Print the current workspace name"
16 echo " status Check if daemon is running and print status"
17 echo " help Show this help message"
18 exit 1
19}
20
21query_daemon() {
22 local command="$1"
23 if [[ ! -S "$SOCKET_PATH" ]]; then
24 echo "Error: Daemon not running (socket not found)" >&2
25 return 1
26 fi
27
28 # Send command and read response
29 response=$(echo "$command" | socat - "UNIX-CONNECT:$SOCKET_PATH" 2>/dev/null)
30 if [[ -z "$response" ]]; then
31 echo "Error: No response from daemon" >&2
32 return 1
33 fi
34
35 echo "$response"
36}
37
38cmd_dir() {
39 response=$(query_daemon "dir") || exit 1
40 echo "$response" | jq -r '.directory // empty'
41}
42
43cmd_workspace() {
44 response=$(query_daemon "workspace") || exit 1
45 echo "$response" | jq -r '.workspace // empty'
46}
47
48cmd_status() {
49 if [[ ! -S "$SOCKET_PATH" ]]; then
50 echo "Daemon is not running"
51 exit 1
52 fi
53
54 response=$(query_daemon "status") || exit 1
55 running=$(echo "$response" | jq -r '.running // false')
56
57 if [[ "$running" == "true" ]]; then
58 workspace=$(echo "$response" | jq -r '.workspace // "unknown"')
59 directory=$(echo "$response" | jq -r '.directory // "unknown"')
60 echo "Daemon is running"
61 echo " Workspace: $workspace"
62 echo " Directory: $directory"
63 else
64 echo "Daemon is not responding properly"
65 exit 1
66 fi
67}
68
69if [[ $# -lt 1 ]]; then
70 usage
71fi
72
73case "$1" in
74 dir)
75 cmd_dir
76 ;;
77 workspace)
78 cmd_workspace
79 ;;
80 status)
81 cmd_status
82 ;;
83 help|--help|-h)
84 usage
85 ;;
86 *)
87 echo "Unknown command: $1" >&2
88 usage
89 ;;
90esac