Skip to content

Commit f887227

Browse files
author
Bruno Sutic
committed
Key bindings now work from the sidebar too
1 parent 02ae8b6 commit f887227

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
### master
4+
- key bindings work from the sidebar now too
45

56
### v0.4.0, Sep 04, 2014
67
- change default key bindings to `Tab` and `Backspace`

scripts/toggle.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ sidebar_pane_args() {
3535
}
3636

3737
register_sidebar() {
38-
set_tmux_option "${REGISTERED_SIDEBAR_PREFIX}-${1}" "sidebar"
38+
local sidebar_id="$1"
39+
local pane_id="$2"
40+
set_tmux_option "${REGISTERED_SIDEBAR_PREFIX}-${sidebar_id}" "$pane_id"
3941
}
4042

4143
register_sidebar_for_current_pane() {
@@ -131,7 +133,7 @@ create_sidebar() {
131133
local sidebar_info=$(tmux split-window "$(orientation_option)" -c "$PANE_CURRENT_PATH" -P -F "#{pane_id},#{pane_width}" "$COMMAND")
132134
local sidebar_id=$(echo "$sidebar_info" | cut -d',' -f1)
133135
local sidebar_width=$(echo "$sidebar_info" | cut -d',' -f2) # half a pane
134-
register_sidebar "$sidebar_id"
136+
register_sidebar "$sidebar_id" "$PANE_ID"
135137
register_sidebar_for_current_pane "$sidebar_id"
136138
if sidebar_left; then
137139
tmux swap-pane -U
@@ -158,11 +160,11 @@ current_pane_too_narrow() {
158160
[ $PANE_WIDTH -lt 81 ]
159161
}
160162

161-
exit_unless_pane_can_have_sidebar() {
162-
if current_pane_is_sidebar; then
163-
display_message "Sidebars can't have sidebars!"
164-
exit
165-
fi
163+
execute_command_from_main_pane() {
164+
# get pane_id for this sidebar
165+
local main_pane_id="$(get_tmux_option "${REGISTERED_SIDEBAR_PREFIX}-${PANE_ID}" "")"
166+
# execute the same command as if from the "main" pane
167+
$CURRENT_DIR/toggle.sh "$ARGS" "$main_pane_id"
166168
}
167169

168170
exit_if_pane_too_narrow() {
@@ -187,8 +189,11 @@ toggle_sidebar() {
187189

188190
main() {
189191
if supported_tmux_version_ok; then
190-
exit_unless_pane_can_have_sidebar
191-
toggle_sidebar
192+
if current_pane_is_sidebar; then
193+
execute_command_from_main_pane
194+
else
195+
toggle_sidebar
196+
fi
192197
fi
193198
}
194199
main

0 commit comments

Comments
 (0)