From 15659c5bac16417cdece907c775359e1d5d81b42 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Tue, 25 Apr 2017 11:54:01 -0600 Subject: Updating for bottom drawer functionality --- scripts/bottom_window_drawer.sh | 29 ++++++++++++++++ scripts/tmux_open_filename_in_vim.sh | 64 ++++++++++++++++++++++++++++++++++++ scripts/window_renum.sh | 15 +++++++++ templates/template.yaml | 2 -- tmux.config | 2 ++ window_renum.sh | 15 --------- 6 files changed, 110 insertions(+), 17 deletions(-) create mode 100755 scripts/bottom_window_drawer.sh create mode 100755 scripts/tmux_open_filename_in_vim.sh create mode 100755 scripts/window_renum.sh delete mode 100755 window_renum.sh diff --git a/scripts/bottom_window_drawer.sh b/scripts/bottom_window_drawer.sh new file mode 100755 index 0000000..7c3dcaf --- /dev/null +++ b/scripts/bottom_window_drawer.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# vim: set filetype=sh : +# +# Author: Cody Hiar +# Date: 2017-04-25 +# +# Purpose: To either close or open a bottom drawer window +# +# Set options: +# e: Stop script if command fails +# u: Stop script if unset variable is referenced +# x: Debug, print commands as they are executed +set -eu + +# Immutable globals +readonly ARGS=( "$@" ) +readonly PROGNAME=$(basename "$0") + +# Main loop of program +main() { + NUM_PANES=$(tmux list-panes | wc -l) + if [[ "$NUM_PANES" == 1 ]]; then + tmux split-window -c '#{pane_current_path}' + tmux resize-pane -t 2 -y 20 + else + tmux kill-pane -t 2 + fi +} +main diff --git a/scripts/tmux_open_filename_in_vim.sh b/scripts/tmux_open_filename_in_vim.sh new file mode 100755 index 0000000..6a799e4 --- /dev/null +++ b/scripts/tmux_open_filename_in_vim.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Author: Cody Hiar +# Date: 2017-04-22 +# +# Purpose: The purpose of this script is to accept a file name then find a tmux +# pane that is currently running either vim or neovim and tell that pane to open +# up the file. This script is meant to be used with a fuzzy find such as fzf so +# that you can use an external fuzzy finder but still integrate it with vim +# +# Set options: +# e: Stop script if command fails +# u: Stop script if unset variable is referenced +# x: Debug, print commands as they are executed +# set -eu + +# Immutable globals +readonly ARGS=( "$@" ) +readonly PROGNAME=$(basename "$0") +readonly USAGE=$(cat << EOF +usage: $PROGNAME file_name + +Script that will search for a tmux pane running vim and will tell vim to open a +file specified by the passed in arguement + +OPTIONS: + -h Display help options +EOF +) + +# Function for processing arguments +cmdline() { + while getopts "h" FLAG; do + case "$FLAG" in + h) + echo "$USAGE" + exit 0 + ;; + *) + exit 0 + ;; + esac + done +} + +# Main loop of program +main() { + if [[ -z ${ARGS[0]} ]]; then + exit + fi + cmdline "${ARGS[@]}" + panes=($(tmux list-panes| awk -F: '{ print $1 }')) + for pane in "${panes[@]}"; do + pane_tty=$(tmux display -p -t "$pane" '#{pane_tty}') + ps -o state= -o comm= -t "$pane_tty" \ + | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$' &> /dev/null + if [[ "$?" == 0 ]]; then + filename="${ARGS[0]}" + tmux send-keys -t "$pane" ":e $filename" Enter + tmux select-pane -t "$pane" + fi + done +} +main diff --git a/scripts/window_renum.sh b/scripts/window_renum.sh new file mode 100755 index 0000000..19e5825 --- /dev/null +++ b/scripts/window_renum.sh @@ -0,0 +1,15 @@ +for session in $(tmux ls | awk -F: '{print $1}') ; do + active_window=$(tmux lsw -t ${session} | awk -F: '/\(active\)$/ {print $1}') + inum=1 + for window in $(tmux lsw -t ${session} | awk -F: '{print $1}') ;do + if [ ${window} -gt ${inum} ] ;then + echo "${session}:${window} -> ${session}:${inum}" + tmux movew -d -s ${session}:${window} -t ${session}:${inum} + fi + if [ ${window} = ${active_window} ] ;then + new_active_window=${inum} + fi + inum=$((${inum}+1)) + done + tmux select-window -t ${session}:${new_active_window} +done diff --git a/templates/template.yaml b/templates/template.yaml index d2a4a09..3218321 100644 --- a/templates/template.yaml +++ b/templates/template.yaml @@ -9,8 +9,6 @@ windows: - shell_command: - nvim focus: true - - shell_command: - - tmux resizep -t 2 -y 20; tmux resize-pane -Z -t 1; clear - window_name: docker layout: even-vertical panes: diff --git a/tmux.config b/tmux.config index 8901170..594dbcf 100644 --- a/tmux.config +++ b/tmux.config @@ -26,6 +26,8 @@ bind C-p previous-window bind a set-window-option synchronize-panes # Remap zoom, sleeping tmux way too much bind C-v resize-pane -Z +# Binding for bottom drawer script +bind C-m run-shell "$HOME/.tmux/scripts/bottom_window_drawer.sh" ##################################### # Settings diff --git a/window_renum.sh b/window_renum.sh deleted file mode 100755 index 19e5825..0000000 --- a/window_renum.sh +++ /dev/null @@ -1,15 +0,0 @@ -for session in $(tmux ls | awk -F: '{print $1}') ; do - active_window=$(tmux lsw -t ${session} | awk -F: '/\(active\)$/ {print $1}') - inum=1 - for window in $(tmux lsw -t ${session} | awk -F: '{print $1}') ;do - if [ ${window} -gt ${inum} ] ;then - echo "${session}:${window} -> ${session}:${inum}" - tmux movew -d -s ${session}:${window} -t ${session}:${inum} - fi - if [ ${window} = ${active_window} ] ;then - new_active_window=${inum} - fi - inum=$((${inum}+1)) - done - tmux select-window -t ${session}:${new_active_window} -done -- cgit v1.2.3