|
|
|
|
|
by neontomo
504 days ago
|
|
I made this helper function to navigate my projects, recursively, it will list them if there are more than one, but defaults to the first one unless you give it a number. syntax: projects <project-name> <match index>
alias: function projects() {
if [ -z "$1" ]; then
echo "please provide a project name"
return
fi
local allMatches=$(find ~/Documents/projects -maxdepth 2 -type d -name "*$1*" -print)
local firstMatch=$(echo "$allMatches" | head -n ${2:-1} | tail -n 1)
if [ -z "$firstMatch" ]; then
echo "no matches found"
return
else
if [ $(echo "$allMatches" | wc -l) -gt 1 ]; then
echo "matches found:"
echo "$allMatches" | awk '{print NR ") " $0}'
fi
cd "$firstMatch"
fi
}
|
|