skip to content

Navigating Multiple Projects In Terminal

I always start my development inside the terminal. Changing around different projects slowly became an important part of my workflow. To make this process easier, I’ve been using this function for a while

Function gets the project list from multiple sources and presents them in a readable format. Once selected, it cd’s to that location, hence the name: cdtp, cd to project.

Here is the full script:

set -x PROJECT_PATHS "$HOME/projects" #project locations as list
function cdtp
if test "$argv[1]" = "--help"
echo "Usage: cdtp"
echo "Navigate to your project folder from defined PROJECT_PATHS."
echo "Define PROJECT_PATHS as a colon-separated list of directories to scan."
return 0
end
# Ensure PROJECT_PATHS is defined
if test -z "$PROJECT_PATHS"
echo "Error: PROJECT_PATHS is not defined. Please set it in your shell configuration."
return 1
end
# Gather all subdirectories from the paths in PROJECT_PATHS
set folders (string split : "$PROJECT_PATHS" | xargs -I{} find {} -mindepth 2 -maxdepth 2 -type d ! -name ".*" 2>/dev/null)
# Ensure there are folders to search
if test -z "$folders"
echo "No project folders found in the defined PROJECT_PATHS."
return 1
end
# Map full paths to their basenames
set selections
for folder in $folders
set basename (basename "$folder")
# echo "Adding: $basename | ($folder" # Debugging print
set selections $selections "$basename -> ($folder)"
end
# Use fzf to select a directory based on its basename
set selected (for line in $selections; echo $line; end | fzf --prompt="Select a project: " --height=40% | sed -E 's/.*-> \((.*)\)/\1/' | string trim)
# Handle no selection
if test -z "$selected"
echo "No project selected."
return 1
end
# Navigate to the selected folder
cd $selected
echo "Navigated to ($selected)"
end

from there I either start version control or spin up my code editor.