Code Monkey home page Code Monkey logo

zsh-fzy's Introduction

zsh-fzy

zsh-fzy is a zsh plugin that uses fzy for certain fuzzy matching operations. The plugin defines the following Zle widgets:

  • fzy-file-widget: Starts recursive file selection, and inserts the chosen file paths in the command line.

  • fzy-cd-widget: Starts subdirectory selection, and changes to the chosen directory with cd.

  • fzy-history-widget: Starts command history selection, using the existing input (if any) as initial search query, and replaces the command line with the chosen one.

  • fzy-proc-widget: Starts processes selection, and inserts the chosen process ID in the command line.

Installation

It can be installed manually, or by using a plugin manager, e.g. zplug:

zplug aperezdc/zsh-fzy

Configuration

By default the widgets defined by the plugin are not bound. A typical configuration could be:

# ALT-C: cd into the selected directory
# CTRL-T: Place the selected file path in the command line
# CTRL-R: Place the selected command from history in the command line
# CTRL-P: Place the selected process ID in the command line
bindkey '\ec' fzy-cd-widget
bindkey '^T'  fzy-file-widget
bindkey '^R'  fzy-history-widget
bindkey '^P'  fzy-proc-widget

Additional configuration is done using Zsh styles. The following lists the available styles and their defaults:

zstyle :fzy:tmux    enabled      no

zstyle :fzy:history show-scores  no
zstyle :fzy:history lines        ''
zstyle :fzy:history prompt       'history >> '
zstyle :fzy:history command      fzy-history-default-command

zstyle :fzy:file    show-scores  no
zstyle :fzy:file    lines        ''
zstyle :fzy:file    prompt       'file >> '
zstyle :fzy:file    command      fzy-file-default-command

zstyle :fzy:cd      show-scores  no
zstyle :fzy:cd      lines        ''
zstyle :fzy:cd      prompt       'cd >> '
zstyle :fzy:cd      command      fzy-cd-default-command

zstyle :fzy:proc    show-scores  no
zstyle :fzy:proc    lines        ''
zstyle :fzy:proc    prompt       'proc >> '
zstyle :fzy:proc    command      fzy-proc-default-command

Setting :fzy:tmux enabled will use a split pane when the shell is running inside Tmux. Currently there are no options to allow configuration of the Tmux pane used for the widgets. Contributions to address this are very welcome, as well as day-to-day testing with this option enabled.

For each widget, the :fzy:${widget} context contains the following options:

  • show-scores: Whether to let fzy show the matching scores for each entry.
  • lines: The number of lines of the screen to use for the list of candidate matches. If undefined, fzy's default is used. A value can be prefixes with min:, which will cause fzy to use at least a certain amount of lines, plus any additional lines which may be available below until the last row of the terminal (note that this needs an ECMA-48-capable terminal (most are).
  • prompt: The prompt shown before the user input.
  • command: The command executed to generate the list of candidates for selection.

Commands

Commands used to generate lists of candidate entries for completoin must write items to standard output, one per line. Commands fzy-file-default-command, fzy-cd-default-command, and fzy-history-default-command are used by default. The first two use find(1) under the hood, and you may prefer to use other tools like RipGrep to produce the list of candidate elements shown by the widgets:

zstyle :fzy:file command rg --files

Note that the command settings are arrays, please take it into account when specifying them:

zstyle :fzy:file command rg --files    # Correct. Array of two elements.
zstyle :fzy:file command 'rg --files'  # Incorrect. Array of one element.

zsh-fzy's People

Contributors

aperezdc avatar elazar avatar hlascelles avatar maximbaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

zsh-fzy's Issues

Unexpected history match

Thanks for the script, really appreciate it.

When I first open the history widget I get the last entries first as I'd expect but as soon as I start typing the ordering changes and I seem to be getting the shortest matches first.

Not sure where the problem is but I'd like to change this behaviour so the ordering is consistent.

zsh-fzy should take the current value from the command line

Steps:

  1. Type something
  2. Press bindkey
  3. Expect that the initial search should have happened with what was already typed

Code fix would make use of something along the lines of...

        if [[ -z $BUFFER ]]; then
            cmd="fzy"
        else
            cmd="fzy -q "$BUFFER"
        fi

If you agree, I'll create a PR?

placed fzy configuration in .zshrc, didnt work

i dont really know where to put these configs, so i put them in the .zshrc.
sorry for being a newbie.

i placed these in the .zshrc file

zstyle :fzy:tmux    enabled      no

zstyle :fzy:history show-scores  no
zstyle :fzy:history lines        ''
zstyle :fzy:history prompt       'history >> '
zstyle :fzy:history command      fzy-history-default-command

zstyle :fzy:file    show-scores  no
zstyle :fzy:file    lines        ''
zstyle :fzy:file    prompt       'file >> '
zstyle :fzy:file    command      fzy-file-default-command

zstyle :fzy:cd      show-scores  no
zstyle :fzy:cd      lines        ''
zstyle :fzy:cd      prompt       'cd >> '
zstyle :fzy:cd      command      fzy-cd-default-command

zstyle :fzy:proc    show-scores  no
zstyle :fzy:proc    lines        ''
zstyle :fzy:proc    prompt       'proc >> '
zstyle :fzy:proc    command      fzy-proc-default-command

i was giving me and error while using the fzy features

my fzy config:

# fzy plugin settings
bindkey '^F'  fzy-file-widget
bindkey '^A' fzy-cd-widget
bindkey '^H' fzy-history-widget
bindkey '^P' fzy-proc-widget

fzy-cd-widget freezes zsh (or is very slow) in dirs with lots of children

When I use alt-c in my home folder, zsh freezes completely. It no longer responds to any input, including control-C, and never seems to finish.

Also, in other places with deep dir structures (some large production projects, for example), there is a noticeable slowdown after pressing alt-c before seeing any results.

Make commands configurable

I'd like to replace find command used in fzy-file-widget with something else, for example rg --files. Same would apply for fzy-cd-widget.

This would allow me to ignore certain files and folders, for example I never want to look for files inside .git directory.

Feature request: fzy-proc-widget

Hi again ๐Ÿ˜‰

FZF completion has a neat feature, usually Ctrl+T is working on a list of files, but if I type $ kill and press Ctrl+T, FZF will show me list of processes instead of list of files.

It does't have to be the same key binding like in FZF, but I would like to have such widget so that it's easier to find a process to kill.

Esc to abort

Thanks for nice write up. Any idea how bind Esc to abort fzf-history-widget?

LICENSE

I'd like to package this for nixpkgs. Do you have a LICENSE for this?

Show fzy under prompt, not on top of it

It would be very useful to show fzy under prompt, so the currently typed command remains visible.

Let's say you want to open two files at once in vim. Because fzy lacks multiselect, the only available way is to trigger zsh-fzy multiple times. With #11 I sneaked in a little patch that allows to do so with just pressing Ctrl+T instead of <Space>Ctrl+T, but because you can't see the prompt you can easily forget which files you've already selected and which not.

Same applies for proc widget, if you want to kill multiple processes at once, you want to see your kill command build up, select first process, see that your kill became kill 1234 , select second process, see that your command expanded to kill 1234 5678 , etc.

I didn't find yet how fzf achieves this, do you have a hint for me maybe?

I even think this behavior should replace the current behavior, i.e. I wouldn't add a configuration option to return the current approach where fzy overlays prompt. But if you deliberately wanted this, then of course I'm happy to make it configurable.

Use manually typed prefix for file widget as starting point of the search

Pressing Ctrl+T now searches starting from the current directory.

Sometimes I'd like to type a prefix and then press Ctrl+T to search from there. Suppose I'm in ~/work/project/vendor/ and I want to move here a file from ~/Downloads, I imagine typing mv ~/Downloads/ and pressing Ctrl+T to start the search.

The paths could be relative, i.e. if my vendor folder is huge and I just want to find a file of specific library, I type vim lib/ and press Ctrl+T to search starting from ~/work/project/vendor/lib/.

To handle cases like vim ~/Down<Ctrl+T> we could say that starting dir is the last typed WORD until the last slash, which in this case is ~/.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.