mirror of
https://github.com/junegunn/fzf.git
synced 2025-07-29 19:21:59 -07:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4ceb520c1d | ||
|
d761ea5158 | ||
|
7ba93d9f83 | ||
|
b34f93f307 | ||
|
ec040d82dd | ||
|
00190677d4 | ||
|
d38f7a5eb5 | ||
|
ee433ef6e9 | ||
|
d89c9e94ba | ||
|
7e2dfef930 | ||
|
0296fcb5cd |
@@ -1,4 +1,5 @@
|
||||
language: ruby
|
||||
sudo: false
|
||||
rvm:
|
||||
- "1.8.7"
|
||||
- "1.9.3"
|
||||
|
42
fzf
42
fzf
@@ -7,7 +7,7 @@
|
||||
# / __/ / /_/ __/
|
||||
# /_/ /___/_/ Fuzzy finder for your shell
|
||||
#
|
||||
# Version: 0.8.8 (Nov 4, 2014)
|
||||
# Version: 0.8.9 (Dec 24, 2014)
|
||||
#
|
||||
# Author: Junegunn Choi
|
||||
# URL: https://github.com/junegunn/fzf
|
||||
@@ -40,6 +40,7 @@ begin
|
||||
require 'curses'
|
||||
rescue LoadError
|
||||
$stderr.puts 'curses gem is not installed. Try `gem install curses`.'
|
||||
sleep 1
|
||||
exit 1
|
||||
end
|
||||
require 'thread'
|
||||
@@ -955,8 +956,10 @@ class FZF
|
||||
get_mouse
|
||||
end
|
||||
when 'b', 98 then :alt_b
|
||||
when 'd', 100 then :alt_d
|
||||
when 'f', 102 then :alt_f
|
||||
when :esc then :esc
|
||||
when 127 then :alt_bs
|
||||
else next
|
||||
end if ord == 27
|
||||
|
||||
@@ -1012,7 +1015,20 @@ class FZF
|
||||
yanked = ''
|
||||
mouse_event = MouseEvent.new
|
||||
backword = proc {
|
||||
cursor = (input[0, cursor].rindex(/\s\S/) || -1) + 1
|
||||
cursor = (input[0, cursor].rindex(/[^[:alnum:]][[:alnum:]]/) || -1) + 1
|
||||
nil
|
||||
}
|
||||
forward = proc {
|
||||
cursor += (input[cursor..-1].index(/([[:alnum:]][^[:alnum:]])|(.$)/) || -1) + 1
|
||||
nil
|
||||
}
|
||||
rubout = proc { |regex|
|
||||
pcursor = cursor
|
||||
cursor = (input[0, cursor].rindex(regex) || -1) + 1
|
||||
if pcursor > cursor
|
||||
yanked = input[cursor...pcursor]
|
||||
input = input[0...cursor] + input[pcursor..-1]
|
||||
end
|
||||
}
|
||||
actions = {
|
||||
:esc => proc { exit 1 },
|
||||
@@ -1036,12 +1052,7 @@ class FZF
|
||||
ctrl(:e) => proc { cursor = input.length; nil },
|
||||
ctrl(:j) => proc { vselect { |v| v - @rev_dir } },
|
||||
ctrl(:k) => proc { vselect { |v| v + @rev_dir } },
|
||||
ctrl(:w) => proc {
|
||||
pcursor = cursor
|
||||
backword.call
|
||||
yanked = input[cursor...pcursor] if pcursor > cursor
|
||||
input = input[0...cursor] + input[pcursor..-1]
|
||||
},
|
||||
ctrl(:w) => proc { rubout.call /\s\S/ },
|
||||
ctrl(:y) => proc { actions[:default].call yanked },
|
||||
ctrl(:h) => proc { input[cursor -= 1] = '' if cursor > 0 },
|
||||
ctrl(:i) => proc { |o|
|
||||
@@ -1066,10 +1077,19 @@ class FZF
|
||||
:del => proc { input[cursor] = '' if input.length > cursor },
|
||||
:pgup => proc { vselect { |v| v + @rev_dir * (max_items - 1) } },
|
||||
:pgdn => proc { vselect { |v| v - @rev_dir * (max_items - 1) } },
|
||||
:alt_b => proc { backword.call; nil },
|
||||
:alt_bs => proc { rubout.call /[^[:alnum:]][[:alnum:]]/ },
|
||||
:alt_b => proc { backword.call },
|
||||
:alt_d => proc {
|
||||
pcursor = cursor
|
||||
forward.call
|
||||
if cursor > pcursor
|
||||
yanked = input[pcursor...cursor]
|
||||
input = input[0...pcursor] + input[cursor..-1]
|
||||
cursor = pcursor
|
||||
end
|
||||
},
|
||||
:alt_f => proc {
|
||||
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
||||
nil
|
||||
forward.call
|
||||
},
|
||||
:default => proc { |val|
|
||||
case val
|
||||
|
@@ -53,8 +53,25 @@ _fzf_opts_completion() {
|
||||
return 0
|
||||
}
|
||||
|
||||
_fzf_handle_dynamic_completion() {
|
||||
local cmd orig ret
|
||||
cmd="$1"
|
||||
shift
|
||||
|
||||
orig=$(eval "echo \$_fzf_orig_completion_$cmd")
|
||||
if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then
|
||||
$orig "$@"
|
||||
elif [ -n "$_fzf_completion_loader" ]; then
|
||||
_completion_loader "$@"
|
||||
ret=$?
|
||||
eval $(complete | \grep "\-F.* $cmd$" | _fzf_orig_completion_filter)
|
||||
source $BASH_SOURCE
|
||||
return $ret
|
||||
fi
|
||||
}
|
||||
|
||||
_fzf_path_completion() {
|
||||
local cur base dir leftover matches trigger cmd orig
|
||||
local cur base dir leftover matches trigger cmd
|
||||
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
||||
COMPREPLY=()
|
||||
trigger=${FZF_COMPLETION_TRIGGER:-**}
|
||||
@@ -88,13 +105,12 @@ _fzf_path_completion() {
|
||||
else
|
||||
shift
|
||||
shift
|
||||
orig=$(eval "echo \$_fzf_orig_completion_$cmd")
|
||||
[ -n "$orig" ] && type "$orig" > /dev/null 2>&1 && $orig "$@"
|
||||
_fzf_handle_dynamic_completion "$cmd" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
_fzf_list_completion() {
|
||||
local cur selected trigger cmd src ret
|
||||
local cur selected trigger cmd src
|
||||
read -r src
|
||||
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
||||
trigger=${FZF_COMPLETION_TRIGGER:-**}
|
||||
@@ -113,16 +129,7 @@ _fzf_list_completion() {
|
||||
fi
|
||||
else
|
||||
shift
|
||||
orig=$(eval "echo \$_fzf_orig_completion_$cmd")
|
||||
if [ -n "$orig" ] && type "$orig" > /dev/null; then
|
||||
$orig "$@"
|
||||
elif [ -n "$_fzf_completion_loader" ]; then
|
||||
_completion_loader "$@"
|
||||
ret=$?
|
||||
eval $(complete | \grep "\-F.* $cmd$" | _fzf_orig_completion_filter)
|
||||
source $BASH_SOURCE
|
||||
return $ret
|
||||
fi
|
||||
_fzf_handle_dynamic_completion "$cmd" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
12
install
12
install
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd `dirname $BASH_SOURCE`
|
||||
fzf_base=`pwd`
|
||||
@@ -294,8 +294,16 @@ function fzf_key_bindings
|
||||
rm -f $TMPDIR/fzf.result
|
||||
end
|
||||
|
||||
function __fzf_reverse
|
||||
if which tac > /dev/null
|
||||
tac $argv
|
||||
else
|
||||
tail -r $argv
|
||||
end
|
||||
end
|
||||
|
||||
function __fzf_ctrl_r
|
||||
history | fzf +s +m > $TMPDIR/fzf.result
|
||||
history | __fzf_reverse | fzf +s +m > $TMPDIR/fzf.result
|
||||
and commandline (cat $TMPDIR/fzf.result)
|
||||
commandline -f repaint
|
||||
rm -f $TMPDIR/fzf.result
|
||||
|
@@ -50,6 +50,7 @@ class MockTTY
|
||||
@buffer << str
|
||||
@condv.broadcast
|
||||
end
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
@@ -805,6 +806,45 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
tty << "\e[Z\e[Z"
|
||||
tty << "\r"
|
||||
end
|
||||
|
||||
# ALT-D
|
||||
assert_fzf_output %w[--print-query], "", "hello baby = world" do |tty|
|
||||
tty << "hello world baby"
|
||||
tty << alt(:b) << alt(:b) << alt(:d)
|
||||
tty << ctrl(:e) << " = " << ctrl(:y)
|
||||
tty << "\r"
|
||||
end
|
||||
|
||||
# ALT-BACKSPACE
|
||||
assert_fzf_output %w[--print-query], "", "hello baby = world " do |tty|
|
||||
tty << "hello world baby"
|
||||
tty << alt(:b) << alt(127.chr)
|
||||
tty << ctrl(:e) << " = " << ctrl(:y)
|
||||
tty << "\r"
|
||||
end
|
||||
|
||||
# Word-movements
|
||||
assert_fzf_output %w[--print-query], "", "ello!_orld!~ foo=?" do |tty|
|
||||
tty << "hello_world==baby?"
|
||||
tty << alt(:b) << ctrl(:d)
|
||||
tty << alt(:b) << ctrl(:d)
|
||||
tty << alt(:b) << ctrl(:d)
|
||||
tty << alt(:f) << '!'
|
||||
tty << alt(:f) << '!'
|
||||
tty << alt(:d) << '~'
|
||||
tty << " foo=bar foo=bar"
|
||||
tty << ctrl(:w)
|
||||
tty << alt(127.chr)
|
||||
tty << "\r"
|
||||
end
|
||||
end
|
||||
|
||||
def alt chr
|
||||
"\e#{chr}"
|
||||
end
|
||||
|
||||
def ctrl char
|
||||
char.to_s.ord - 'a'.ord + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user