Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hidakatsuya/acc7eb869699417c336e85940646df0e to your computer and use it in GitHub Desktop.
Save hidakatsuya/acc7eb869699417c336e85940646df0e to your computer and use it in GitHub Desktop.
Quickly cd into directories using fd and fzf

Quickly cd into directories using fd and fzf

Prerequisites

Setup

Just add the following function to your .bashrc or equivalent. Tested on Ubuntu 24.04 with Bash.

d() {
  local results count dir
  
  results=$(fd -td -I -- "$1")
  count=$(printf '%s\n' "$results" | grep -c .)
  
  if [ "$count" -eq 1 ]; then
    cd "$results"
  elif [ "$count" -gt 1 ]; then
    dir=$(printf '%s\n' "$results" | fzf)
    [ -n "$dir" ] && cd "$dir"
  fi
}

Demo

asciicast

@hidakatsuya
Copy link
Author

Updated:

  • If there is only one result, it will directly cd into that directory.
  • Directories in .gitignore are now included in the search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment