diff options
Diffstat (limited to 'fzf')
-rwxr-xr-x | fzf | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -7,7 +7,7 @@ # / __/ / /_/ __/ # /_/ /___/_/ Fuzzy finder for your shell # -# Version: 0.8.6 (Jun 27, 2014) +# Version: 0.8.6 (Jun 30, 2014) # # Author: Junegunn Choi # URL: https://github.com/junegunn/fzf @@ -50,8 +50,9 @@ end class FZF C = Curses - attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256, :reverse, - :mouse, :multi, :query, :select1, :exit0, :filter, :extended + attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256, :reverse, :prompt, + :mouse, :multi, :query, :select1, :exit0, :filter, :extended, + :print_query def sync @shr_mtx.synchronize { yield } @@ -91,7 +92,9 @@ class FZF @nth = nil @delim = nil @reverse = false + @prompt = '> ' @shr_mtx = Mutex.new + @print_query = false argv = if opts = ENV['FZF_DEFAULT_OPTS'] @@ -127,7 +130,7 @@ class FZF when '+0', '--no-exit-0' then @exit0 = false when '-q', '--query' usage 1, 'query string required' unless query = argv.shift - @query = query.dup + @query = query when /^-q(.*)$/, /^--query=(.*)$/ @query = $1 when '-f', '--filter' @@ -151,6 +154,13 @@ class FZF @sort = sort.to_i when /^-s([0-9]+)$/, /^--sort=([0-9]+)$/ @sort = $1.to_i + when '--prompt' + usage 1, 'prompt string required' unless prompt = argv.shift + @prompt = prompt + when /^--prompt=(.*)$/ + @prompt = $1 + when '--print-query' then @print_query = true + when '--no-print-query' then @print_query = false when '-e', '--extended-exact' then @extended = :exact when '+e', '--no-extended-exact' then @extended = nil else @@ -220,9 +230,11 @@ class FZF len = empty ? get(:@count) : matches.length if loaded if @select1 && len == 1 + puts @query if @print_query puts empty ? matches.first : matches.first.first exit 0 elsif @exit0 && len == 0 + puts @query if @print_query exit 0 end end @@ -243,6 +255,7 @@ class FZF end def filter_list list + puts @filter if @print_query matches = matcher.match(list, @filter, '', '') if @sort && matches.length <= @sort matches = FZF.sort(matches) @@ -314,12 +327,14 @@ class FZF +2, --no-256 Disable 256-color --black Use black background --reverse Reverse orientation + --prompt=STR Input prompt (default: '> ') Scripting -q, --query=STR Start the finder with the given query -1, --select-1 Automatically select the only match -0, --exit-0 Exit immediately when there's no match -f, --filter=STR Filter mode. Do not start interactive finder. + --print-query Print query as the first line Environment variables FZF_DEFAULT_COMMAND Default command to use when input is tty @@ -352,7 +367,7 @@ class FZF def print_input C.setpos cursor_y, 0 C.clrtoeol - cprint '> ', color(:prompt, true) + cprint @prompt, color(:prompt, true) C.attron(C::A_BOLD) do C.addstr get(:@query) end @@ -382,7 +397,7 @@ class FZF def refresh query, xcur = geta(:@query, :@xcur) - C.setpos cursor_y, 2 + width(query[0, xcur]) + C.setpos cursor_y, @prompt.length + width(query[0, xcur]) C.refresh end @@ -1004,7 +1019,7 @@ class FZF x, y, shift = val.values_at :x, :y, :shift y = @reverse ? (C.lines - 1 - y) : y if y == C.lines - 1 - cursor = [0, [input.length, x - 2].min].max + cursor = [0, [input.length, x - @prompt.length].min].max elsif x > 1 && y <= max_items tv = get(:@yoff) + max_items - y - 1 @@ -1047,8 +1062,9 @@ class FZF end ensure C.close_screen + q, selects = geta(:@query, :@selects) + @stdout.puts q if @print_query if got - selects = call(:@selects, :dup) if selects.empty? @stdout.puts got else |