aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-01-28 08:34:35 -0700
committerCody Hiar <cody@hiar.ca>2021-01-28 08:34:35 -0700
commit8866483844e64543a652590e2ec9aa40a5bb6ef4 (patch)
tree3e69fa22b465f11c66f574924228edba4d2e6cc5
parent1b3a041521e3bb59febd21d6f86f1881d86d971e (diff)
Updating scripts
-rwxr-xr-xscripts/path_search.sh13
-rwxr-xr-xscripts/rolodex (renamed from scripts/rolodex.sh)118
-rwxr-xr-xscripts/url_search.sh13
-rwxr-xr-xscripts/window_renum (renamed from scripts/window_renum.sh)0
-rw-r--r--stow/tmux/.tmux.conf10
5 files changed, 99 insertions, 55 deletions
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.sh b/scripts/rolodex
index 00cc1ce..fe386b3 100755
--- a/scripts/rolodex.sh
+++ b/scripts/rolodex
@@ -48,10 +48,9 @@ NC='\e[0m' # No Color
readonly ARGS=( "$@" )
readonly NUM_ARGS="$#"
readonly PROGNAME=$(basename "$0")
-
-get_number_of_active_window_panes() {
- echo $(tmux lsp | wc -l)
-}
+readonly OPEN=1
+readonly CLOSED=0
+readonly DRAWER_SIZE=15
get_active_pane(){
echo $(tmux lsp | grep '(active)' | cut -c 1)
@@ -61,26 +60,19 @@ 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
+get_number_of_active_window_panes() {
+ echo $(tmux lsp | wc -l)
}
-# 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
+get_number_of_windows() {
+ echo $(tmux lsw | wc -l)
+}
- ACTIVE_PANE=$(get_active_pane)
- if [[ "$ACTION" == 'prev' ]]; then
- open_drawer_if_unopen
+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
@@ -88,8 +80,14 @@ main() {
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
+ 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
@@ -97,8 +95,78 @@ main() {
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 "Command not recognized: $ACTION"
+ echo "Unrecognized command: ${ACTION}"
fi
}
-main
+main $ARGS
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.sh b/scripts/window_renum
index ef0a87f..ef0a87f 100755
--- a/scripts/window_renum.sh
+++ b/scripts/window_renum
diff --git a/stow/tmux/.tmux.conf b/stow/tmux/.tmux.conf
index e491eae..bfe8678 100644
--- a/stow/tmux/.tmux.conf
+++ b/stow/tmux/.tmux.conf
@@ -19,10 +19,10 @@ bind J resize-pane -D 3
bind K resize-pane -U 3
bind L resize-pane -R 3
# Rollodex commands
-bind n run-shell "rolodex next"
-bind p run-shell "rolodex prev"
-bind C-m run-shell "rolodex toggle"
-bind C-e run-shell "rolodex new"
+bind n run-shell "~/.tmux/scripts/rolodex next"
+bind p run-shell "~/.tmux/scripts/rolodex prev"
+bind C-m run-shell "~/.tmux/scripts/rolodex toggle"
+bind C-e run-shell "~/.tmux/scripts/rolodex new"
# Bind the last window/pane command
bind C-b last-pane
# Faster window switching
@@ -47,6 +47,8 @@ bind C-t clock-mode
# Use fzf for switching sessions
unbind s
bind s run-shell 'tmux_session_fzf_wrapper'
+# Renumber the windows
+bind C-w run-shell "~/.tmux/scripts/window_renum"
#####################################
# Settings