Skip to content

Instantly share code, notes, and snippets.

@brentk
Last active September 27, 2021 21:40
Show Gist options
  • Select an option

  • Save brentk/ed8600145302cdecc8b0e6d7c8d13190 to your computer and use it in GitHub Desktop.

Select an option

Save brentk/ed8600145302cdecc8b0e6d7c8d13190 to your computer and use it in GitHub Desktop.
Bash script to simplify opening a vs solution from a bash prompt
#!/bin/bash
# Bash script to simplify opening a vs solution from a bash prompt
file=""
fileCount=$(ls *.sln 2> /dev/null | wc -l)
if [ $fileCount -eq "0" ]; then
echo "ERROR: No solution files found."
exit 1
fi
if [ $fileCount -ne "1" ]; then
echo "More than one solution file found, please choose which one to open:"
declare -i i=0
for n in *.sln; do
i=$((i+1))
printf ' #%d %s\n' "$i" "$n";
done
printf "\n"
read -p 'Enter file #: ' filenum
i=0
for n in *.sln; do
i=$((i+1))
if [ $i -eq $filenum ]; then
file=$n;
fi
done
if [ "$file" == "" ]; then
echo "Unknown file number $filenum"
exit 1
fi
else
file=$(ls *.sln)
fi
if [ -f "$file" ]; then
echo "Opening $file..."
start $file
else
echo "Solution file $file not found?"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment