Johnny.Decimal and the terminal

Hey everyone

I just wanted to drop in and share with you a few things I’ve found helped me with using Johnny.Decimal and the terminal in a very productive way.

I’m liking vimwiki a lot, but that’s probably only relevant to the people using vim already.

The simplest and most fun one is this: I keep my projects in different folders. Some’re in dropbox, some in iCloud etc. I like the setup because it allows me to store (and sync) things where I need them. However, the pats can be quite long to time out. Before using any of the scripts suggested in the forum and on the website, I found a variable called CDPATH, and it is glorious. It’s basically PATH, but for your cd command.

So I can simply add all my Johnny.Decimal folders to my CDPATH and find them wherever I am on my machine. This is, what it looks like in my ~/.zshrc

##########
# CDPATH #
##########

# https://www.theunixschool.com/2012/04/what-is-cdpath.html
# https://www.howtoforge.com/tutorial/linux-command-line-tips-tricks-part-3-cdpath/

if [[ -o interactive ]]; then
    # Make sure the current directory is used first
    export CDPATH="."
    # Add Johnny.Decimal from iCloud
    export CDPATH="$CDPATH:$HOME/Library/Mobile Documents/com~apple~CloudDocs/Documents"
    # Add Johnny.Decimal from DropBox
    export CDPATH="$CDPATH:$HOME/Dropbox/Johnny.Decimal"
fi

What did you find helpful in your setup?

Reviving this old post to share some very cool terminal (`zsh`) features I discovered recently:

1: Named directories

You probably know that `~` will expand do your user home. So the following command will change to your home directory: `cd ~`

Well, did you know that `zsh` knows the concept of named directories, which allows you to define an expansion for any directory.

Example. Assume that the root for your live admin system is `/a/very/long/path` and the root for your small business system ist `/another/very/long/path`. Define them as named directories:

hash -d jLive="/a/very/long/path"
hash -d jBiz="/another/very/long/path"

Now you can change into them like so:

cd ~jLive
pwd
>/a/very/long/path

Because the path will be expanded you can also do things like the following and get tap completion for free:

cd ~jLive/10-19\ Life\ admin/14\ My\ online\ life
1 Like

The other one is more involved and requires fzf, a really powerful fuzzy finder. But it’s relatively straightforward to define a zsh function including fzf that will let you:

  • Find any directory in your jdex
  • cd into it or
  • open it in finder
# JDEX
# ====
# Usage:
# - press 'enter' to cd into the selected directory
# - press 'ctrl-o' to open the selected directory in finder
function jdex () {
    local JDEX_ROOT="${1:?Usage: jdex <root folder>}"
    local target_dir="$(
        find "$JDEX_ROOT" -type d 2>/dev/null | \
            fzf --exact \
                --no-multi \
                --reverse \
                --tmux center,80% \
                --delimiter / \
                --ghost="${JDEX_ROOT:t}" \
                --info-command='echo -e "$FZF_INFO - $FZF_GHOST"'\
                --with-nth -3,-2,-1 \
                --bind 'ctrl-o:execute-silent(open -- {})+abort' \
                --keep-right
            )" || return
    if [[ -z "$target_dir" ]];then
        # target_dir is empty if we execute the bind
        return
    fi
    cd -- "${target_dir:a}"
}
1 Like