Favor is a powerful tool designed to streamline your workflow by allowing you to swiftly switch working directories in your terminal. Built with Go and integrated with zsh, Favor is equipped with a robust set of features including multiple trees scan, directory prefixing, and stdin picking.
Installing Favor is straightforward. It requires Go to be installed on your system. If you don't have Go, you can install it by following the instructions here.
After Go has been installed, Favor can be installed by running the following command in your terminal:
go install github.com/kovetskiy/favor@latest
Favor utilizes a configuration file to set its behavior. This YAML file defines key parameters including the number of threads Favor will use, the picker tool settings, the votes database path, globally ignored directories, and specific directory trees for scanning.
Here is a sample configuration:
threads: 12
picker:
- fzf
- --sort
- --no-exact
- --tiebreak=index
votes_path: ~/.config/favor/votes.db
ignore_global:
- .git
- vendor
trees:
- name: go
dir: ~/go/src/
min_depth: 2
max_depth: 3
ignore:
- company.com
- name: src
dir: ~/sources/
max_depth: 3
ignore:
- company.com
- name: vim
dir: ~/.vim/bundle/
max_depth: 1
-
threads
: This parameter controls the number of threads the tool uses for scanning directory trees. A higher number may speed up the scanning process on systems with multiple cores. -
picker
: Here you specify the command and flags for the tool you use to pick directories from the list generated by Favor. The example usesfzf
, a popular command-line fuzzy finder. -
votes_path
: This is the location where Favor stores its votes database. The votes system is used to rank directories based on your selection frequency, allowing you to navigate to your most frequently used directories faster. -
ignore_global
: List of patterns that should be ignored in every scanned tree. -
trees
: This is a list of directory trees that Favor will scan. Each tree is defined by aname
,dir
,min_depth
,max_depth
, and optionally anignore
list.
After you have installed and configured Favor, you can use it to quickly switch directories in your terminal.
Add a simple zle function into your .zshrc:
bindkey -v '^N' :favor
zle -N :favor
:favor() {
local favor_dir="$(favor --quiet)"
if [[ ! "$favor_dir" ]]; then
return
fi
eval cd "$favor_dir"
unset favor_dir
#clear
zle -R
lambda17:update
zle reset-prompt
}
Now, open a new terminal and press CTRL+N. You will see a list of directories that Favor has scanned based on your configuration. You can use your picker tool to select a directory from the list and press enter to navigate to it. Favor will also rank the directories based on your selection frequency, allowing you to navigate to your most frequently used directories faster.
This project is licensed under the terms of the MIT license.