From eefbd029b55b2782b0d7b11b4989ce0ca9b256cd Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Tue, 15 Oct 2019 20:56:41 -0400 Subject: Massive organization of my dotfiles --- tmux/tmux.conf | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tmux/tmux_helper.sh | 28 +++++++++++++++++ tmux/tmx.sh | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 tmux/tmux.conf create mode 100644 tmux/tmux_helper.sh create mode 100644 tmux/tmx.sh (limited to 'tmux') diff --git a/tmux/tmux.conf b/tmux/tmux.conf new file mode 100644 index 0000000..c80958d --- /dev/null +++ b/tmux/tmux.conf @@ -0,0 +1,91 @@ + +# *OLD* way to set styles +# set -g status-bg green +# set -g status-fg black +# set-window-option -g window-status-current-bg black +# set-window-option -g window-status-current-fg green + +# New way: +set -g status-style "fg=green,bg=black" +set-window-option -g window-status-current-style "bg=green,fg=black" +set -g status-right "#[fg=black,bg=green] #(whoami)@#h|m:#(sh $HOME/.tmux_helper.sh memory)|l:#(sh $HOME/.tmux_helper.sh load)|#(sh $HOME/.tmux_helper.sh uptime)" +# For a basic tmux configuration without the helper +# set -g status-right "#[fg=black,bg=green] #(whoami)@#h" + +# Pretty nifty little option to mirror input for all panes +bind M-s setw synchronize-panes + +# Allow the hotkeys to be switched using M-x to C-x, M-b to C-b, and so forth +bind M-x set prefix C-x +bind M-b set prefix C-b +bind M-a set prefix C-a + +# set -g mode-mouse on +setw -g mode-keys vi +# setw -g aggressive-resize on + +# This has previously not given me any issues other than 'set termguicolors' in +# vim +# set -g default-terminal "screen-256color" + +# This seems to fix that problem, it may cause other issues but I'm going to +# keep an eye on it +set-option -g default-terminal "tmux-256color" +set-option -ga terminal-overrides ",xterm*:Tc" + + +# Don't let command rename our windows +set-option -g allow-rename off + +# Press v to "visually" and y to "yank" the text +# Press `c-b ]` to paste +# If you ever want to look up a keybind use `c-b ?` +bind-key -T copy-mode-vi v send-keys -X begin-selection +bind-key -T copy-mode-vi y send-keys -X copy-selection + +# This one is also useful if you don't want to do what is listed above +# bind p paste-buffer + +# Rather large histroy buffer so I don't lose shit +set-option -g history-limit 16000 + +# Fix for certian applications such as Nvim +set -sg escape-time 0 + +# Select panes with vim like bindings +bind-key M-k select-pane -U +bind-key M-j select-pane -D +bind-key M-h select-pane -L +bind-key M-l select-pane -R + + +# Reload configuration +bind-key r source ~/.tmux.conf +# Respawn the pane # Useful if you have `set -g remain-on-exit on` or so +bind-key M-r respawn-pane + + +# Change the status line a little bit, most are close to defaults +set -g status-left-length 16 +set -g status-left "[#S] " + +set -g status-right-length 40 +set -g window-status-format "#I:#W#F" + +set -g set-titles on +set -g set-titles-string "tmux: #{session_name} [#I]#{window_name} -- #T" + + +# If you still want to select text out of the terminal as you normally would +# You should hold the shift key ( Linux ) Option/Alt works in iTerm2 on MacOS +# Does not seem to work with the native terminal. +set -g mouse on + +# Old mouse method +# set-option -g mode-mouse on +# set-option -g mouse-resize-pane on +# set-option -g mouse-select-pane on +# set-option -g mouse-select-window on + +# If you want any local configuration +source ~/.tmux.conf.local diff --git a/tmux/tmux_helper.sh b/tmux/tmux_helper.sh new file mode 100644 index 0000000..7ce68bd --- /dev/null +++ b/tmux/tmux_helper.sh @@ -0,0 +1,28 @@ +#!/bin/sh + + +# Little helper script to clean up the nasty embeded commands in my tmux configuration +# Functions ripped out of `mkshrc`, worth checking out + +_sys_memory() { + if [ `uname` = "Linux" ] ; then + vmstat | tail -n1 | awk '{print $4/1024}' | sed -e's/\..*$//g' + elif [ `uname` = "FreeBSD" ] ; then + vmstat | tail -n1 | awk '{print $5/1024}' | sed -e's/\..*$//g' + elif [ `uname` = "OpenBSD" ] ; then + vmstat | sed -n '$p' | awk '{print $4}' | sed 's/M$//' + fi +} + +_sys_load() { + # Works on BSD too, neat. + uptime | sed -re's/^.*load averages?: ([0-9]+\.[0-9]+).*$/\1/g' +} + +_sys_uptime() { + # Took awhile to figure out, but this works on BSD as well + uptime | sed -re's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g' +} + + +_sys_$1 diff --git a/tmux/tmx.sh b/tmux/tmx.sh new file mode 100644 index 0000000..0d66c27 --- /dev/null +++ b/tmux/tmx.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# Modified further by Mitchell Riedstra to be compatible with /bin/sh + +# +# Modified TMUX start script from: +# http://forums.gentoo.org/viewtopic-t-836006-start-0.html +# +# Store it to `~/bin/tmx` and issue `chmod +x`. +# + +# Works because bash automatically trims by assigning to variables and by +# passing arguments +trim() { echo $1; } + +if [ -z "$1" ]; then + echo "Specify session name as the first argument" + exit +fi + +# Only because I often issue `ls` to this script by accident +if [ "$1" == "ls" ]; then + tmux ls + exit +fi + +base_session="$1" +# This actually works without the trim() on all systems except OSX +tmux_nb=$(trim `tmux ls | grep "^$base_session" | wc -l`) +if [ "$tmux_nb" == "0" ]; then + echo "Launching tmux base session $base_session ..." + tmux new-session -s $base_session +else + # Make sure we are not already in a tmux session + if [ -z "$TMUX" ]; then + # Kill defunct sessions first + old_sessions=$(tmux ls 2>/dev/null | egrep "^[0-9]{14}.*[0-9]+\)$" | cut -f 1 -d:) + for old_session_id in $old_sessions; do + tmux kill-session -t $old_session_id + done + + echo "Launching copy of base session $base_session ..." + # Session is is date and time to prevent conflict + session_id=`date +%Y%m%d%H%M%S` + # Create a new session (without attaching it) and link to base session + # to share windows + tmux new-session -d -t $base_session -s $session_id + # Create a new window in that session + #tmux new-window + # Attach to the new session + tmux attach-session -t $session_id + # When we detach from it, kill the session + tmux kill-session -t $session_id + fi +fi -- cgit v1.2.3