Easily jump to recently used directories with oh-my-zsh's 'd'-like directory history that still saved after exiting the terminal. A directory is considered to be used if you have opened a file or ran your preferred command in that directory.
-
Show the list of 10 most recent used directories with
d
. -
Jump to any directory in the list by typing the number of the directory in the list. You need to use 0 instead of 10 to jump to the 10th directory.
-
A directory path will be put to the top of the list every time you use
v
(vim) to edit files oro
(xdg-open) to open a file from that directory. Or if you like, every time you visit a directory.
- Automatically list all files in the directory you jumped to if it contains 30 or fewer files. You can disable this feature if you like.
- Home or
~/
is never added to the history (we can just typecd
). - Shows the last time a path was removed from the history. This information may help you adjust the history size to better suit your need. To change the history size, refer to this section
You can modify the code to suit your needs. If you follow the installation guide, the script is located in ~/.config/dirjump/dirjump
.
You can change the main command from d
to another by modifying the code below:
dirjump_command="d"
By default, you can also jump with <main command> <directory number>
:
d 8
If you already used any number as aliases, just delete or comment out the code from line 18 to 25.
You can make a spesific command trigger dirjump to put your current directory to the directory history by adding the following line to the end of the script:
alias <yourcommand alias>="propose_dir_path && <yourcommand> " # make sure you put a space before the closing double quote
Here's an example to make vsc
an alias of code
(the command to run VSCode):
alias vsc="propose_dir_path && code "
This is not recommended but if you want dirjump to always put visited directory to the history, add the following snippet to the end of the script:
# If using Zsh
if [ -n "$ZSH_VERSION" ]
then
# Source: https://stackoverflow.com/a/3964198/9157799
chpwd_functions=(${chpwd_functions[@]} propose_dir_path)
else
cd()
{
builtin cd "$@" # https://unix.stackexchange.com/a/366974/307359
propose_dir_path
}
fi
Here, just delete it.
There you go.
-
Download the script.
curl --create-dirs -o ~/.config/dirjump/dirjump https://raw.githubusercontent.com/imambungo/dirjump/master/dirjump
-
Source the script to your shell. Don't forget to restart your terminal afterward.
echo 'source ~/.config/dirjump/dirjump' >> ~/.bashrc
If you use Zsh:
echo 'source ~/.config/dirjump/dirjump' >> ~/.zshrc
-
Delete the script and the directory history file.
rm -rf ~/.config/dirjump
-
Unsource the script from your shell.
grep -Fxv "source ~/.config/dirjump/dirjump" ~/.bashrc > temp; mv temp ~/.bashrc
If you use Zsh:
grep -Fxv "source ~/.config/dirjump/dirjump" ~/.zshrc > temp; mv temp ~/.zshrc #####
If you found bugs, typos, wrong grammar, or have any suggestion or question, feel free to create a new issue.