The Problem: “cd” & “ls” Suck 👎

Using cd command to change the directory and ls to preview files in the current directory may work sometimes, but it’s frustrating to have to use this workflow all the time whenever you want to go somewhere.

The Solution

I will give you 3 solutions not just one to make your life easier in terminal and jump easily between files.

“Give me six hours to chop down a tree, and I will spend the first four sharpening the axe.” — Abraham Lincoln

Let’s Sharpen Our Axe 🪓

You’re gonna need some perquisites to follow with me:

Solution 1: Zoxide

zoxide is a smarter cd command


This one is pretty cool; here’s what it does:



Step 1: Install It With Homebrew

Brew install zoxide.

Step 2: Initialize in ~/.zshrc


eval "$(zoxide init zsh)"


source ~/.zshrc

Step 3: Use Zoxide Instead of “cd”



z desk// cd ~/Desktop

Solution 2: LF Manager

lf (as in "list files") is a terminal file manager written in Go with a heavy inspiration from ranger file manager


Let me tell you a secret; this is my favorite one 🤫




Step 1: Install It With Homebrew

Brew install lf.

Step 2: Change the Directory on Quit

“ it’s funny, but for some reason, it didn’t change the directory on quit”





Add this function to your~/.zshrc

lf Wrapper

function lf { local tmp=$(mktemp)

command lf -last-dir-path="$tmp" "$@" cd "$(cat "$tmp")" rm -r "$tmp" }

Step 3: Customize Your “lfrc” File

It’s the LF config file to customize it; I like to keep it minimal.



you’re gonna find it at ~/.config/lf/lfrc ( if you can’t find it, create it )

| |/ | ___ ___ _ __ / () __ _ | | | / / _ | ' | || |/ ` | | | | | (| () | | | | | | (| | ||| */|| ||| |*|, | |_/

UI

Set hidden # show hidden files set icons # show icons for files/directories set relativenumber # show files/directories relative numbers

Jump Shortcuts

map gh cd ~ # use 'gh' to go home directory map gp cd ~/personal/ # use 'gp' to go personal directory map gw cd ~/work/ # use 'gw' to go work directory map gt cd ~/tools/ # use 'gt' to go tools directory map gd cd ~/Downloads/ # use 'gd' to go downloads directory map gv cd /Volumes/ # use 'gv' to go volumes for (external drives) map gb cd ~/brainExt # use 'gb' to go obsidian BrainExt vault

Fav Shortcuts

hjkl/gg/G # Vim-like Navigation (move)

space/v/u # select/invert/unselect (select)

y/d/p/c # yank/delete/paste/clear (change)

i/e/l # open with less/default-editor/default-app (open)

change your default editor in ~/.zshrc



export EDITOR=vi # change default editor to vim

Step 4: Cool Tmux Keybinding

Imagine this scenario: you’re working on a file in Tmux, then do a quick shortcut open lf in new window to open any file from the same directory 🚀



Set the Default Shell to zsh

set-option -g default-shell /bin/zsh



ctrl+f => lf (q)

bind -n C-f new-window -n "files" -c "#{pane_current_path}" "zsh -ic 'lf; zsh'"

tmux source-file ~/.tmux.conf

Solution 3: Tmux-fzf Script

For this one, we don’t just use another utility. We build our own tmux manager script to fuzzy find all our project files in specific directories and jump. 🦘

Step 1: Organize Your Project Files in Specific Directories

For example

Step 2: Build “Tmux Manager” Bash Script




#!/usr/bin/env bash


| | _ __ ___ _ ___ __| | ' ` _ | | | \ / / | || | | | | | || |> <|| || ||,//_\

use fuzzy finder to get my working directories paths

session=$(find ~ ~/personal ~/work/ ~/tools -mindepth 1 -maxdepth 1 -type d | fzf)

get last part as a name & replace any (.) with (_)

session_name=$(basename "$session" | tr . _)

if the session doesn't already exist, create it.

if ! tmux has-session -t "$session_name" 2> /dev/null; then # remove err msg to null tmux new-session -s "$session_name" -c "$session" -d fi

switch to the session by name

tmux switch-client -t "$session_name"

Step 3: Create an Alias to Our “Tmux Manager” Script



alias tm="~/tools/tmux_manager.sh"

Step 4: Cooool tmux keybinding for “Tmux Manager”






bind -n C-t new-window -n "tmux" "zsh -ic 'tm; zsh'"



tmux source-file ~/.tmux.conf

Let’s Be Friends on Twitter 👋

https://twitter.com/belalsamyyy