#!/bin/bash # curl -sL "https://vim.chan15.info/download/get_tmux.sh" | bash yellow='\033[1;33m' no_color='\033[0m' # No Color shell_config='alias tmux="tmux -2"' tmux_config=$(cat << EOF # ~/.tmux.conf set -g default-terminal "xterm" setw -g mode-keys vi set -g pane-border-status top set -g mouse on bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection-no-clear bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-selection-no-clear bind-key -T copy-mode-vi 'v' send -X begin-selection # List of plugins set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'dracula/tmux' set -g @dracula-plugins "git cpu-usage ram-usage time" set -g @dracula-show-powerline true set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-copycat' run '~/.tmux/plugins/tpm/tpm' EOF ) get_shell_rc() { case "$(basename "${SHELL:-bash}")" in zsh) echo "$HOME/.zshrc" ;; *) echo "$HOME/.bashrc" ;; esac } config_not_in_shell_rc() { ! grep -Fqx "$shell_config" "$shell_rc" 2>/dev/null } dracula_not_in_tmux_conf() { counter=$(grep "dracula/tmux" ~/.tmux.conf | wc -l) if [[ "$counter" -gt 0 ]]; then return 1 fi return 0 } insert_tmux_conf() { echo "$tmux_config" >> ~/.tmux.conf } get_distribution() { lsb_dist="" if [[ -r /etc/os-release ]]; then lsb_dist="$(. /etc/os-release && echo "$ID")" fi echo "$lsb_dist" } dispatch() { cd /tmp || exit 1 if [[ ! -d /tmp/tmux ]]; then git clone https://github.com/tmux/tmux.git fi cd tmux || exit 1 sudo sh autogen.sh sudo ./configure && sudo make sudo make install } go_apt() { echo "install tmux in $1" sudo apt purge -y tmux sudo apt install -y git make gcc autoconf automake pkg-config libevent-dev libncurses-dev bison dispatch } go_centos() { echo install tmux in centos sudo yum install -y git sudo yum remove -y tmux sudo yum install -y git make gcc autoconf automake pkg-config bison libevent-devel ncurses-devel dispatch } go_macos() { echo install tmux in macOS if ! command -v brew >/dev/null 2>&1; then echo "Homebrew is required. Install it from https://brew.sh, then run this script again." exit 1 fi brew install tmux } if [[ "$(uname -s)" == "Darwin" ]]; then go_macos else distribution=$(get_distribution) case "$distribution" in ubuntu|debian) go_apt "$distribution" ;; centos) go_centos ;; *) echo not compatible OS exit 1 esac fi if ! command -v tmux >/dev/null 2>&1; then echo "tmux installation failed" exit 1 fi if [[ ! -d ~/.tmux/plugins/tpm ]]; then mkdir -p ~/.tmux/plugins git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm fi if [[ ! -f ~/.tmux.conf ]]; then touch ~/.tmux.conf insert_tmux_conf else if dracula_not_in_tmux_conf; then insert_tmux_conf fi fi shell_rc=$(get_shell_rc) if config_not_in_shell_rc; then echo -e "\n$shell_config" >> "$shell_rc" echo -e "${yellow}Added tmux alias to $shell_rc. Please run 'source $shell_rc' or restart your terminal to activate it.${no_color}" fi echo -e "${yellow}$(tmux -V)${no_color} installed"