Change Directory Interactively
When working on a project, there's an easier way to navigate directories without the typical workflow like:
> ls
📂 .github
📂 config
📂 lib
📂 src
📄 .editorconfig
📄 .gitignore
📄 LICENSE.md
📄 README.md
> cd src
Here is a solution using fzf
.
1
cdi() {
2
selected_dir=$(ls -d */ | fzf --no-multi --reverse --cycle --bind "enter:execute(true)+accept")
3
4
if [ -n "$selected_dir" ]; then
5
cd "$(echo $selected_dir | awk '{print $NF}')" || return 1
6
echo "Changed directory into: $selected_dir"
7
else
8
echo "Exit: No directory selected"
9
fi
10
}
Demo
- Run
cdi
- Query directory
- Press
Enter
to change directory