Commit 6fcf429bc218
Changed files (1)
pkgs
my
scripts
bin
pkgs/my/scripts/bin/shpool-connect
@@ -3,10 +3,25 @@
#
# Features:
# - Lists available hosts from SSH config (detects shpool-enabled hosts)
-# - Lists sessions on selected host
+# - Lists sessions on selected host (shows connected/disconnected status)
# - Attaches to selected session using kitty (wayland) or current terminal
+# - Handles already-attached sessions (force detach/attach)
set -euo pipefail
+# Error handler - show error and wait for user input before exiting
+error_handler() {
+ local exit_code=$?
+ local line_no=$1
+ if [[ $exit_code -ne 0 ]]; then
+ echo ""
+ echo "Error on line $line_no: Command exited with status $exit_code"
+ echo "Press Enter to close..."
+ read -r
+ fi
+ exit $exit_code
+}
+trap 'error_handler $LINENO' ERR
+
# Extract shpool-enabled hosts from SSH config
# These are hosts with the pattern "host/*" (shpool session aliases)
get_shpool_hosts() {
@@ -64,19 +79,30 @@ if [[ -z "$selected_host" ]]; then
exit 0
fi
-# Step 2: Get sessions on the host
-sessions=$(ssh "$selected_host" shpool list 2>/dev/null | tail -n +2 | awk '{print $1}')
+# Step 2: Get sessions on the host with status
+# Format: "session-name (status)" where status is connected/disconnected
+session_list=$(ssh "$selected_host" shpool list 2>/dev/null | tail -n +2 | awk '{
+ status = $3
+ if (status == "connected") {
+ print $1 " (attached)"
+ } else {
+ print $1
+ }
+}')
-if [[ -z "$sessions" ]]; then
+if [[ -z "$session_list" ]]; then
notify "shpool" "No sessions on $selected_host"
exit 0
fi
# Add option to create new session
-sessions="[new session]"$'\n'"$sessions"
+sessions="[new session]"$'\n'"$session_list"
selected_session=$(echo "$sessions" | select_item "Session on $selected_host: ")
+# Strip status suffix if present (e.g., "session (attached)" -> "session")
+selected_session="${selected_session% (attached)}"
+
if [[ -z "$selected_session" ]]; then
exit 0
fi