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…

List local disks

GET-CimInstance -query "SELECT * from Win32_DiskDrive" DeviceID Caption Partitions Size Model -------- -------...

Create ISO using Powershell

Usage New-IsoFile -NewIsoFilePath C:\tmp\Hyper-V.iso-sources -ImageName Hyper-V -SourceFilePath 'C:\tmp\Hyper-V'...