Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 20 additions & 96 deletions tmux/session-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ show_usage() {
Usage: $0 [OPTIONS] [SESSION_TYPE]

Session Types:
main - General purpose session with system monitoring
dev - Development-focused session with project tools
main - btop, home (~ + neo), projects (~/Projects + lls)
dev - btop, home (~ + neo), projects (~/Projects + lls), git (~/Projects)
list - List all active sessions
kill - Kill specified session
killall - Kill all sessions
Expand All @@ -41,113 +41,37 @@ Examples:
EOF
}

# Create main session
# Create main session (aligned with setup-main.sh)
create_main_session() {
local session_name="${MAIN_SESSION}"
log "${session_name}" "Creating main session: ${session_name}"

create_tmux_session "${session_name}"
if ! tmux new-session -d -s "${session_name}" -c "${HOME}" -n 'btop'; then
error_exit "Failed to create tmux session: ${session_name}"
fi

configure_session_options "${session_name}" "green"
create_main_session_windows "${session_name}"

# Window 0: Home/Overview
create_window "${session_name}" "home" 0 "${HOME}" \
"clear" \
'echo "Welcome to Main Session!"' \
'echo "Available commands: htop, nvtop, neofetch"' \
"pwd"

# Window 1: Documentation
create_window "${session_name}" "docs" 1 "${HOME}/Projects/documentation" \
"clear" \
'echo "Documentation workspace"' \
"ls -la"

# Window 2: Projects
create_window "${session_name}" "projects" 2 "${HOME}/Projects" \
"clear" \
'echo "Projects workspace"' \
"ls -la"

# Window 3: System monitoring
create_window "${session_name}" "monitor" 3 "" \
"clear" \
'echo "System monitoring - press Ctrl+C to exit htop"' \
"htop"

# Window 4: Development tools
create_window "${session_name}" "tools" 4 "" \
"clear" \
'echo "Development tools workspace"' \
'echo "Available: git, docker, kubectl, etc."' \
"pwd"

log "${session_name}" "Main session created successfully with 5 windows"
log "${session_name}" "Main session created (windows: btop, home, projects)"
}

# Create development session
# Create development session (aligned with setup-dev.sh)
create_dev_session() {
local session_name="${DEV_SESSION}"
log "${session_name}" "Creating development session: ${session_name}"

create_tmux_session "${session_name}"
if ! tmux new-session -d -s "${session_name}" -c "${HOME}" -n 'btop'; then
error_exit "Failed to create tmux session: ${session_name}"
fi

configure_session_options "${session_name}" "cyan"
create_main_session_windows "${session_name}"

tmux new-window -t "${session_name}" -n 'git' -c "${HOME}/Projects"
prepare_tmux_pane "${session_name}:git" "${HOME}/Projects"

# Window 0: Development Home
create_window "${session_name}" "dev-home" 0 "" \
"clear" \
'echo "Development Session Ready!"' \
'echo "Quick commands: git status, docker ps, kubectl get pods"' \
"pwd"

# Window 1: Active Project (with split panes)
create_window "${session_name}" "project" 1 "${HOME}/Projects" \
"clear" \
'echo "Active project workspace"' \
"ls -la"

# Split the project window horizontally
split_window_horizontal "${session_name}" 1 \
'echo "Right pane - logs, monitoring, etc."' \
"pwd"

# Window 2: Git/Version Control
create_window "${session_name}" "git" 2 "" \
"clear" \
'echo "Git workspace - check status, branches, etc."' \
"git status 2>/dev/null || echo 'Not in a git repository'"

# Window 3: Docker/Containers
create_window "${session_name}" "docker" 3 "" \
"clear" \
'echo "Docker workspace"' \
"docker ps 2>/dev/null || echo 'Docker not running or not installed'"

# Window 4: Testing/CI
create_window "${session_name}" "test" 4 "" \
"clear" \
'echo "Testing workspace"' \
'echo "Run tests, linting, etc. here"' \
"pwd"

# Window 5: Database/Backend
create_window "${session_name}" "db" 5 "" \
"clear" \
'echo "Database workspace"' \
'echo "Connect to databases, run queries, etc."' \
"pwd"

# Window 6: Logs/Monitoring
create_window "${session_name}" "logs" 6 "" \
"clear" \
'echo "Logs and monitoring"' \
'echo "Tail logs, monitor system, etc."' \
"pwd"

# Set up window layout for project window (1)
tmux select-window -t "${session_name}:1"
tmux select-pane -t "${session_name}:1.0"

log "${session_name}" "Development session created successfully with 7 windows"
log "${session_name}" "Development session created (windows: btop, home, projects, git)"
}

# Handle session creation or attachment
Expand All @@ -170,7 +94,7 @@ handle_session() {
error_exit "Unknown session type: ${session_type}"
;;
esac
tmux select-window -t "${session_name}:0"
tmux select-window -t "${session_name}:home"
attach_to_session "${session_name}"
fi
}
Expand Down
126 changes: 19 additions & 107 deletions tmux/setup-dev.sh
Original file line number Diff line number Diff line change
@@ -1,136 +1,48 @@
#!/bin/bash

# Development tmux session setup script
# Creates or reattaches to a development session with development-focused windows
# Development tmux session — main layout plus git (index 3, ~/Projects)

set -euo pipefail # Exit on error, undefined vars, pipe failures
set -euo pipefail

# Configuration
readonly SESSION_NAME='dev'
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly LOG_FILE="${HOME}/.tmux-session-${SESSION_NAME}.log"

# Colors for output
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly NC='\033[0m' # No Color

# Logging function
log() {
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $*" | tee -a "${LOG_FILE}"
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=tmux-utils.sh
source "${SCRIPT_DIR}/tmux-utils.sh"

# Error handling
error_exit() {
echo -e "${RED}Error: $1${NC}" >&2
exit 1
}

# Check if tmux is installed
if ! command -v tmux >/dev/null 2>&1; then
error_exit "tmux is not installed. Please install tmux first."
fi
readonly SESSION_NAME='dev'

# Function to create new session with windows
create_session() {
log "Creating new development tmux session: ${SESSION_NAME}"
log "${SESSION_NAME}" "Creating new tmux session: ${SESSION_NAME}"

# Create detached session
if ! tmux new-session -d -s "${SESSION_NAME}" 2>/dev/null; then
if ! tmux new-session -d -s "${SESSION_NAME}" -c "${HOME}" -n 'btop'; then
error_exit "Failed to create tmux session: ${SESSION_NAME}"
fi

# Configure session options for development
tmux set-option -t "${SESSION_NAME}" -g status on
tmux set-option -t "${SESSION_NAME}" -g status-interval 1
tmux set-option -t "${SESSION_NAME}" -g status-left-length 20
tmux set-option -t "${SESSION_NAME}" -g status-right-length 50
tmux set-option -t "${SESSION_NAME}" -g status-left '#[fg=cyan]#S #[fg=white]| '
tmux set-option -t "${SESSION_NAME}" -g status-right '#[fg=yellow]%Y-%m-%d %H:%M:%S'
tmux set-option -t "${SESSION_NAME}" -g default-terminal "screen-256color"

# Window 0: Development Home
tmux rename-window -t "${SESSION_NAME}:0" 'dev-home'
tmux send-keys -t "${SESSION_NAME}:0" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:0" 'echo "Development Session Ready!"' C-m
tmux send-keys -t "${SESSION_NAME}:0" 'echo "Quick commands: git status, docker ps, kubectl get pods"' C-m
tmux send-keys -t "${SESSION_NAME}:0" 'pwd' C-m

# Window 1: Active Project (with split panes)
tmux new-window -t "${SESSION_NAME}" -n 'project'
tmux send-keys -t "${SESSION_NAME}:1" 'cd "${HOME}/Projects" 2>/dev/null || cd "${HOME}"' C-m
tmux send-keys -t "${SESSION_NAME}:1" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:1" 'echo "Active project workspace"' C-m
tmux send-keys -t "${SESSION_NAME}:1" 'ls -la' C-m

# Split the project window horizontally
tmux split-window -t "${SESSION_NAME}:1" -h
tmux send-keys -t "${SESSION_NAME}:1.1" 'echo "Right pane - logs, monitoring, etc."' C-m
tmux send-keys -t "${SESSION_NAME}:1.1" 'pwd' C-m

# Window 2: Git/Version Control
tmux new-window -t "${SESSION_NAME}" -n 'git'
tmux send-keys -t "${SESSION_NAME}:2" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:2" 'echo "Git workspace - check status, branches, etc."' C-m
tmux send-keys -t "${SESSION_NAME}:2" 'git status 2>/dev/null || echo "Not in a git repository"' C-m

# Window 3: Docker/Containers
tmux new-window -t "${SESSION_NAME}" -n 'docker'
tmux send-keys -t "${SESSION_NAME}:3" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:3" 'echo "Docker workspace"' C-m
tmux send-keys -t "${SESSION_NAME}:3" 'docker ps 2>/dev/null || echo "Docker not running or not installed"' C-m

# Window 4: Testing/CI
tmux new-window -t "${SESSION_NAME}" -n 'test'
tmux send-keys -t "${SESSION_NAME}:4" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:4" 'echo "Testing workspace"' C-m
tmux send-keys -t "${SESSION_NAME}:4" 'echo "Run tests, linting, etc. here"' C-m
tmux send-keys -t "${SESSION_NAME}:4" 'pwd' C-m

# Window 5: Database/Backend
tmux new-window -t "${SESSION_NAME}" -n 'db'
tmux send-keys -t "${SESSION_NAME}:5" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:5" 'echo "Database workspace"' C-m
tmux send-keys -t "${SESSION_NAME}:5" 'echo "Connect to databases, run queries, etc."' C-m
tmux send-keys -t "${SESSION_NAME}:5" 'pwd' C-m

# Window 6: Logs/Monitoring
tmux new-window -t "${SESSION_NAME}" -n 'logs'
tmux send-keys -t "${SESSION_NAME}:6" 'clear' C-m
tmux send-keys -t "${SESSION_NAME}:6" 'echo "Logs and monitoring"' C-m
tmux send-keys -t "${SESSION_NAME}:6" 'echo "Tail logs, monitor system, etc."' C-m
tmux send-keys -t "${SESSION_NAME}:6" 'pwd' C-m
configure_session_options "${SESSION_NAME}" "cyan"
create_main_session_windows "${SESSION_NAME}"

# Set up window layout for project window (1)
tmux select-window -t "${SESSION_NAME}:1"
tmux select-pane -t "${SESSION_NAME}:1.0"
tmux new-window -t "${SESSION_NAME}" -n 'git' -c "${HOME}/Projects"
prepare_tmux_pane "${SESSION_NAME}:git" "${HOME}/Projects"

log "Development session ${SESSION_NAME} created successfully with 7 windows"
log "${SESSION_NAME}" "Session ${SESSION_NAME} created (windows: btop, home, projects, git)"
}

# Function to attach to existing session
attach_session() {
log "Attaching to existing development session: ${SESSION_NAME}"
log "${SESSION_NAME}" "Attaching to existing session: ${SESSION_NAME}"
tmux attach-session -t "${SESSION_NAME}"
}

# Main execution
main() {
log "Starting development tmux session manager for: ${SESSION_NAME}"
log "${SESSION_NAME}" "Starting tmux setup for: ${SESSION_NAME}"
check_tmux_installed

# Check if session exists
if tmux has-session -t "${SESSION_NAME}" 2>/dev/null; then
log "Development session ${SESSION_NAME} already exists"
if session_exists "${SESSION_NAME}"; then
log "${SESSION_NAME}" "Session ${SESSION_NAME} already exists"
attach_session
else
create_session
# Select first window and attach
tmux select-window -t "${SESSION_NAME}:0"
tmux select-window -t "${SESSION_NAME}:home"
attach_session
fi
}

# Run main function
main "$@"
Loading
Loading