aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bottom_window_drawer.sh29
-rwxr-xr-xscripts/tmux_open_filename_in_vim.sh64
-rwxr-xr-xscripts/window_renum.sh15
3 files changed, 108 insertions, 0 deletions
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