Code Monkey home page Code Monkey logo

zfzf's Introduction

zfzf version license: MIT

Zsh + fzf

Demo

demonstration screencast

Install

# zinit
zinit light b0o/zfzf

Usage

zfzf can work in three ways:

  • as a standalone utlity by running the zfzf command
  • as a ZLE (zsh line editor) plugin via a keyboard shortcut
  • as a Zsh completion for file paths (experimental and buggy)

As a standalone utility

zfzf can be invoked by running the zfzf command and optionally passing a path as the first argument. The result will be printed to stdout.

As a ZLE plugin

By default, zfzf is mapped to Alt-period. If your cursor is adjacent to any non-whitespace text when you trigger zfzf, it will attempt to interpret that text as a path.

As a Zsh completion function

If you would like to use zfzf to complete filenames when you press tab, you should call the enable-zfzf-tab function in your .zshrc.

If you use other completion plugins like fzf-tab, you should call enable-zfzf-tab after all other plugins have been loaded and enabled, otherwise another plugin may override zfzf.

You can later call disable-zfzf-tab to restore the prior completion function.


zfzf v0.2.0

zfzf is a fzf-based file picker for zsh which allows you to easily navigate the
directory hierarchy and pick files using keybindings.

zfzf can be used as a standalone program, as an explicit zle widget, and as a
file path completion. By default, zfzf can be explicitly triggered with Alt-.
(this is configurable with the ZFZF_ZSH_BINDING option).

If you would like to use zfzf as your file completion when you press tab, you
should call the enable-zfzf-tab function in your .zshrc. If you use other
completion plugins like fzf-tab, you should call enable-zfzf-tab after all
other plugins have been loaded and enabled. You can later call disable-zfzf-tab
to restore the prior completion function.

Configuration Options
  Environment Variable          Default Value

  ZFZF_ENABLE_COLOR             1
    When enabled, files and previews will be colorized.

  ZFZF_ENABLE_PREVIEW           1
    When enabled, the focused item will be displayed in the fzf preview window.

  ZFZF_ENABLE_DOT_DOTDOT        1
    When enabled, display '.' and '..' at the top of the file listing.

  ZFZF_ZSH_BINDING              ^[. (Alt-.)
    Sets the keybinding sequence used to trigger zfzf. If set to the empty
    string, zfzf will not be bound. You can create a keybinding yourself by
    binding to the zfzf zle widget. See zshzle(1) for more information on key
    bindings.

  ZFZF_ENABLE_BAT               2
  ZFZF_ENABLE_EXA               2
    These options control zfzf's use of non-standard programs. Valid values
    include:
      - 0: Disable program
      - 1: Enable program (Force)
      - 2: Enable program (Optional)
    If the value 2 is used, the program will be enabled only if it is found in
    the PATH or if its path is explicitly specified as described below.

  ZFZF_BAT_PATH                 None
  ZFZF_EXA_PATH                 None
    These options allow paths to non-standard programs to be manually
    specified.

Default Key Bindings

  return             accept final
  alt-return         accept final (return absolute path)
  esc                escape
  ctrl-g             escape (return absolute path)
  alt-o              accept query
  ctrl-d             accept query final
  alt-P              append query
  ctrl-o             replace query
  alt-i              descend into directory or accept file
  alt-.              descend into directory or accept file
  alt-u              ascend into parent directory
  alt->              ascend into parent directory
  alt-U              ascend to next existing ancestor

TODO

  • configurable options
    • fzf key bindings
    • sorting
    • filtering
    • color
    • fzf options

License

© 2021 Maddison Hellstrom

Released under the MIT License.

zfzf's People

Contributors

aragon999 avatar b0o avatar konmeo 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

Watchers

 avatar  avatar  avatar  avatar

Forkers

aragon999

zfzf's Issues

Meta

Just using this issue to host the example gif separate from the repository.

demo-01

Content of `$LBUFFER` is missing

While implementing #8 I noticed that when I am on main (I used v0.2.0 previously), the content of $LBUFFER is not considered anymore.

So when I have:
❯ less
as the current prompt and press alt + . I see the fzf "window", but when selecting an entry I end up with the prompt like:
❯ <selected_file>

Not sure why this is happening, as I not fully understand the changes and the code. But I noticed that when I revert the change, i.e. local left=$$LBUFFER" it works again. So I think there is some problem either with the regex or some other if does not behave as it should.

I only have the additional plugin zsh-autosuggestions installed and use the powerlevel10k theme.

Refine behavior when cursor is in the middle of a path

In the case that the cursor isn’t at the end of a path:

/usr/local/foo/bar
          ^
          cursor

The current behavior is to use the full path as the zfzf target. Other options include:

  • Only use the left-hand side (lhs), then re-append the right-hand side (rhs) after selection
  • Ignore the rhs
  • Use the lhs as the target, but only show subdirectories of the lhs that contain the path on the rhs (either as a direct or distant descendant). Similar to /usr/local/**/foo/bar.

Ideally, zfzf intelligently picks the option that makes the most sense based on context. And/or we could add new parameters to explicitly specify the desired behavior.

Attempt to retain relative/absolute paths and unexpanded sequences

zfzf currently expands and resolves the input path, which leads to a few undesirable behaviors:

Input                 Selection  Current Output               Desired Output
./foo/bar             qux        foo/bar/qux                  ./foo/bar/qux
~/Documents           hi.txt     /home/user/Documents/hi.txt  ~/Documents/hi.txt
/run/user/$UID/pulse  pid        /run/user/1000/pulse/pid     /run/user/$UID/pulse/pid

zfzf should try to retain as much of the user's original input as possbile.

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.