cdcommand with an interactive filter
cd command is one of the frequently used commands.
Nevertheless, it is not so easy to handle unfortunately. A directory path given as an argument to
cd command must be a valid path that exists and is able to resolve. In other words, you cannot pass a partial path such as "dir" (you are in
/home/lisa, dir is
The new cd command called "enhancd" enhanced the flexibility and usability for a user. enhancd will memorize all directories visited by a user and use it for the pathname resolution. If the log of enhancd have more than one directory path with the same name, enhancd will pass the candidate directories list to the filter within the ENHANCD_FILTER environment variable in order to narrow it down to one directory.
Thanks to this mechanism, the user can intuitively and easily change the directory you want to go.
- Go to the visited directory in the past
- Easy to filter, using your favorite filter
- Work on Bash and Zsh (Full compatible)
- Go back to a specific parent directory like zsh-bd
- Fuzzy search in a similar name directory
- Support standard input (
echo $HOME | cdis acceptable)
- Custom options (user-defined option is acceptable)
You can fuzzy-search a directory name you want to run
cd. For example, a word "text" is expand to "test" and "txt".
Under Zsh or Bourne shells such as sh and bash, you just source
init.sh into your shell:
$ source ./init.sh
Because enhancd functions must be executed in the context of the current shell, you should run something like above command.
The basic usage of the
cd command that has been implemented by
enhancd is the same as the normal builtin
$ cd [-|..] <directory>
If no arguments are given, enhancd
cd command will display a list of the directory you've visited once, encourage you to filter the directory that you want to move.
$ cd ... /home/lisa/src/github.com/b4b4r07/enhancd/zsh /home/lisa/src/github.com/b4b4r07/gotcha /home/lisa/src/github.com/b4b4r07/blog/public /home/lisa/src/github.com/b4b4r07/blog /home/lisa/src/github.com/b4b4r07/link_test /home/lisa/src/github.com/b4b4r07 /home/lisa/Dropbox/etc/dotfiles /home/lisa/src/github.com/b4b4r07/enhancd > /home/lisa 247/247 > _
The ENHANCD_FILTER variable is specified as a list of one or more visual filter command such as this separated by colon (
It is likely the only environment variable you'll need to set when starting enhancd.
$ ENHANCD_FILTER=peco; export ENHANCD_FILTER
$ENHANCD_FILTER variable can be a list, enhancd will use
$ENHANCD_FILTER to mean the first element unless otherwise specified.
$ ENHANCD_FILTER=fzy:fzf:peco $ export ENHANCD_FILTER
When enhancd takes a hyphen (
-) string as an argument, it searchs from the last 10 directory items in the log. With it, you can search easily the directory you used last.
$ cd - /home/lisa/Dropbox/etc/dotfiles /home/lisa/Dropbox /home/lisa/src/github.com /home/lisa/src/github.com/b4b4r07/cli /home /home/lisa/src /home/lisa/src/github.com/b4b4r07/enhancd /home/lisa/src/github.com/b4b4r07/gotcha /home/lisa/src/github.com/b4b4r07 > /home/lisa/src/github.com/b4b4r07/portfolio 10/10 > _
Then, since the current directory will be delete from the candidate, you just press Enter key to return to the previous directory after type
cd - (
From the beginning,
.. means the directory's parent directory, that is, the directory that contains it. When enhancd takes a double-dot (
..) string as an argument, it behaves like a zsh-bd plugin. In short, you can jump back to a specific directory, without doing
For example, when you are in
cd .. in your terminal:
$ cd .. / home lisa src github.com > b4b4r07 6/6 > _
When moving to the parent directory, the current directory is removed from the candidate.
You can make the option that you thought for your enhancd from 2.2.0 or above.
$ cd --help usage: cd [OPTIONS] [dir] OPTIONS: -h, --help Show help message -V, --version Show version information -G, --ghq Filter ghq list
Those options are defined at config.ltsv. As it is written in this json, the user have to make a directory list file or script that generate the list like this script. Of cource, you can disable those options if you do not like it.
Give me a trial!
Install with zplug:
enhancd can be installed by adding following to your
.zshrcfile in the same function you're doing your other
zplug loadcalls in.
$ zplug "b4b4r07/enhancd", use:init.sh
$ git clone https://github.com/b4b4r07/enhancd $ source /path/to/enhancd/init.sh
The ENHANCD_DIR variable is a base directory path. It defaults to
What is ENHANCD_FILTER?
The ENHANCD_FILTER is an environment variable. It looks exactly like the PATH variable containing with many different filters such as peco concatenated using '
How to set the ENHANCD_FILTER variable?
Setting the ENHANCD_FILTER variable is exactly like setting the PATH variable. For example:
$ export ENHANCD_FILTER="/usr/local/bin/peco:fzf:non-existing-filter"
This above command will hold good till the session is closed. In order to make this change permanent, we need to put this command in the appropriate profile file. The ENHANCD_FILTER command in this example is set with 3 components:
enhancd narrows the ENHANCD_FILTER variable down to one. However, the command does not exist can not be the candidate.
Let us try to test this ENHANCD_FILTER variable.
If cd command does not return error, the settings of ENHANCD_FILTER is success.
How to find the value of the ENHANCD_FILTER variable?
$ echo $ENHANCD_FILTER /usr/local/bin/peco:fzf:non-existing-filter
The ENHANCD_COMMAND environment variable is to change the command name of enhancd
cd. It defaults to
When the command name is changed, you should set new command name to ENHANCD_COMMAND, export it and restart your shell (reload
$ echo $ENHANCD_COMMAND cd $ export ENHANCD_COMMAND=ecd $ source /path/to/init.sh
The ENHANCD_COMMAND may only hold one command name. Thus, in the previous example, it is true that enhancd
cd command name is
ecd, but it is not
cd is turned into original
Besides putting a setting such as this one in your
.zshenv would be a good idea:
ENHANCD_COMMAND=ecd; export ENHANCD_COMMAND
The ENHANCD_DOT_SHOW_FULLPATH environment variable is to set whether to show the full path or not when executing Double-dot. It defaults to
$ export ENHANCD_DOT_SHOW_FULLPATH=1 $ cd .. / /home /home/lisa /home/lisa/src /home/lisa/src/github.com > /home/lisa/src/github.com/b4b4r07 6/6 > _
If you don't want to use the interactive filter, when specifing a double dot (
..), you should set not zero value to
$ENHANCD_DISABLE_DOT. Defaults to 0.
This option is similar to
ENHANCD_DISABLE_DOT. Defaults to 0.
If you don't want to use the interactive filter when you call
cd without an argument, you can set any value but
$ENHANCD_DISABLE_HOME. Defaults to
You can customize the double-dot (
..) argument for enhancd by this environment variable.
If you set this variable any but
.., it gives you the double-dot behavior with that argument; i.e. upward search of directory hierarchy.
cd .. changes current directory to parent directory without interactive filter.
In other words, you can keep original
cd .. behavior by this option.
You can customize the hyphen (
-) argument for enhancd by this environment variable.
If you set this variable any but
-, it gives you the hyphen behavior with that argument; i.e. backward search of directory-change history.
cd - changes current directory to
$OLDPWD without interactive filter.
In other words, you can keep original
cd - behavior by this option.
You can customize the number of rows by "cd -"
This is passed to
head comand as
You can customize to trigger the argumentless
cd behavior by giving the string specified by this environment variable as an argument.
Default is empty string.
If you set this variable any but empty string, it gives you the behavior of
cd with no argument; i.e. backward search of the whole directory-change history.
cd with no argument changes current directory to
$HOME without interactive filter.
In other words, you can keep original behavior of
cd with no argument by this option.
Default is empty. You can run any commands after changing directory with enhancd (e.g.
cd && ls).
Default is 1 (enable). See #33.
The "visual filter" (interactive filter) is what is called "Interactive Grep Tool" according to percol that is a pioneer in interactive selection to the traditional pipe concept on UNIX.
👉percol adds flavor of interactive selection to the traditional pipe concept on UNIX
👉Simplistic interactive filtering tool
👉 🌸fzf is a blazing fast command-line fuzzy finder written in Go
👉 🔍A better fuzzy finder
👉gof - Go Fuzzy
👉Selecta is a fuzzy text selector for files and anything else you need to select
👉Pick is "just like Selecta, but faster"
👉icepick is a reimplementation of Selecta in Rust
👉Utility to make sentaku (selection, 選択(sentaku)) window with shell command
👉hf is a command line utility to quickly find files and execute a command