Skip to content

Commit ddcee50

Browse files
author
Bruno Sutic
committed
More options to customize tree sidebar
1 parent 4d1336c commit ddcee50

File tree

5 files changed

+60
-28
lines changed

5 files changed

+60
-28
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+
- more options for customizing tree sidebar
45

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

scripts/helpers.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ display_message() {
4040
tmux set-option -gq display-time "$saved_display_time"
4141
}
4242

43-
key_not_defined() {
44-
local key="$1"
45-
local search_value="$(tmux show-option -gqv "${VAR_KEY_PREFIX}-${key}")"
46-
[ -z $search_value ]
47-
}
48-
4943
stored_key_vars() {
5044
tmux show-options -g |
5145
\grep -i "^${VAR_KEY_PREFIX}-" |

scripts/tree_helpers.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# file sourced from ./sidebar.tmux
2+
custom_tree_command="$CURRENT_DIR/scripts/custom_tree.sh"
3+
4+
command_exists() {
5+
local command="$1"
6+
type "$command" >/dev/null 2>&1
7+
}
8+
9+
tree_command() {
10+
if command_exists "tree"; then
11+
echo "tree"
12+
else
13+
echo "$custom_tree_command"
14+
fi
15+
}
16+
17+
tree_key() {
18+
get_tmux_option "$TREE_OPTION" "$TREE_KEY"
19+
}
20+
21+
tree_focus_key() {
22+
get_tmux_option "$TREE_FOCUS_OPTION" "$TREE_FOCUS_KEY"
23+
}
24+
25+
tree_pager() {
26+
get_tmux_option "$TREE_PAGER_OPTION" "$TREE_PAGER"
27+
}
28+
29+
tree_position() {
30+
get_tmux_option "$TREE_POSITION_OPTION" "$TREE_POSITION"
31+
}
32+
33+
tree_width() {
34+
get_tmux_option "$TREE_WIDTH_OPTION" "$TREE_WIDTH"
35+
}

scripts/variables.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
VAR_KEY_PREFIX="@sidebar-key"
2-
OPTION_DELIMITER="->"
32
REGISTERED_PANE_PREFIX="@-sidebar-registered-pane"
43
REGISTERED_SIDEBAR_PREFIX="@-sidebar-is-sidebar"
54

5+
TREE_KEY="Tab"
6+
TREE_OPTION="@sidebar-tree"
7+
8+
TREE_FOCUS_KEY="Bspace"
9+
TREE_FOCUS_OPTION="@sidebar-tree-focus"
10+
11+
TREE_PAGER="less -S"
12+
TREE_PAGER_OPTION="@sidebar-tree-pager"
13+
14+
TREE_POSITION="left"
15+
TREE_POSITION_OPTION="@sidebar-tree-position"
16+
17+
TREE_WIDTH="40"
18+
TREE_WIDTH_OPTION="@sidebar-tree-width"
19+
620
SUPPORTED_TMUX_VERSION="1.9"
721

822
SIDEBAR_DIR="$HOME/.tmux/sidebar"

sidebar.tmux

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,18 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
source "$CURRENT_DIR/scripts/helpers.sh"
66
source "$CURRENT_DIR/scripts/variables.sh"
7-
8-
custom_tree_command="$CURRENT_DIR/scripts/custom_tree.sh"
9-
10-
command_exists() {
11-
local command="$1"
12-
type "$command" >/dev/null 2>&1
13-
}
14-
15-
tree_command() {
16-
if command_exists "tree"; then
17-
echo "tree"
18-
else
19-
echo "$custom_tree_command"
20-
fi
21-
}
7+
source "$CURRENT_DIR/scripts/tree_helpers.sh"
228

239
set_default_key_binding_options() {
2410
local tree_command="$(tree_command)"
25-
if key_not_defined "Tab"; then
26-
set_tmux_option "${VAR_KEY_PREFIX}-Tab" "$tree_command | less -S,left,40"
27-
fi
28-
if key_not_defined "Bspace"; then
29-
set_tmux_option "${VAR_KEY_PREFIX}-Bspace" "$tree_command | less -S,left,40,focus"
30-
fi
11+
local tree_key="$(tree_key)"
12+
local tree_focus_key="$(tree_focus_key)"
13+
local tree_pager="$(tree_pager)"
14+
local tree_position="$(tree_position)"
15+
local tree_width="$(tree_width)"
16+
17+
set_tmux_option "${VAR_KEY_PREFIX}-${tree_key}" "$tree_command | ${tree_pager},${tree_position},${tree_width}"
18+
set_tmux_option "${VAR_KEY_PREFIX}-${tree_focus_key}" "$tree_command | ${tree_pager},${tree_position},${tree_width},focus"
3119
}
3220

3321
set_key_bindings() {

0 commit comments

Comments
 (0)