Skip to content

Instantly share code, notes, and snippets.

@zereraz
Last active October 26, 2016 09:24
Show Gist options
  • Save zereraz/7d5e959915aed9998a051a229dbcf143 to your computer and use it in GitHub Desktop.
Save zereraz/7d5e959915aed9998a051a229dbcf143 to your computer and use it in GitHub Desktop.
a script to create c files and open it in vim, "alias c_create=. c_create" is put in .zshrc or .bashrc file
#!/bin/bash
# first argument is the name of the folder and the c file
fileName=$1
# change to the desired folder
filePath='/Users/apple/Documents/coding/c/c_generated/'
folderToCreate="$filePath$fileName"
fileToCreate="$filePath$fileName/$fileName.c"
helloWorld="#include<stdio.h>\n\nint main(){\n\tprintf(\"Hello world\");\n}\n"
if [ ! -d "$folderToCreate" ]; then
echo "creating file at : $folderToCreate"
mkdir $folderToCreate && touch "$fileToCreate"
echo -e $helloWorld >> $fileToCreate
fi
echo "opening file : $fileName"
cd $folderToCreate
vim $fileToCreate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment