Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

i use it a lot but want an accompanying binding just for directories

edit: okay done

http://i.imgur.com/n12DYUu.png

Two examples in case you have a preference w/ or w/o the preview:

    fzf_insert_directory_preview() {
      local dir
      dir=$(find . -type d -not -path '*/\.*' | fzf --height 40% --reverse --preview 'tree -C {} | head -200')
      if [[ -n $dir ]]; then
        READLINE_LINE="${READLINE_LINE}${dir}"
        READLINE_POINT=$((${#READLINE_LINE}))
      fi
    }

    fzf_insert_directory() {
      local dir
      dir=$(find . -type d -not -path '*/\.*' | fzf --height 40% --reverse)
      if [[ -n $dir ]]; then
        READLINE_LINE="${READLINE_LINE}${dir}"
        READLINE_POINT=$((${#READLINE_LINE}))
      fi
    }

    bind -x '"\ey": fzf_insert_directory_preview' # alt-y
    bind -x '"\et": fzf_insert_directory' # alt-t
http://ix.io/4rtn/sh

Sent from a LLM



sort by: page size:

This is great, thank you! Just a couple of minor changes to handle softlinks to folders...

  function fcd() {
    local dir;
  
    while true; do
      # exit with ^D
      dir="$(ls -a1F | grep '[/@]$' | grep -v '^./$' | sed 's/@$//' | fzf --height 40% --reverse --no-multi --preview 'pwd' --preview-window=up,1,border-none --no-info)"
      if [[ -z "${dir}" ]]; then
        break
      elif [[ -d "${dir}" ]]; then
        cd "${dir}"
      fi
    done
  }

I've been looking for something like <() for a long time. Thanks for sharing it!

Regarding :h, is it any different than just using dirname?



A nice idea... I may end up using it, though a lot of my folders are the same name and I do like deterministic behavior.

In the meantime, this kicks the pants off separate Finder + Terminal action: http://decimus.net/DTerm/


Okay I think this is more elegant than my workaround. But it doesn’t work for directories, does it?

dired-mode by itself is pretty excellent for navigating directories.

Congrats for getting this out!

> I also wanted an excuse to learn

This is the best reason ever, and not just for you: seeing your GIF I thought "could I achieve that with fzf?". Turns out, yes I can:

    function fcd() {
      local dir;
    
      while true; do
        # exit with ^D
        dir="$(ls -a1p | grep '/$' | grep -v '^./$' | fzf --height 40% --reverse --no-multi --preview 'pwd' --preview-window=up,1,border-none --no-info)"
        if [[ -z "${dir}" ]]; then
          break
        else
          cd "${dir}"
        fi
      done
    }
Certainly not the best code (and definitely not a jab at your implementation!) but, hey, it was purely for the heck of it.

Lately I've been trying to find the joy in programming again, these kind of fun little challenges help a lot, so thanks for sharing, enthusiasm and creativity is contaminating :)


I highly recommend autojump[1] as a simple way to jump to commonly-used working directories. It's saved me a lot of repetitive typing since I discovered it.

[1] https://github.com/joelthelion/autojump


I've also found this extremely useful. It lets you mark directories with a keyword and jump directly to them regardless of where you are. http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-f...

For my purposes that hasn’t been a problem.

I guess I would normally just start with ‘path/to/dir/‘ or ‘/path/to/dir/index.html’


I don’t just want specific directories to autocomplete. Whatever I navigate to is likely something I never even opened but was generated by a script and I now want to do manual changes to the contents. This approach makes for me the rare case as usable as the common one.

Smart idea. Good job! Could you extend bd to jump to bookmarked directories. I often jump between /data... and ~/dir/containing/code/ -- would be useful to have one command help with both scenarios.

Thanks!

And yeah, didn't think of that. It would be neat to be able to tag files or directories and then execute a command to see all the directories with that tag and then enter that directory easily. Maybe i'll try adding that to the next version. Can you think of anything else that would be useful?


directory-local variables in emacs? thank you! I will look at that.

`nnoremap <space><space> :ls<cr>:b<space>`

Is crucial for my personal workflow and one of the only bindings i require.

I use it in conjunction with

`nnoremap - :Explore<cr>` Which opens the best directory navigator in existence (actually dired should be named here)

This changes the game dramatically.

Read about :ls and :b


I've found that Perl works even better for this.

my @allfiles = `ls /somedir/`; for my $file (@allfiles) { chomp $file; ... }

Is a wonderful thing. It's not pretty Perl, but it's still better than Bash, IMO.


This is cool. But often I wish there is a shortcut to open a bunch of files using wildcard characters, e.g :e <dir>/*.rb.

I would highlight the support for directories more. It's a vital feature that none of the others in this space seem to support.

I have a bunch of directories I always go to, and instead of cd-ing on a relative path from where I am, I prefer using an interactive way to select where to go (I’ve aliased this script as “c”):

d=$(ls ~/Dev | fzf)

if [ -z $d ]; then return 0

cd "~/Dev/$d"

next

Legal | privacy