Last active
April 24, 2022 23:08
-
-
Save NickKelly1/0e5f83b6fe851cebfe4629227833e22f to your computer and use it in GitHub Desktop.
tmux-init.sh
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
| #! /usr/bin/env bash | |
| # | |
| # tmux config script | |
| # | |
| # https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f | |
| # | |
| # usage: | |
| # $ curl -s https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f/raw | bash | |
| # | |
| # author: Nick Kelly | |
| # created: 2022-04-24 | |
| # updated: 2022-04-24 | |
| # | |
| # useful tmux commands: | |
| # 1. view root keys (keys without prefix): | |
| # - tmux list-keys root | |
| # 2. view prefixed keys (preceeded by leader eg C-b): | |
| # - tmux list-keys prefix | |
| # | |
| ABOUT="" | |
| set -e | |
| set -u | |
| set -o pipefail | |
| CONF_FILEPATH=~/.tmux.conf | |
| echo | |
| echo "=======================================" | |
| echo "=== Initialising tmux configuration ===" | |
| echo "=== author: Nick Kelly ===" | |
| echo "=== created: 2022-04-24 ===" | |
| echo "=== updated: 2022-04-24 ===" | |
| echo "=======================================" | |
| echo | |
| echo "Tmux conf filepath: ${CONF_FILEPATH}" | |
| if [[ -f "${CONF_FILEPATH}" ]]; then | |
| echo "${CONF_FILEPATH} already exists" | |
| read -r -p "Append to the existing .tmux.conf file? [Y/n] " cont | |
| case ${cont} in | |
| [yY][eE][sS]|[yY]) | |
| # allow continue | |
| ;; | |
| [nN][oO]|[nN]) | |
| echo "Exiting" | |
| exit 0 | |
| ;; | |
| *) | |
| echo "Invalid input..." | |
| exit 1 | |
| ;; | |
| esac | |
| fi | |
| # get the desired prefix | |
| PREFIX_DEFAULT="b" | |
| PREFIX= | |
| read -e -p "Tmux prefix: " -i "${PREFIX_DEFAULT}" PREFIX | |
| # lowercase | |
| PREFIX=${PREFIX,,} | |
| # lowercase | |
| PREFIX=${PREFIX,,} | |
| # first char | |
| PREFIX=${PREFIX:0:1} | |
| PREFIX=${PREFIX:-${PREFIX_DEFAULT}} | |
| PREFIX_SECTION="# prefix: ${PREFIX}" | |
| if [[ "${PREFIX}" != "${PREFIX_DEFAULT}" ]]; then | |
| PREFIX_SECTION=$(cat <<-EOF | |
| # change prefix from ${PREFIX_DEFAULT} to ${PREFIX} | |
| unbind C-${PREFIX_DEFAULT} | |
| bind-key C-${PREFIX} send-prefix | |
| set -g prefix C-${PREFIX} | |
| EOF | |
| ) | |
| fi | |
| # bash heredoc | |
| # append these lines into CONF_FILEPATH | |
| cat <<-EOF >> ${CONF_FILEPATH} | |
| ${ABOUT} | |
| # vi mode | |
| # https://sanctum.geek.nz/arabesque/vi-mode-in-tmux/ | |
| set-window-option -g mode-keys vi | |
| ${PREFIX_SECTION} | |
| # switch between panes with vi keys | |
| bind-key -T prefix k select-pane -U | |
| bind-key -T prefix j select-pane -D | |
| bind-key -T prefix l select-pane -R | |
| bind-key -T prefix h select-pane -L | |
| # resize panes with vi keys | |
| bind-key C-k resize-pane -U 5 | |
| bind-key C-j resize-pane -D 5 | |
| bind-key C-l resize-pane -R 5 | |
| bind-key C-h resize-pane -L 5 | |
| # https://www.tecmint.com/owerline-adds-powerful-statuslines-and-prompts-to-vim-and-bash/ | |
| set -g default-terminal "xterm-256color" | |
| EOF | |
| echo "Finished. See new configuration in ${CONF_FILEPATH}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment