From 8866483844e64543a652590e2ec9aa40a5bb6ef4 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Thu, 28 Jan 2021 08:34:35 -0700 Subject: Updating scripts --- scripts/path_search.sh | 13 ---- scripts/rolodex | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/rolodex.sh | 104 ----------------------------- scripts/url_search.sh | 13 ---- scripts/window_renum | 23 +++++++ scripts/window_renum.sh | 23 ------- 6 files changed, 195 insertions(+), 153 deletions(-) delete mode 100755 scripts/path_search.sh create mode 100755 scripts/rolodex delete mode 100755 scripts/rolodex.sh delete mode 100755 scripts/url_search.sh create mode 100755 scripts/window_renum delete mode 100755 scripts/window_renum.sh (limited to 'scripts') diff --git a/scripts/path_search.sh b/scripts/path_search.sh deleted file mode 100755 index d473607..0000000 --- a/scripts/path_search.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# vim: set filetype=sh -# -# Author: Cody Hiar -# Date: 2019-04-26 -# -# Description: Search buffer for unix paths in current tmux pane and send -# results to fzf to copy to clipboard - -URL=$(tmux capture-pane -pS -30000 | perl -wnl -e '/\S*(html|py|md|txt|pdf|js|ini|json)$/ and print $&' | awk '!x[$0]++' | fzf-tmux) -if [[ -n "$URL" ]]; then - echo "$URL" | xp -fi diff --git a/scripts/rolodex b/scripts/rolodex new file mode 100755 index 0000000..fe386b3 --- /dev/null +++ b/scripts/rolodex @@ -0,0 +1,172 @@ +#!/usr/bin/env bash +# vim: set filetype=sh +# +# Author: Cody Hiar +# Date: 2019-01-11 +# +# Description: Rolodex script. Consider the following setup +# +# +------------------------------+-----------------------------+ +# | | | +# | | Pane 3 | +# | | | +# | Pane 1 +-----------------------------+ +# | | | +# | | Pane 4 | +# +------------------------------+ | +# | | | +# | +-----------------------------+ +# | Pane 2 | | +# | | | +# | | Pane 5 | +# | | | +# +------------------------------+-----------------------------+ +# Window 1 Window 2 +# +# This is my standard setup. Pane 1 is vim, pane 2-5 are just used for docker +# or w/e else. I almost always want to stick on Window 1 but I want to cycle +# between pane 2-5. This script will simply rotate them in either direction so +# I can stay in window 1 but have a sort of "tabbed" bottom 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 +# 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") +readonly OPEN=1 +readonly CLOSED=0 +readonly DRAWER_SIZE=15 + +get_active_pane(){ + echo $(tmux lsp | grep '(active)' | cut -c 1) +} + +get_number_of_buffer_window_panes() { + echo $(tmux lsp -t 2 | wc -l) +} + +get_number_of_active_window_panes() { + echo $(tmux lsp | wc -l) +} + +get_number_of_windows() { + echo $(tmux lsw | wc -l) +} + +get_prev_pane() { + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$PANE_COUNT" == '2' ]]; then + BUFFER_COUNT=$(get_number_of_buffer_window_panes) + ACTIVE_PANE=$(get_active_pane) + 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."$ACTIVE_PANE" + fi +} + +get_next_pane() { + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$PANE_COUNT" == '2' ]]; then + BUFFER_COUNT=$(get_number_of_buffer_window_panes) + ACTIVE_PANE=$(get_active_pane) + 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."$ACTIVE_PANE" + fi +} + + +close_drawer() { + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$PANE_COUNT" == '2' ]]; then + WINDOW_COUNT=$(get_number_of_windows) + if [[ "$WINDOW_COUNT" == '1' ]]; then + tmux new-window + fi + tmux move-pane -s 1.2 -t 2.1 + tmux move-pane -s 2.1 -t 2.2 + if [[ "$WINDOW_COUNT" == '1' ]]; then + tmux kill-pane -t 2.2 + fi + tmux select-window -t 1 + fi +} + +open_drawer() { + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$PANE_COUNT" == '1' ]]; then + WINDOW_COUNT=$(get_number_of_windows) + if [[ "$WINDOW_COUNT" == '1' ]]; then + tmux split-window -c '#{pane_current_path}' + + else + tmux move-pane -s 2.1 + fi + tmux resize-pane -t 1.2 -y "${DRAWER_SIZE}" + fi +} + +check_if_drawer_is_open_or_closed() { + set +e + tmux showenv DRAWER_PANE_ID &> /dev/null + RETVAL="$?" + set -e + if [[ "$RETVAL" == 0 ]]; then + echo "${OPEN}" + else + echo "${CLOSED}" + fi +} + +toggle_drawer() { + PANE_COUNT=$(get_number_of_active_window_panes) + if [[ "$PANE_COUNT" == '1' ]]; then + open_drawer + elif [[ "$PANE_COUNT" == '2' ]]; then + close_drawer + fi +} + +create_new_pane() { + tmux split-window -c '#{pane_current_path}' + tmux resize-pane -t 1.2 -y "${DRAWER_SIZE}" +} + +main() { + ACTION="${1:-}" + if [[ $ACTION == "toggle" ]]; then + toggle_drawer + elif [[ $ACTION == "next" ]]; then + get_next_pane + elif [[ $ACTION == "prev" ]]; then + get_prev_pane + elif [[ $ACTION == "new" ]]; then + create_new_pane + else + echo "Unrecognized command: ${ACTION}" + fi +} +main $ARGS diff --git a/scripts/rolodex.sh b/scripts/rolodex.sh deleted file mode 100755 index 00cc1ce..0000000 --- a/scripts/rolodex.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bash -# vim: set filetype=sh -# -# Author: Cody Hiar -# Date: 2019-01-11 -# -# Description: Rolodex script. Consider the following setup -# -# +------------------------------+-----------------------------+ -# | | | -# | | Pane 3 | -# | | | -# | Pane 1 +-----------------------------+ -# | | | -# | | Pane 4 | -# +------------------------------+ | -# | | | -# | +-----------------------------+ -# | Pane 2 | | -# | | | -# | | Pane 5 | -# | | | -# +------------------------------+-----------------------------+ -# Window 1 Window 2 -# -# This is my standard setup. Pane 1 is vim, pane 2-5 are just used for docker -# or w/e else. I almost always want to stick on Window 1 but I want to cycle -# between pane 2-5. This script will simply rotate them in either direction so -# I can stay in window 1 but have a sort of "tabbed" bottom 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 -# 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_active_pane(){ - echo $(tmux lsp | grep '(active)' | cut -c 1) -} - -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 - - ACTIVE_PANE=$(get_active_pane) - 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."$ACTIVE_PANE" - 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."$ACTIVE_PANE" - else - echo "Command not recognized: $ACTION" - fi -} -main diff --git a/scripts/url_search.sh b/scripts/url_search.sh deleted file mode 100755 index 54a0bc3..0000000 --- a/scripts/url_search.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# vim: set filetype=sh -# -# Author: Cody Hiar -# Date: 2019-04-25 -# -# Description: Search tmux pane for urls then pass to fzf -# for copying to clipboard - -URL=$(tmux capture-pane -pS -30000 | perl -wnl -e '/https?\:\/\/[^\s]+[\/\w]/ and print $&' | fzf-tmux) -if [[ -n "$URL" ]]; then - echo "$URL" | xp -fi diff --git a/scripts/window_renum b/scripts/window_renum new file mode 100755 index 0000000..ef0a87f --- /dev/null +++ b/scripts/window_renum @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# vim: set filetype=sh +# +# Author: Unknown +# Date: 2016-11-09 +# +# Description: Renumber tmux windows (1, 3, 4, 6) -> (1, 2, 3, 4) + +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/scripts/window_renum.sh b/scripts/window_renum.sh deleted file mode 100755 index ef0a87f..0000000 --- a/scripts/window_renum.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# vim: set filetype=sh -# -# Author: Unknown -# Date: 2016-11-09 -# -# Description: Renumber tmux windows (1, 3, 4, 6) -> (1, 2, 3, 4) - -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