Optimizing developer productivity, one line at a time
folder, star, favorites-25129.jpg

Bookmark Your Favorite Directories with the wd ZSH Plugin

When I used to do most of my work on Windows, I used Total Commander as for file management. You can pretty much navigate to your favorite directories within a few key strokes. I missed it a lot when I switched to use Mac and Linux, and spend the majority of my day using command lines. I found myself having to constantly switch workspaces and directories in command line, and it was painful, even with the shell auto-completion enabled. Luckily, I found the tool that made navigation so much easier, the wd plugin for ZSH

The wd ZSH plugin is a command line navigation tool that allows users to navigate their file system with ease. It helps streamline and simplify the navigation process, allowing users to get more done in less time. The plugin provides a more intuitive way of navigating and organizing files, making it a valuable addition to the ZSH shell environment.

Installation

First, you will need to have the zsh shell installed, installation instruction is OS specific, detailed instructions can be found here.

Then install the oh-my-zsh framework with the following command

ShellScript
# install the oh my zsh framework for managing zsh configurations
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Lastly, edit the .zshrc file and add the wd plugin:

ShellScript
plugins=(... wd)

Using wd

ShellScript
> wd --help
Usage: wd [command] [point]

Commands:
    add <point>     Adds the current working directory to your warp points
    add             Adds the current working directory to your warp points with current directory's name
    add! <point>    Overwrites existing warp point
    add!            Overwrites existing warp point with current directory's name
    rm <point>      Removes the given warp point
    rm              Removes the given warp point with current directory's name
    show <point>    Print path to given warp point
    show            Print warp points to current directory
    list            Print all stored warp points
    ls  <point>     Show files from given warp point (ls)
    path <point>    Show the path to given warp point (pwd)
    clean!          Remove points warping to nonexistent directories

    -v | --version  Print version
    -d | --debug    Exit after execution with exit codes (for testing)
    -c | --config   Specify config file (default ~/.warprc)
    -q | --quiet    Suppress all output

    help            Show this extremely helpful text

As you can see, has a few very straight-forward subcommands, which you can easily guess what each will do.

Adding a warp-point (bookmark)

wd add <name> will add the current directory as a bookmark which you can later go to with very few key strokes.

ShellScript
> wd add temp
 * Warp point added

Listing all bookmarks

The command wd list shows all the current warp points

ShellScript
> wd list
 * All warp points:
  scripts  ->  ~/workplace/scripts
     temp  ->  ~/workplace/temp
       ws  ->  ~/workplace
      cfg  ->  ~/workplace/configurations
...

Quick navigation to bookmarked directory

You can use the wd <name> command to navigate to a bookmarked directory.

ShellScript
> wd temp 

I would recommend using short names to reduce the number of keyboard strokes. For example, when I am working on a project and would stay focus on it for more than a few days, I would create use wd add r to create a “recent” bookmark, and I can easily go to this directory with 4 key strokes: wd r.

Leave a comment