Last active
December 21, 2022 12:17
-
-
Save edr3x/ec6ebbffdcb0c518de61ab5a664321b6 to your computer and use it in GitHub Desktop.
Guide on using fzf and tmux to make project navigation faster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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