Skip to content

Commit 23cd5b3

Browse files
committed
BUG: keybinding values undergo globbing, may break mappings
I have configured the copycat search key to '?' (set -g @copycat_search '?' in .tmux.conf), and all of a sudden the mapping was assigned to prefix + 6 instead of prefix + ?. Turned out I had a file ~/6, and the ? mistakenly is expanded to 6. The problem is the unquoted variable reference "for key in $key_bindings". As we need the word splitting for the (undocumented?) feature of allowing multiple key mappings, it cannot be quoted. As a fix, use read with a here-string to perform word splitting in an array variable, and then iterate over the array elements.
1 parent dd24d36 commit 23cd5b3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

copycat.tmux

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ set_start_bindings() {
4545
}
4646

4747
set_copycat_search_binding() {
48-
local key_bindings=$(get_tmux_option "$copycat_search_option" "$default_copycat_search_key")
48+
local key_bindings
49+
read -r -d '' -a key_bindings <<<"$(get_tmux_option "$copycat_search_option" "$default_copycat_search_key")"
4950
local key
50-
for key in $key_bindings; do
51+
for key in "${key_bindings[@]}"; do
5152
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/copycat_search.sh"
5253
done
5354
}
5455

5556
set_copycat_git_special_binding() {
56-
local key_bindings=$(get_tmux_option "$copycat_git_search_option" "$default_git_search_key")
57+
local key_bindings
58+
read -r -d '' -a key_bindings <<<"$(get_tmux_option "$copycat_git_search_option" "$default_git_search_key")"
5759
local key
58-
for key in $key_bindings; do
60+
for key in "${key_bindings[@]}"; do
5961
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/copycat_git_special.sh #{pane_current_path}"
6062
done
6163
}

0 commit comments

Comments
 (0)