fix(tmux): use heredoc for config to handle special characters

The previous implementation using inline variable assignment and printf
caused issues with custom tmux configs containing special characters:

1. `TMUX_CONFIG="${TMUX_CONFIG}"` - Terraform's templatefile substitutes
   the multi-line config inline, causing bash to interpret tmux commands
   (like `set -g`, `bind C-s`) as shell commands.

2. `printf "$TMUX_CONFIG"` - The `%` character in tmux's default
   horizontal split keybind (`bind %`) is interpreted as a printf format
   specifier, corrupting the output.

Changes:
- Use heredoc with `read -r -d ''` for safe variable assignment
- Use `cat <<<` instead of `printf` for output
- Add `|| true` to handle read's non-zero exit on EOF
This commit is contained in:
Sebastian Mengwall 2026-01-01 18:45:30 +00:00
parent 3677e93e36
commit 2afe7d8306
No known key found for this signature in database

View File

@ -4,7 +4,9 @@ BOLD='\033[0;1m'
# Convert templated variables to shell variables
SAVE_INTERVAL="${SAVE_INTERVAL}"
TMUX_CONFIG="${TMUX_CONFIG}"
read -r -d '' TMUX_CONFIG << 'TMUX_EOF' || true
${TMUX_CONFIG}
TMUX_EOF
# Function to install tmux
install_tmux() {
@ -73,7 +75,7 @@ setup_tmux_config() {
mkdir -p "$config_dir"
if [ -n "$TMUX_CONFIG" ]; then
printf "$TMUX_CONFIG" > "$config_file"
cat <<< "$TMUX_CONFIG" > "$config_file"
printf "$${BOLD}Custom tmux configuration applied at {$config_file} \n\n"
else
cat > "$config_file" << EOF