Skip to content

Commit 48413c6

Browse files
author
Bruno Sutic
committed
Fix sidebar right resizing
Fixes #17
1 parent 488b4df commit 48413c6

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### master
44
- more options for customizing tree sidebar
55
- describe various options in the readme
6+
- fix sidebar right resizing
67

78
### v0.5.0, Sep 04, 2014
89
- key bindings work from the sidebar now too

scripts/toggle.sh

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,48 @@ touch_resize_main_pane() {
129129
fi
130130
}
131131

132+
sidebar_left_resize() {
133+
local sidebar_width="$1"
134+
if directory_in_sidebar_file "$PANE_CURRENT_PATH"; then
135+
# use stored sidebar width for the directory
136+
local saved_width="$(width_from_sidebar_file "$PANE_CURRENT_PATH")"
137+
tmux resize-pane -x "$((saved_width - 1))"
138+
elif size_defined && [ $SIZE -lt $sidebar_width ]; then
139+
tmux resize-pane -x "$((SIZE - 1))"
140+
fi
141+
}
142+
143+
sidebar_right_resize() {
144+
local sidebar_width="$1"
145+
local correction
146+
if directory_in_sidebar_file "$PANE_CURRENT_PATH"; then
147+
# use stored sidebar width for the directory
148+
local saved_width="$(width_from_sidebar_file "$PANE_CURRENT_PATH")"
149+
correction="$((sidebar_width - saved_width))"
150+
tmux resize-pane -t "$PANE_ID" -R "$((correction + 1))"
151+
elif size_defined && [ $SIZE -lt $sidebar_width ]; then
152+
correction="$((SIZE - saved_width))"
153+
tmux resize-pane -t "$PANE_ID" -R "$((correction + 1))"
154+
fi
155+
}
156+
157+
split_sidebar() {
158+
tmux split-window "$(orientation_option)" -c "$PANE_CURRENT_PATH" -P -F "#{pane_id},#{pane_width}" "$COMMAND"
159+
}
160+
132161
create_sidebar() {
133-
local sidebar_info=$(tmux split-window "$(orientation_option)" -c "$PANE_CURRENT_PATH" -P -F "#{pane_id},#{pane_width}" "$COMMAND")
162+
local sidebar_info=$(split_sidebar)
134163
local sidebar_id=$(echo "$sidebar_info" | cut -d',' -f1)
135164
local sidebar_width=$(echo "$sidebar_info" | cut -d',' -f2) # half a pane
136165
register_sidebar "$sidebar_id" "$PANE_ID"
137166
register_sidebar_for_current_pane "$sidebar_id"
138167
if sidebar_left; then
139168
tmux swap-pane -U
169+
sidebar_left_resize "$sidebar_width"
170+
else # sidebar right
171+
sidebar_right_resize "$sidebar_width"
140172
fi
141-
if directory_in_sidebar_file "$PANE_CURRENT_PATH"; then
142-
# use stored sidebar width for the directory
143-
local saved_width="$(width_from_sidebar_file "$PANE_CURRENT_PATH")"
144-
tmux resize-pane -x "$((saved_width - 1))"
145-
elif size_defined && [ $SIZE -lt $sidebar_width ]; then
146-
tmux resize-pane -x "$((SIZE - 1))"
147-
fi
173+
148174
if no_focus; then
149175
tmux last-pane
150176
fi

0 commit comments

Comments
 (0)