diff --git a/README.md b/README.md index d5a48d08744a84fbff68d6d62faa34b298fa15e5..815b06e1ab34d98fce261907515215f3b0f1d0ab 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ fd() { # fda - including hidden directories fda() { - DIR=$(find ${1:-*} -type d 2> /dev/null | fzf) && cd "$DIR" + DIR=$(find ${1:-.} -type d 2> /dev/null | fzf) && cd "$DIR" } # fh - repeat history diff --git a/fzf b/fzf index d135d7ab188d991fc18ac2d280528907730d9d25..ed9e6c62e8b423eeb2894cd684f37f369c3cd888 100755 --- a/fzf +++ b/fzf @@ -347,7 +347,7 @@ class FZF tokens << [line[b...e], true] index = e end - tokens << [line[index..-1], false] + tokens << [line[index..-1], false] if index < line.length tokens.reject { |pair| pair.first.empty? } end @@ -829,6 +829,8 @@ class FZF case w when '' nil + when /^\^(.*)\$$/ + Regexp.new('^' << sanitize(Regexp.escape $1) << '$', rxflag) when /^'/ w.length > 1 ? Regexp.new(sanitize(Regexp.escape(w[1..-1])), rxflag) : nil diff --git a/test/test_fzf.rb b/test/test_fzf.rb index 1c5860b993eeb9ec6ecef22007180aa461c776a6..98818d7584113c8cc775041608f50d0933a70d70 100644 --- a/test/test_fzf.rb +++ b/test/test_fzf.rb @@ -197,6 +197,11 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal list.length, match.call('j', '').length assert_equal list.length - 1, match.call('^j', '').length + # ^ + $ + assert_equal 0, match.call('^juici$', '').length + assert_equal 1, match.call('^juice$', '').length + assert_equal 0, match.call('^.*$', '').length + # ! assert_equal 0, match.call('!j', '').length @@ -332,5 +337,14 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"], FZF::UConv.split("abc\xFFdef") end + + # ^$ -> matches empty item + def test_format_empty_item + fzf = FZF.new [] + item = ['', [[0, 0]]] + line, offsets = fzf.convert_item item + tokens = fzf.format line, 80, offsets + assert_equal [], tokens + end end