feat: add configurable case sensitivity (ignorecase/smartcase/casesensitive)

This commit is contained in:
Max Görner 2026-07-08 11:41:18 +02:00
parent 0cbc040059
commit f01985fbe9
4 changed files with 74 additions and 3 deletions

View file

@ -81,6 +81,23 @@ And the keys:
set -g @jump-keys 'aoeuidhtns'
```
The case sensitivity setting can be configured as well. The default is
case-insensitive search. With casesensitive tmux-jump will only match the
search character if the case matches. With smartcase, tmux-jump will match the
search character case-insensitively if the search character is lowercase, and
case-sensitively if the search character is uppercase.
```
# case-insensitive search (default)
set -g @jump-key-case 'ignorecase'
# case-sensitive only when the search character is uppercase
set -g @jump-key-case 'smartcase'
# always case-sensitive
set -g @jump-key-case 'casesensitive'
```
## Similar Projects
* [vimium](https://vimium.github.io/)

View file

@ -131,12 +131,23 @@ def async_detect_user_escape(result_queue)
end
end
def matches_case?(char, jump_to_char)
case ENV.fetch('JUMP_KEY_CASE', 'ignorecase')
when 'casesensitive'
char == jump_to_char
when 'smartcase'
jump_to_char =~ /[[:upper:]]/ ? char == jump_to_char : char.downcase == jump_to_char
else # ignorecase (default)
char.downcase == jump_to_char.downcase
end
end
def positions_of(jump_to_char, screen_chars)
positions = []
positions << 0 if screen_chars[0] =~ /\w/ && screen_chars[0].downcase == jump_to_char
positions << 0 if screen_chars[0] =~ /\w/ && matches_case?(screen_chars[0], jump_to_char)
screen_chars.each_char.with_index do |char, i|
if (char =~ /\w/).nil? && screen_chars[i+1] && screen_chars[i+1].downcase == jump_to_char
if (char =~ /\w/).nil? && screen_chars[i+1] && matches_case?(screen_chars[i+1], jump_to_char)
positions << i+1
end
end

View file

@ -3,10 +3,11 @@
tmp_file="$(mktemp)"
tmux command-prompt -1 -p 'char:' "run-shell \"printf '%1' >> $tmp_file\""
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
export JUMP_BACKGROUND_COLOR=$(get_tmux_option "@jump-bg-color" "\e[0m\e[32m")
export JUMP_FOREGROUND_COLOR=$(get_tmux_option "@jump-fg-color" "\e[1m\e[31m")
export JUMP_KEYS_POSITION=$(get_tmux_option "@jump-keys-position" "left")
export JUMP_KEYS=$(get_tmux_option "@jump-keys" "jfhgkdlsa")
export JUMP_KEY_CASE=$(get_tmux_option "@jump-key-case" "ignorecase")
ruby "$current_dir/tmux-jump.rb" "$tmp_file"

View file

@ -63,6 +63,48 @@ RSpec.describe 'tmux-jump' do
expect(positions_of('s', simple_screen)).to eq []
end
end
context 'with ignorecase (default)' do
let(:mixed_case_screen) { "Hello hello HELLO" }
it 'matches lowercase and uppercase chars regardless of input case' do
expect(positions_of('h', mixed_case_screen)).to eq [0, 6, 12]
expect(positions_of('H', mixed_case_screen)).to eq [0, 6, 12]
end
end
context 'with casesensitive' do
around do |example|
ENV['JUMP_KEY_CASE'] = 'casesensitive'
example.run
ENV.delete('JUMP_KEY_CASE')
end
let(:mixed_case_screen) { "Hello hello HELLO" }
it 'only matches chars with the same case as input' do
expect(positions_of('h', mixed_case_screen)).to eq [6]
expect(positions_of('H', mixed_case_screen)).to eq [0, 12]
end
end
context 'with smartcase' do
around do |example|
ENV['JUMP_KEY_CASE'] = 'smartcase'
example.run
ENV.delete('JUMP_KEY_CASE')
end
let(:mixed_case_screen) { "Hello hello HELLO" }
it 'is case-insensitive when input is lowercase' do
expect(positions_of('h', mixed_case_screen)).to eq [0, 6, 12]
end
it 'is case-sensitive when input is uppercase' do
expect(positions_of('H', mixed_case_screen)).to eq [0, 12]
end
end
end
describe 'keys_for' do