Skip to content

Instantly share code, notes, and snippets.

@dalejung
Last active May 23, 2016 17:26
Show Gist options
  • Save dalejung/1caad1949cda661e8c10fa2ee47ac059 to your computer and use it in GitHub Desktop.
Save dalejung/1caad1949cda661e8c10fa2ee47ac059 to your computer and use it in GitHub Desktop.
select pane that doesn't wrap.
#!/usr/bin/env bash
pane_at_edge() {
direction=$1
case "$direction" in
"U")
coord='top'
op='<='
;;
"D")
coord='bottom'
op='>='
;;
"L")
coord='left'
op='<='
;;
"R")
coord='right'
op='>='
;;
esac
cmd="#{pane_id}:#{pane_$coord}:#{?pane_active,_active_,_no_}"
panes=$(tmux list-panes -F "$cmd")
active_pane=$(echo "$panes" | grep _active_)
active_pane_id=$(echo "$active_pane" | cut -d: -f1)
active_coord=$(echo "$active_pane" | cut -d: -f2)
coords=$(echo "$panes" | cut -d: -f2)
if [ "$op" == ">=" ]; then
test_coord=$(echo "$coords" | sort -nr | head -n1)
at_edge=$(( active_coord >= test_coord ? 1 : 0 ))
else
test_coord=$(echo "$coords" | sort -n | head -n1)
at_edge=$(( active_coord <= test_coord ? 1 : 0 ))
fi;
echo $at_edge
}
select_pane_no_wrap() {
direction=$1
at_edge=$(pane_at_edge $direction)
if [ "$at_edge" = 0 ] ; then
tmux select-pane "-$direction"
else
:
fi
}
echo "U" $(pane_at_edge "U")
echo "D" $(pane_at_edge "D")
echo "L" $(pane_at_edge "L")
echo "R" $(pane_at_edge "R")
echo "R" $(select_pane_no_wrap "L")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment