diff options
author | Cody Hiar <codyfh@gmail.com> | 2019-02-14 19:16:55 +0000 |
---|---|---|
committer | Cody Hiar <codyfh@gmail.com> | 2019-02-14 19:16:55 +0000 |
commit | e3bb01fd2b859d9144beb585a1b3a8f478906b7d (patch) | |
tree | 0f46c8f87eabcdee9c70d348ccc243a99be3d174 | |
parent | 3466993b19aed1953ea8890019ff7ec72b46aee8 (diff) |
Adding rolodex script
-rwxr-xr-x | scripts/rolodex.sh | 77 | ||||
-rw-r--r-- | stow/tmux/.tmux.conf | 6 |
2 files changed, 79 insertions, 4 deletions
diff --git a/scripts/rolodex.sh b/scripts/rolodex.sh new file mode 100755 index 0000000..56010a2 --- /dev/null +++ b/scripts/rolodex.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# vim: set filetype=sh +# +# Author: Cody Hiar +# Date: 2019-01-11 +# +# Description: Rolodex script +# +# Set options: +# e: Stop script if command fails +# u: Stop script if unset variable is referenced +# x: Debug, print commands as they are executed +# o pipefail: If any command in a pipeline fails it all fails +# +# IFS: Internal Field Separator +set -euo pipefail +IFS=$'\n\t' + +# Colors for printing +G='\e[0;32m' # Green +LG='\e[0;37m' # Light Gray +C='\e[0;36m' # Cyan +NC='\e[0m' # No Color + +# Immutable globals +readonly ARGS=( "$@" ) +readonly NUM_ARGS="$#" +readonly PROGNAME=$(basename "$0") + +get_number_of_active_window_panes() { + echo $(tmux lsp | wc -l) +} + +get_number_of_buffer_window_panes() { + echo $(tmux lsp -t 2 | wc -l) +} + +open_drawer_if_unopen() { + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$PANE_COUNT" == '1' ]]; then + "$HOME"/.tmux/plugins/tmux-drawer/scripts/open_or_close_drawer.sh + fi +} + +# Main loop of program +main() { + BUFFER_COUNT=$(get_number_of_buffer_window_panes) + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$NUM_ARGS" == 0 ]]; then + ACTION='next' + elif [[ "$NUM_ARGS" == 1 ]]; then + ACTION="${ARGS[0]}" + fi + + if [[ "$ACTION" == 'prev' ]]; then + open_drawer_if_unopen + tmux swap-pane -s 1.2 -t 2."$BUFFER_COUNT" + MAX=$((BUFFER_COUNT - 1)) + for i in $(seq 1 "$MAX" | tac); do + NEXT=$((i + 1)) + tmux swap-pane -s 2."$i" -t 2."$NEXT" + done + tmux select-pane -t 1.1 + elif [[ "$ACTION" == 'next' ]]; then + open_drawer_if_unopen + tmux swap-pane -s 1.2 -t 2.1 + MAX=$((BUFFER_COUNT - 1)) + for i in $(seq 1 "$MAX"); do + NEXT=$((i + 1)) + tmux swap-pane -s 2."$i" -t 2."$NEXT" + done + tmux select-pane -t 1.1 + else + echo "Command not recognized: $ACTION" + fi +} +main diff --git a/stow/tmux/.tmux.conf b/stow/tmux/.tmux.conf index 4a524fc..20f4c6e 100644 --- a/stow/tmux/.tmux.conf +++ b/stow/tmux/.tmux.conf @@ -21,10 +21,8 @@ bind C-u resize-pane -D 3 bind C-i resize-pane -U 3 bind C-y resize-pane -L 3 bind C-o resize-pane -R 3 -bind j resize-pane -D 3 -bind k resize-pane -U 3 -bind h resize-pane -L 3 -bind l resize-pane -R 3 +bind J run-shell "bash $HOME/.tmux/scripts/rolodex.sh next" +bind K run-shell "bash $HOME/.tmux/scripts/rolodex.sh prev" # Bind the last window/pane command bind C-b last-window bind C-g last-pane |