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.
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
You’re gonna need some perquisites to follow with me:
zoxide is a smarter cd command
This one is pretty cool; here’s what it does:
des => Desktop
Brew install zoxide.
eval "$(zoxide init zsh)"
source ~/.zshrc
z
+ any letters you remember from the directory.z desk// cd ~/Desktop
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 🤫
Brew install lf.
“ it’s funny, but for some reason, it didn’t change the directory on quit”
Add this function to your~/.zshrc
function lf { local tmp=$(mktemp)
command lf -last-dir-path="$tmp" "$@" cd "$(cat "$tmp")" rm -r "$tmp" }
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 )
| |/ | ___ ___ _ __ / () __ _ | | | / / _ | ' | || |/ ` | | | | | (| () | | | | | | (| | ||| */|| ||| |*|, | |_/
Set hidden # show hidden files set icons # show icons for files/directories set relativenumber # show files/directories relative numbers
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
change your default editor in ~/.zshrc
e
shortcut, it always opens with it.echo $EDITOR
export EDITOR=vi # change default editor to vim
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 🚀
~/.tmux.conf
set-option -g default-shell /bin/zsh
ctrl+f
opens a new window with the name “Files.”lf
directly there ( use q to quit )bind -n C-f new-window -n "files" -c "#{pane_current_path}" "zsh -ic 'lf; zsh'"
~/.tmux.conf
tmux source-file ~/.tmux.conf
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. 🦘
For example
tmux_manager.sh
in the tools directory.chmod +x tmux_manager.sh
#!/usr/bin/env bash
| | _ __ ___ _ ___ __| | ' ` _ | | | \ / / | || | | | | | || |> <|| || ||,//_\
session=$(find ~ ~/personal ~/work/ ~/tools -mindepth 1 -maxdepth 1 -type d | fzf)
session_name=$(basename "$session" | tr . _)
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
tmux switch-client -t "$session_name"
source ~/.zshrc
alias tm="~/tools/tmux_manager.sh"
lf.
ctrl+t
will run our tmux manager script alias.bind -n C-t new-window -n "tmux" "zsh -ic 'tm; zsh'"
~/.tmux.conf
tmux source-file ~/.tmux.conf