Skip to content

Commit a1b4848

Browse files
committed
feat: enhance tmux session management and configuration
1 parent 0c243cc commit a1b4848

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

registry/anomaly/modules/tmux/main.tf

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,53 @@ variable "save_interval" {
2626
default = 1
2727
}
2828

29+
variable "order" {
30+
type = number
31+
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
32+
default = null
33+
}
34+
35+
variable "group" {
36+
type = string
37+
description = "The name of a group that this app belongs to."
38+
default = null
39+
}
40+
41+
variable "icon" {
42+
type = string
43+
description = "The icon to use for the app."
44+
default = "/icon/tmux.svg"
45+
}
46+
47+
variable "sessions" {
48+
type = list(string)
49+
description = "List of tmux sessions to create or start."
50+
default = ["default"]
51+
}
52+
2953
resource "coder_script" "tmux" {
3054
agent_id = var.agent_id
3155
display_name = "tmux"
3256
icon = "/icon/terminal.svg"
33-
script = templatefile("${path.module}/run.sh", {
57+
script = templatefile("${path.module}/scripts/run.sh", {
3458
TMUX_CONFIG = var.tmux_config
3559
SAVE_INTERVAL = var.save_interval
3660
})
3761
run_on_start = true
3862
run_on_stop = false
39-
}
63+
}
64+
65+
resource "coder_app" "tmux_sessions" {
66+
for_each = toset(var.sessions)
67+
68+
agent_id = var.agent_id
69+
slug = "tmux-${each.value}"
70+
display_name = "tmux - ${each.value}"
71+
icon = var.icon
72+
order = var.order
73+
group = var.group
74+
75+
command = templatefile("${path.module}/scripts/start.sh", {
76+
SESSION_NAME = each.value
77+
})
78+
}

registry/anomaly/modules/tmux/run.sh renamed to registry/anomaly/modules/tmux/scripts/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ main() {
142142
install_plugins
143143

144144
printf "$${BOLD}✅ tmux setup complete! \n\n"
145+
146+
printf "$${BOLD} Attempting to restore sessions\n"
147+
tmux new-session -d \; source-file ~/.tmux.conf \; run-shell '~/.tmux/plugins/tmux-resurrect/scripts/restore.sh'
148+
printf "$${BOLD} Sessions restored: -> %s\n" "$(tmux ls)"
149+
145150
}
146151

147152
# Run main function

registry/anomaly/modules/tmux/scripts/start.sh

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Convert templated variables to shell variables
4-
SESSIONS='${SESSIONS}'
4+
SESSION_NAME='${SESSION_NAME}'
55

66
# Function to check if tmux is installed
77
check_tmux() {
@@ -30,29 +30,7 @@ handle_session() {
3030
main() {
3131
# Check if tmux is installed
3232
check_tmux
33-
34-
# If no sessions are specified, create or attach to a default session
35-
if [ "$SESSIONS" = "[]" ] || [ -z "$SESSIONS" ]; then
36-
echo "No sessions specified, using default session..."
37-
handle_session "default"
38-
exit 0
39-
fi
40-
41-
# Parse the JSON array by removing brackets and quotes, then split by commas
42-
# Remove the opening and closing brackets
43-
sessions_str=$${SESSIONS#[}
44-
sessions_str=$${sessions_str%]}
45-
46-
# Remove quotes and split by commas
47-
sessions_str=$(echo "$sessions_str" | sed s/\"//g)
48-
IFS=',' read -ra SESSION_ARRAY <<< "$sessions_str"
49-
50-
# Handle each session
51-
for session in "$${SESSION_ARRAY[@]}"; do
52-
# Trim whitespace
53-
session=$(echo "$session" | sed s/^[[:space:]]*//\;s/[[:space:]]*$//)
54-
handle_session "$session"
55-
done
33+
handle_session "${SESSION_NAME}"
5634
}
5735

5836
# Run the main function

0 commit comments

Comments
 (0)