Skip to content

Instantly share code, notes, and snippets.

@NickKelly1
Last active April 24, 2022 23:08
Show Gist options
  • Select an option

  • Save NickKelly1/0e5f83b6fe851cebfe4629227833e22f to your computer and use it in GitHub Desktop.

Select an option

Save NickKelly1/0e5f83b6fe851cebfe4629227833e22f to your computer and use it in GitHub Desktop.

Revisions

  1. NickKelly1 renamed this gist Apr 24, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 35 additions and 23 deletions.
    58 changes: 35 additions & 23 deletions .sh
    Original file line number Diff line number Diff line change
    @@ -25,12 +25,21 @@ set -e
    set -u
    set -o pipefail

    CONF_FILENAME=~/.tmux.conf
    CONF_FILEPATH=~/.tmux.conf

    echo "tmux conf filename: ${CONF_FILENAME}"
    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_FILENAME}" ]]; then
    echo "${CONF_FILENAME} already exists"
    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])
    @@ -52,31 +61,33 @@ fi
    PREFIX_DEFAULT="b"
    PREFIX=

    echo "Prefix (default: ${PREFIX_DEFAULT}):"
    read -s PREFIX
    echo
    read -e -p "Tmux prefix: " -i "${PREFIX_DEFAULT}" PREFIX

    # lowercase
    PREFIX=${PREFIX,,}

    # lowercase
    PREFIX=${PREFIX,,}

    # first char
    PREFIX=${PREFIX:0:1}

    PREFIX_SECTION="# prefix: ${PREFIX_DEFAULT}"
    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
    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_FILENAME
    cat << EOF >> ${CONF_FILENAME}
    # append these lines into CONF_FILEPATH
    cat <<-EOF >> ${CONF_FILEPATH}
    ${ABOUT}
    # vi mode
    @@ -92,12 +103,13 @@ bind-key -T prefix l select-pane -R
    bind-key -T prefix h select-pane -L
    # resize panes with vi keys
    bind-key -T C-k resize-pane -U 5
    bind-key -T C-j resize-pane -D 5
    bind-key -T C-l resize-pane -R 5
    bind-key -T C-h resize-pane -L 5
    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"
    set -g default-terminal "xterm-256color"
    EOF

    echo "Finished. See new configuration in ${CONF_FILEPATH}"
  3. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions .sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    #! /usr/bin/env bash

    ABOUT=$(cat <<EOF
    #
    # tmux config script
    #
    @@ -19,8 +18,8 @@ ABOUT=$(cat <<EOF
    # 2. view prefixed keys (preceeded by leader eg C-b):
    # - tmux list-keys prefix
    #
    EOF
    )

    ABOUT=""

    set -e
    set -u
  4. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #! /usr/bin/env bash

    ABOUT=$(cat << EOF
    ABOUT=$(cat <<EOF
    #
    # tmux config script
    #
  5. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions .sh
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,7 @@ ABOUT=$(cat << EOF
    # https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f
    #
    # usage:
    # ```sh
    # $ curl -s https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f/raw | bash
    # ```
    #
    # author: Nick Kelly
    # created: 2022-04-24
  6. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions .sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #! /usr/bin/env bash

    ABOUT=$(cat EOF <<
    ABOUT=$(cat << EOF
    #
    # tmux config script
    #
    @@ -78,7 +78,7 @@ fi
    # bash heredoc
    # append these lines into CONF_FILENAME
    cat <<EOF >> ${CONF_FILENAME}
    cat << EOF >> ${CONF_FILENAME}
    ${ABOUT}
  7. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion .sh
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,9 @@ ABOUT=$(cat EOF <<
    # https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f
    #
    # usage:
    # $
    # ```sh
    # $ curl -s https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f/raw | bash
    # ```
    #
    # author: Nick Kelly
    # created: 2022-04-24
  8. NickKelly1 revised this gist Apr 24, 2022. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions .sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,11 @@ ABOUT=$(cat EOF <<
    #
    # tmux config script
    #
    # https://gist.github.com/NickKelly1/0e5f83b6fe851cebfe4629227833e22f
    #
    # usage:
    # $
    #
    # author: Nick Kelly
    # created: 2022-04-24
    # updated: 2022-04-24
  9. NickKelly1 created this gist Apr 24, 2022.
    99 changes: 99 additions & 0 deletions .sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    #! /usr/bin/env bash

    ABOUT=$(cat EOF <<
    #
    # tmux config script
    #
    # 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
    #
    EOF
    )

    set -e
    set -u
    set -o pipefail

    CONF_FILENAME=~/.tmux.conf

    echo "tmux conf filename: ${CONF_FILENAME}"

    if [[ -f "${CONF_FILENAME}" ]]; then
    echo "${CONF_FILENAME} 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=

    echo "Prefix (default: ${PREFIX_DEFAULT}):"
    read -s PREFIX
    echo

    # lowercase
    PREFIX=${PREFIX,,}

    # first char
    PREFIX=${PREFIX:0:1}

    PREFIX_SECTION="# prefix: ${PREFIX_DEFAULT}"
    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_FILENAME
    cat <<EOF >> ${CONF_FILENAME}
    ${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 -T C-k resize-pane -U 5
    bind-key -T C-j resize-pane -D 5
    bind-key -T C-l resize-pane -R 5
    bind-key -T 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