@@ -119,62 +119,57 @@ size_defined() {
119
119
[ -n $SIZE ]
120
120
}
121
121
122
- # this is done just to refresh the main pane. See github issue #14.
123
- touch_resize_main_pane () {
124
- local sidebar_id=" $1 "
125
- if sidebar_left; then
126
- tmux resize-pane -t " $sidebar_id " " -R" 1
127
- else
128
- tmux resize-pane -t " $PANE_ID " " -L" 1
129
- fi
130
- }
131
-
132
- sidebar_left_resize () {
133
- local sidebar_width=" $1 "
122
+ desired_sidebar_size () {
123
+ local half_pane=" $(( PANE_WIDTH / 2 )) "
134
124
if directory_in_sidebar_file " $PANE_CURRENT_PATH " ; then
135
125
# 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 )) "
126
+ echo " $( width_from_sidebar_file " $PANE_CURRENT_PATH " ) "
127
+ elif size_defined && [ $SIZE -lt $half_pane ]; then
128
+ echo $SIZE
140
129
fi
141
130
}
142
131
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 )) "
132
+ resize_sidebar_left () {
133
+ local " $sidebar_id "
134
+ local desired_size=" $( desired_sidebar_size) "
135
+ if [ -n $desired_size ]; then
136
+ tmux resize-pane -x " $(( desired_size - 1 )) "
137
+ # this is done just to refresh the main pane. See github issue #14.
138
+ tmux resize-pane -t " $sidebar_id " " -R" 1
154
139
fi
155
140
}
156
141
157
- split_sidebar () {
142
+ split_sidebar_left () {
158
143
tmux split-window " $( orientation_option) " -c " $PANE_CURRENT_PATH " -P -F " #{pane_id},#{pane_width}" " $COMMAND "
159
144
}
160
145
161
- create_sidebar () {
162
- local sidebar_info=$( split_sidebar )
146
+ create_sidebar_left () {
147
+ local sidebar_info=$( split_sidebar_left )
163
148
local sidebar_id=$( echo " $sidebar_info " | cut -d' ,' -f1)
164
- local sidebar_width=$( echo " $sidebar_info " | cut -d' ,' -f2) # half a pane
165
149
register_sidebar " $sidebar_id " " $PANE_ID "
166
150
register_sidebar_for_current_pane " $sidebar_id "
167
- if sidebar_left ; then
168
- tmux swap-pane -U
169
- sidebar_left_resize " $sidebar_width "
170
- else # sidebar right
171
- sidebar_right_resize " $sidebar_width "
151
+ tmux swap-pane -U
152
+ resize_sidebar_left " $sidebar_id "
153
+
154
+ if no_focus ; then
155
+ tmux last-pane
172
156
fi
157
+ }
158
+
159
+ split_sidebar_right () {
160
+ local sidebar_size=$( desired_sidebar_size)
161
+ tmux split-window " $( orientation_option) " -l " $sidebar_size " -c " $PANE_CURRENT_PATH " -P -F " #{pane_id},#{pane_width}" " $COMMAND "
162
+ }
163
+
164
+ create_sidebar_right () {
165
+ local sidebar_info=$( split_sidebar_right)
166
+ local sidebar_id=$( echo " $sidebar_info " | cut -d' ,' -f1)
167
+ register_sidebar " $sidebar_id " " $PANE_ID "
168
+ register_sidebar_for_current_pane " $sidebar_id "
173
169
174
170
if no_focus; then
175
171
tmux last-pane
176
172
fi
177
- touch_resize_main_pane " $sidebar_id "
178
173
}
179
174
180
175
current_pane_is_sidebar () {
@@ -209,7 +204,11 @@ toggle_sidebar() {
209
204
# fi
210
205
else
211
206
exit_if_pane_too_narrow
212
- create_sidebar
207
+ if sidebar_left; then
208
+ create_sidebar_left
209
+ else
210
+ create_sidebar_right
211
+ fi
213
212
fi
214
213
}
215
214
0 commit comments