Created
October 9, 2024 15:57
-
-
Save dphilla/9ea97045c8d98baa10d28b2913a369c2 to your computer and use it in GitHub Desktop.
Fresh tmux setup + configure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This script installs tmux and configures it with common key bindings and settings. | |
| # | |
| # Usage: | |
| # chmod +x tmux.sh | |
| # ./tmux.sh or bash tmux.sh | |
| # Determine the OS | |
| ios="$(uname)" | |
| if [[ "$ios" == "Linux" ]]; then | |
| # Update and install tmux for Linux | |
| sudo apt update && sudo apt install -y tmux | |
| elif [[ "$ios" == "Darwin" ]]; then | |
| # Install tmux for macOS | |
| if ! command -v brew &> /dev/null; then | |
| echo "Homebrew not found. Installing Homebrew..." | |
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| fi | |
| brew install tmux | |
| else | |
| echo "Unsupported operating system: $ios" | |
| exit 1 | |
| fi | |
| # Create a default .tmux.conf configuration | |
| TMUX_CONF="$HOME/.tmux.conf" | |
| cat << EOF > $TMUX_CONF | |
| # General Settings | |
| set -g mouse on # Enable mouse support | |
| set -g history-limit 10000 # Set scrollback buffer to 10,000 lines | |
| setw -g mode-keys vi # Use vi keys in copy mode | |
| # Prefix Key | |
| unbind C-b # Unbind default prefix | |
| set -g prefix C-a # Set prefix to Ctrl-a | |
| bind C-a send-prefix # Allow double-tapping Ctrl-a | |
| # Split Windows | |
| bind | split-window -h # Split pane horizontally | |
| bind - split-window -v # Split pane vertically | |
| # Navigation between Panes | |
| bind h select-pane -L # Move left | |
| bind j select-pane -D # Move down | |
| bind k select-pane -U # Move up | |
| bind l select-pane -R # Move right | |
| # Resizing Panes | |
| bind -r < resize-pane -L 5 # Resize pane left | |
| bind -r > resize-pane -R 5 # Resize pane right | |
| bind -r + resize-pane -U 5 # Resize pane up | |
| bind -r _ resize-pane -D 5 # Resize pane down | |
| # Reload Configuration | |
| bind r source-file ~/.tmux.conf \; display-message "Config reloaded" | |
| # Set status bar style | |
| set -g status-bg black # Status bar background color | |
| set -g status-fg white # Status bar text color | |
| set -g status-left '#[fg=green](#S) ' # Session name | |
| EOF | |
| # Inform the user | |
| echo "tmux has been installed and configured!" | |
| echo "You can edit the configuration file at: $TMUX_CONF" | |
| echo "To apply the configuration, run: tmux source-file $TMUX_CONF" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment