Skip to content

Instantly share code, notes, and snippets.

@edr3x
Last active December 21, 2022 12:17
Show Gist options
  • Save edr3x/ec6ebbffdcb0c518de61ab5a664321b6 to your computer and use it in GitHub Desktop.
Save edr3x/ec6ebbffdcb0c518de61ab5a664321b6 to your computer and use it in GitHub Desktop.
Guide on using fzf and tmux to make project navigation faster
#!/usr/bin/env bash
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find ~/projects ~/tests -mindepth 1 -maxdepth 1 -type d | fzf)
fi
if [[ -z $selected ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
exit 0
fi
if ! tmux has-session -t=$selected_name 2> /dev/null; then
tmux new-session -ds $selected_name -c $selected
fi
if [[ -z $TMUX ]]; then
tmux attach -t $selected_name
else
tmux switch-client -t $selected_name
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment