Change to a directory using a bash menu script and launch vscode

Written by James McDonald

September 19, 2018

This is a shell script that changes to my code development directory and then lists the directorys and gives a numbered menu to enter a number and then change to that directory and launch vscode

You need to add an alias to your .bash_profile so that the script is sourced instead of being run in a new process. (remember to source your ~/.bash_profile to make the alias active)

Menu Script


# /usr/local/bin/

PS3='Please enter your choice: '

# change to my development directory
cd ~/sites || {
	echo "Directory doesn't exist exiting"
	kill -INT $$


# glob for directories only
# add the Quit option to the end of the array

# create the select menu
select opt in "${options[@]}"; do
	case $opt in
	# do something different if they choose quit
		echo "Quitting without changing directory"

	# otherwise default is change directory
		echo "Changing Directory to $opt ($REPLY)"
		cd $opt
                vscode .


Line to add to .bash_profile

# in ~/.bash_profile
alias smenu='. /usr/local/bin/'


You May Also Like…

Toggen builds a new website

So I have built and hosted a new website for Roger Clark Pest Management they are a family owned and operated Pest...


Just downloaded WizTree (not a sponsor) from It seems to do what it says on the tin which is...

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...