aboutsummaryrefslogtreecommitdiff
path: root/scripts/tmux_open_filename_in_vim.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/tmux_open_filename_in_vim.sh')
-rwxr-xr-xscripts/tmux_open_filename_in_vim.sh38
1 files changed, 6 insertions, 32 deletions
diff --git a/scripts/tmux_open_filename_in_vim.sh b/scripts/tmux_open_filename_in_vim.sh
index b82c867..55f0c48 100755
--- a/scripts/tmux_open_filename_in_vim.sh
+++ b/scripts/tmux_open_filename_in_vim.sh
@@ -17,48 +17,22 @@
# 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" \
+ CURRENT_PANE=$(tmux display-message -p "#{pane_index}")
+ 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 kill-pane
- # tmux select-pane -t "$pane"
+ tmux select-pane -t "$pane"
fi
done
}