Last active
May 17, 2021 14:55
-
-
Save mike-weiner/87233ba7e575773560f6da6e01b518ec to your computer and use it in GitHub Desktop.
A bash script that will create a new file with the given name in the command line argument, save it in a specified directory, and open it in VSCode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script that will start VSCode with a new file saved in a specified directory to edit. | |
# Filename of the new file saved will be taken in as an argument | |
# Directory will be specified within the script | |
# | |
# Location of the directory where the files created by the script should be stored | |
file_location=${HOME}/Documents/Programming/scratchpad | |
# VSCode command line executable | |
vscode_exec=code | |
# Function that will print requirements if the user passes in the -help flag as the first argument | |
function help | |
{ | |
echo "Parameters are: " | |
echo "[Required]: filename" | |
} | |
# Check for '-help' flag | |
if [ $1 == "-help" ]; then | |
help | |
exit 0 | |
fi | |
# Store the filename that the user passed in | |
file_name=$1 | |
# Append path to directory with filename with .$RANOM.txt file type to create a full path to the file that will be touched without overwriting any exisiting files | |
full_file_name=${file_location}/${file_name}.$RANDOM.txt | |
# Touch the new file to create it | |
touch ${full_file_name} | |
# Open the new file in VSCode | |
${vscode_exec} -n ${full_file_name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment