1. 44

  2. 10

    I don’t think any other single cli tool has ever had such a big and positive impact on my workflow than fzf has, it’s really a great piece of work.

    1. 6

      Your comment prompted me to buy fzf’s author a coffee or two https://twitter.com/qmacro/status/1377225451995852802

      I need to do this sort of thing more often.

      1. 2

        Thanks for the prompt, I did similar.

        1. 2

          I think that’s a good idea and I will do so also :)

      2. 4

        A handful from my setup:

        • h: navigate through directory history
        • b: bookmark directory paths, jump to bookmarks
        • git-sel-changed and git-edit-changed: use fzf to select from changed files in a git repo. git-edit-changed just wraps git-sel-changed.
        • VimwikiMakeLink: use fzf to select a page / tag to link to in my vimwiki setup.
        • ,f: a vim keybinding to quickly open files by way of fzf
        • ,F bound to FragmentMenu: include output from a fzf menu of scripts starting with fragment-. Date formats, brief markup templates, text decorations, etc.

        Of these, I use h and the vim stuff by far the most, but it’s a great general pattern and I should extend it to other things.

        Relatedly, rofi works pretty well for doing similar tasks under X. More or less a nicer replacement for dmenu.

        1. 1

          mind sharing how you set up h and b?

          1. 2

            First, in .zshrc, keep a log of directory history:

            # Record directory history to a simple text file:
            function chpwd {
              echo "$PWD" >> ~/.directory_history

            I haven’t solved keeping the history for Bash, since I rarely use it on my desktop machine, but SO has Is there a hook in Bash to find out when the cwd changes? which suggests that wrapping cd in a function could work well enough:

            function cd() {
                builtin cd $@

            Next, define h and b themselves. In a file that’s sourced by both Bash or ZSH, so should work fine in .zshrc or .bashrc:

            # Jump around in recent directory history - takes an optional query string: 
            function h {
              if [ ! -z "$@" ]; then
                cd "$(tail -2500 ~/.directory_history | tac | awk '!x[$0]++' | fzf --no-sort --height=50% -q $@)"
                cd "$(tail -2500 ~/.directory_history | tac | awk '!x[$0]++' | fzf --no-sort --height=50%)"
            # Bookmark list - if given a parameter, treats it as a path to add to the list:
            function b {
              if [ ! -z "$@" ]; then
                echo "$(realpath "$@")" >> ~/.directory_bookmarks
                cd "$(sort ~/.directory_bookmarks | uniq | fzf --no-sort --height=50%)"

            The awk '!x[$0]++' bit is handy for a bunch of stuff - I actually keep it in ~/bin/unsorted-unique. Just filters out duplicates from the list.

            Edits: Noticed I could use some extra quoting around directory names in h() and b().

        2. 2

          Small note, gh now supports a --jq parameter that can parse jq syntax so you don’t need the CLI tool separately.

          1. 1

            FZF is my RSS reader. It’s pretty good too, the lack of read/unread tracking is a feature for me and you get a free “unified” view of your items

            1. 1

              This is a pretty great set of examples.

              One thing: the article says

              First, there is no convenient CLI tool like gh to communicate with the JIRA API

              True, there isn’t an official one, but go-jira exists and has been very useful. You can create custom templates and commands for its output so you could easily set up a jira command with output suitable for piping to fzf.

              1. 1

                I love this! I’ve been using FZF in vim for ages but I really need to add it to my shell workflow.

                A suggestion: I prefer BLOG/1232-add-a-verbose-flag-to-the-startup-script as slash placement because then you can do tree .git/refs/heads and see your branches broken down by Jira project. I wrote a git-tree helper to do that

                1. 1

                  I do this extensively in scripts for cloning Git repos, downloading files from cloud storage (see also: rclone), managing plain-text to-do lists, the works. I used Gary Bernhardt’s selecta in all these scripts or years, and recently moved over to fzf with very little fiddling.

                  1. 1

                    This is a really well written post with some great use cases. It also captures beautifully the essence of a shell, for me - the continuum between a command prompt and a script.

                    Specifically this post has opened the door to the next chapter in my fzf learning, namely the preview mechanism.

                    1. 1

                      I was inspired to write a post of my own on this subject: SAP Tech Bytes: Exploring SAP-samples with gh and fzf