Skip to content

Commit b3680df

Browse files
committed
feat: replace echo with printf
- better logs
1 parent 3e894dc commit b3680df

File tree

1 file changed

+25
-70
lines changed
  • registry/anomaly/modules/tmux

1 file changed

+25
-70
lines changed

registry/anomaly/modules/tmux/run.sh

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

3+
BOLD='\033[0;1m'
4+
35
# Convert templated variables to shell variables
4-
SESSION_NAME="${SESSION_NAME}"
5-
STARTUP_COMMAND="${STARTUP_COMMAND}"
66
SAVE_INTERVAL="${SAVE_INTERVAL}"
77
TMUX_CONFIG="${TMUX_CONFIG}"
88

99
# Function to install tmux
1010
install_tmux() {
11-
echo "Checking for tmux installation..."
11+
printf "Checking for tmux installation\n"
1212

1313
if command -v tmux &> /dev/null; then
14-
echo "tmux is already installed"
14+
printf "tmux is already installed \n\n"
1515
return 0
1616
fi
1717

18-
echo "Installing tmux..."
18+
printf "Installing tmux \n\n"
1919

2020
# Detect package manager and install tmux
2121
if command -v apt-get &> /dev/null; then
@@ -32,47 +32,51 @@ install_tmux() {
3232
elif command -v brew &> /dev/null; then
3333
brew install tmux
3434
else
35-
print_error "No supported package manager found. Please install tmux manually."
35+
printf "No supported package manager found. Please install tmux manually. \n"
3636
exit 1
3737
fi
3838

39-
echo "tmux installed successfully"
39+
printf "tmux installed successfully \n"
4040
}
4141

4242
# Function to install Tmux Plugin Manager (TPM)
4343
install_tpm() {
4444
local tpm_dir="$HOME/.tmux/plugins/tpm"
4545

4646
if [ -d "$tpm_dir" ]; then
47-
echo "TPM is already installed"
47+
printf "TPM is already installed"
4848
return 0
4949
fi
5050

51-
echo "Installing Tmux Plugin Manager (TPM)..."
51+
printf "Installing Tmux Plugin Manager (TPM) \n"
5252

5353
# Create plugins directory
5454
mkdir -p "$HOME/.tmux/plugins"
5555

5656
# Clone TPM repository
5757
if command -v git &> /dev/null; then
5858
git clone https://github.com/tmux-plugins/tpm "$tpm_dir"
59-
echo "TPM installed successfully"
59+
printf "TPM installed successfully"
6060
else
61-
print_error "Git is not installed. Please install git to use tmux plugins."
61+
printf "Git is not installed. Please install git to use tmux plugins. \n"
6262
exit 1
6363
fi
6464
}
6565

6666
# Function to create tmux configuration
6767
setup_tmux_config() {
68-
echo "Setting up tmux configuration..."
68+
printf "Setting up tmux configuration \n"
6969

7070
local config_dir="$HOME/.tmux"
7171
local config_file="$HOME/.tmux.conf"
7272

7373
mkdir -p "$config_dir"
7474

75-
cat > "$config_file" << EOF
75+
if [ -n "$TMUX_CONFIG" ]; then
76+
printf "$TMUX_CONFIG" > "$config_file"
77+
printf "$${BOLD}Custom tmux configuration applied at {$config_file} \n\n"
78+
else
79+
cat > "$config_file" << EOF
7680
# Tmux Configuration File
7781
7882
# =============================================================================
@@ -102,75 +106,30 @@ bind C-r run-shell "~/.tmux/plugins/tmux-resurrect/scripts/restore.sh"
102106
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
103107
run '~/.tmux/plugins/tpm/tpm'
104108
EOF
105-
106-
echo "tmux configuration created at $config_file"
109+
printf "tmux configuration created at {$config_file} \n\n"
110+
fi
107111
}
108112

109113
# Function to install tmux plugins
110114
install_plugins() {
111-
echo "Installing tmux plugins..."
115+
printf "Installing tmux plugins"
112116

113117
# Check if TPM is installed
114118
if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then
115-
print_error "TPM is not installed. Cannot install plugins."
119+
printf "TPM is not installed. Cannot install plugins. \n"
116120
return 1
117121
fi
118122

119123
# Install plugins using TPM
120124
"$HOME/.tmux/plugins/tpm/bin/install_plugins"
121125

122-
echo "tmux plugins installed successfully"
123-
}
124-
125-
# Function to start tmux session
126-
start_tmux_session() {
127-
echo "Setting up tmux session..."
128-
129-
# Check if session already exists
130-
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
131-
print_warning "Session '$SESSION_NAME' already exists"
132-
return 0
133-
fi
134-
135-
# Create new session
136-
if [ -n "$STARTUP_COMMAND" ]; then
137-
echo "Creating tmux session '$SESSION_NAME' with startup command"
138-
tmux new-session -d -s "$SESSION_NAME" "$STARTUP_COMMAND"
139-
else
140-
echo "Creating tmux session '$SESSION_NAME'"
141-
tmux new-session -d -s "$SESSION_NAME"
142-
fi
143-
144-
echo "tmux session '$SESSION_NAME' created successfully"
145-
}
146-
147-
# Function to display usage information
148-
show_usage_info() {
149-
echo -e "$${BOLD}✅ tmux setup complete!$${RESET}"
150-
echo ""
151-
echo -e "$${BOLD}📋 Quick reference:$${RESET}"
152-
echo " • Attach to session: tmux attach -t $${SESSION_NAME}"
153-
echo " • Detach from session: Ctrl+a, then d"
154-
echo " • List sessions: tmux list-sessions"
155-
echo " • Kill session: tmux kill-session -t $${SESSION_NAME}"
156-
echo ""
157-
echo -e "$${BOLD}🔄 Session persistence:$${RESET}"
158-
echo " • Auto-save interval: every $${SAVE_INTERVAL} minutes"
159-
echo " • Manual save: Ctrl+a, then Ctrl+s"
160-
echo " • Manual restore: Ctrl+a, then Ctrl+r"
161-
echo " • Sessions automatically restore on boot"
162-
echo ""
163-
echo -e "$${BOLD}🔌 Plugin management:$${RESET}"
164-
echo " • Install plugins: Ctrl+a, then I"
165-
echo " • Update plugins: Ctrl+a, then U"
166-
echo " • Uninstall plugins: Ctrl+a, then alt+u"
167-
echo ""
126+
printf "tmux plugins installed successfully \n"
168127
}
169128

170129
# Main execution
171130
main() {
172-
echo -e "$${BOLD}Setting up tmux with session persistence...$${RESET}"
173-
echo ""
131+
printf "$${BOLD} 🛠️Setting up tmux with session persistence! \n\n"
132+
printf ""
174133

175134
# Install dependencies
176135
install_tmux
@@ -182,11 +141,7 @@ main() {
182141
# Install plugins
183142
install_plugins
184143

185-
# Start tmux session
186-
start_tmux_session
187-
188-
# Show usage information
189-
show_usage_info
144+
printf "$${BOLD}✅ tmux setup complete! \n\n"
190145
}
191146

192147
# Run main function

0 commit comments

Comments
 (0)