Blazing Fast File Management for Terminal ⚡️
The Problem: “cd” & “ls” sucks 👎
keep 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 the 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 gonna need some perquisites to follow with me
Zsh
Tmux
Zoxide
LF
Fzf
Solution 1: Zoxide
zoxide is a marter cd command
this one is pretty cool, here is what it’s doing:
it remembers all directories you visit, and organizes them by most frequent
all you need is to type some letters from the name
des => Desktop
it jumps immediately there (super super cool)
step 1: Install it with Homebrew
brew install zoxide
step 2: Initialize in ~/.zshrc
- open your ~/.zshrc file and add this to initialize it
eval "$(zoxide init zsh)"
- source ~/.zshrc to apply the changes
source ~/.zshrc
step 3: Use zoxide instead of “cd”
first, you need to visit the directories you want to jump to
so, zoxide can identify it, and Fuzzy find it
type
z
+ any letters you remember from the directory
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 🤫
if you’re like me, using Vim navigation keys hjkl
After you get used to it, you suddenly want to use them everywhere
LF does exactly that, it works like columns view in Finder but with Vim
But don’t get me wrong, it still works with regular “Arrow” keys as well
Step 1: Install it with Homebrew
brew install lf
Step 2: Change directory on quit
“ It's funny, but for some reason, it didn’t change the directory on quit”
It’s like the main point, right !! 🥲
so let's fix this with a small function that works as a wrapper to lf
it just saves the last directory path in the temp file, then cd to it
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
few UI interface configurations
shortcuts to jump to my frequent main directories
with a small cheatsheet for favorite LF shortcuts
you gonna find 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
to make sure, that when you use
e
shortcut, it always opens with itthen verify that your default editor changed:
echo $EDITOR
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 to open lf
in a new window, to open any file from the same directory 🚀
Let's go do exactly that, in
~/.tmux.conf
But first, make sure that zsh is our default shell for tmux conf
# set default shell to zsh
set-option -g default-shell /bin/zsh
this smart keybinding
ctrl+f
, open a new window with the name “Files”The new window starts from the same path as well as your current window
And finally it open
lf
directly there ( use q to quit )
# ctrl+f => lf (q)
bind -n C-f new-window -n "files" -c "#{pane_current_path}" "zsh -ic 'lf; zsh'"
- Don’t forget to source
~/.tmux.conf
tmux source-file ~/.tmux.conf
Solution 3: Tmux-fzf Script
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
~/personal
~/work
~/tools
Step 2: Build “Tmux Manager” Bash Script
Create a new file with the name
tmux_
manager.sh
in tools directorychange this file into an executable:
chmod +x tmux_
manager.sh
This script lists all projects, in those directories to fuzzy find
Finally, open the selected project as Tmux Session (or create it if not found)
#!/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 name & replace any (.) with (_)
session_name=$(basename "$session" | tr . _)
# if session isn't already existed, 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 session by name
tmux switch-client -t "$session_name"
Step 3: Create Alias to our “Tmux Manager” script
open ~/.zshrc, to add our new Alias
Don’t forget to source it 😉
source ~/.zshrc
alias tm="~/tools/tmux_manager.sh"
Step 4: Cooool tmux keybinding for “Tmux Manager”
The same trick we did before with
lf
quick shortcut
ctrl+t
will run our tmux manager script aliasit will open in a new tmux window, big list of all projects
your selected project will open in its own Tmux session
tell me that this isn’t cool ?! 🙃
bind -n C-t new-window -n "tmux" "zsh -ic 'tm; zsh'"
- don’t forget to source
~/.tmux.conf
tmux source-file ~/.tmux.conf
Let’s be friends on Twitter 👋
Subscribe to my newsletter
Read articles from Belal Samy directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by