Chdir to the favorite directory.
$ pwd
/home/user/work/projects/first
$ cdf -a first
(Label the path of the working directory with "first")
$ cd
$ pwd
/home/user
$ cdf first
(Chdir to the directory labeled with "first")
$ pwd
/home/user/work/projects/first
usage:
cdf [--] select a label and chdir to the labeled path
cdf [--] <label> chdir to the labeled path
cdf {-a|--add} <label> [<path>] label the path (default: working directory)
cdf {-l|--list} list labels
cdf {-L|--list-with-paths} list labels with paths
cdf {-p|--print} <label> print the labeled path
cdf {-r|--remove} <label(s)> remove labels
cdf {-w|--wrapper} [<shell>] output the wrapper script (default: sh)
cdf --help print usage and exit
supported-shells:
sh, bash, zsh, yash, fish
environment-variables:
CDF_REGISTRY the registry path (default: ~/.config/cdf/registry.json)
CDF_FILTER the interactive filtering command for selecting a label
- Perl (5.14.0 or later)
- Copy
cdf
into your$PATH
. - Make
cdf
executable. - Add the following config to your shell's profile.
Shell | |
---|---|
sh | eval "$(cdf -w)" |
bash | eval "$(cdf -w bash)" |
zsh | eval "$(cdf -w zsh)" |
yash | eval "$(cdf -w yash)" |
fish | source (cdf -w fish | psub) |
$ curl -L https://raw.githubusercontent.com/nil-two/cdf/master/cdf > ~/bin/cdf
$ chmod +x ~/bin/cdf
$ echo 'eval "$(cdf -w bash)"' >> ~/.bashrc
Note: In this example, $HOME/bin
must be included in $PATH
.
Select a label and chdir to the labeled path. It works only when the shell integration is enabled.
$ cdf
(Select a label from labels in the registry, and chdir to the labeled path)
Chdir to the labeled path. It works only when the shell integration is enabled.
$ cdf first
(Chdir to /home/user/work/free/first if /home/user/work/free/first is labeled with "first")
$ cdf home
(Chdir to /home/user if /home/user is labeled with "home")
Label the path. The default path is the working directory.
$ cdf -a work
(Label the working directory with "work")
$ cdf -a bin /home/user/bin
(Label /home/user/bin with "bin")
List labels.
$ cdf -l
first
home
List labels with paths.
$ cdf -L
first /home/user/work/free/first
home /home/user
Print the labeled path.
$ cdf -p first
/home/user/work/free/first
$ cdf -p home
/home/user
Remove labels.
$ cdf -r home
(Remove "home" in the registry)
$ cdf -r first home
(Remove "first" and "home" in the registry)
Print the wrapper script.
The default shell is sh
.
Supported shells are as follows:
- sh
- bash
- zsh
- yash
- fish
$ eval "$(cdf -w)"
(Enable the shell integration for the shell compatible with Bourne Shell)
$ eval "$(cdf -w bash)"
(Enable the shell integration for Bash)
$ eval "$(cdf -w zsh)"
(Enable the shell integration for Zsh)
$ eval "$(cdf -w yash)"
(Enable the shell integration for Yash)
$ source (cdf -w fish | psub)
(Enable the shell integration for Fish)
Print usage.
$ cdf --help
(Print usage)
The path of the registry file.
The default value is $HOME/.config/cdf/registry.json
.
The structure of JSON is as follows:
{
"version": "<registry-version>",
"labels": {
"<label1>": "<path1>",
"<label2>": "<path2>",
...
}
}
The command to use select a label.
The default value is percol
.
# Use fzy to select the label
export CDF_FILTER=fzy
# Use fzf with preview to select the label
export CDF_FILTER='fzf --layout=reverse --preview='"'"'printf "# %s\n" {}; cdf --print {}'"'"''
MIT License
nil2 nil2@nil2.org