Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sensible.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ command_exists() {
type "$command" >/dev/null 2>&1
}

escape_for_regex() {
local inp="$1"
echo $inp | sed 's/\\/\\\\/g'
}

# returns prefix key, e.g. 'C-a'
prefix() {
tmux show-option -gv prefix
Expand All @@ -45,7 +50,7 @@ server_option_value_not_changed() {
}

key_binding_not_set() {
local key="$1"
local key=$(escape_for_regex "$1")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the escape_for_regex method. You can use bash expansions directly

local key="${key//\\/\\\\}"

if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then
return 1
else
Expand All @@ -54,8 +59,8 @@ key_binding_not_set() {
}

key_binding_not_changed() {
local key="$1"
local default_value="$2"
local key=$(escape_for_regex "$1")
local default_value=$(escape_for_regex "$2")
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
# key still has the default binding
return 0
Expand Down