diff --git a/goto b/goto new file mode 100755 index 0000000..38ea43c --- /dev/null +++ b/goto @@ -0,0 +1,41 @@ +#!/bin/zsh + +# Dependencies: +# quaxlyqueen/scripts/mark + +BOOKMARKS_FILE=~/.bookmarks + +# Catch any invalid input. +if [[ $# -eq 0 || $# -gt 1 ]]; then + echo "\nImproper usage. Try:" + echo "\ngoto [keyword]" + echo " goto downloads" + echo " goto school" + echo " goto portfolio" + echo " goto -h" + echo " goto --help" + +# Display help. +elif [[ $1 == "-h" || $1 == "--help" ]]; then + echo "\nImproper usage. Try:" + echo "\ngoto [keyword]" + echo " goto downloads" + echo " goto school" + echo " goto portfolio" + echo " goto -h" + echo " goto --help" + +else + + # Locate the bookmark. + if [ $(grep -c "$1" $BOOKMARKS_FILE) -gt 0 ]; then + + # Go to the bookmark + cd $(grep "$1" $BOOKMARKS_FILE | head -n 1) + + # List bookmarks if bookmark was not found. + else + echo "Bookmark not found. Available bookmarks:" + mark -ls + fi +fi diff --git a/gupdate b/gupdate deleted file mode 100755 index 6ef54a9..0000000 --- a/gupdate +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/zsh - diff --git a/mark b/mark index 842f76e..2eb85ef 100755 Binary files a/mark and b/mark differ diff --git a/newproject b/newproject index 7571ff6..20d18ce 100755 --- a/newproject +++ b/newproject @@ -137,7 +137,6 @@ elif [[ $LANG == "python" ]]; then cd $NAME; touch main.py; - echo "print(\"hello world!\")" >> main.py; mark; # Create a new Flutter/Dart project. diff --git a/src/mark.c b/src/mark.c index 2c25632..e75e4dc 100644 --- a/src/mark.c +++ b/src/mark.c @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) { // Append the current directory to the bookmarks file. else if(argc == 1) { char cwd[PATH_MAX]; - fprintf(f, "%s", getcwd(cwd, sizeof(cwd))); + fprintf(f, "\n%s", getcwd(cwd, sizeof(cwd))); printf("Successfully bookmarked %s.", cwd); } diff --git a/src/newproject b/src/newproject new file mode 100755 index 0000000..674de3f Binary files /dev/null and b/src/newproject differ diff --git a/src/newproject.c b/src/newproject.c new file mode 100644 index 0000000..ddec09e --- /dev/null +++ b/src/newproject.c @@ -0,0 +1,183 @@ +#include +#include +#include +#include +#include + +const int numTypes = 8; +int type; +char name[25]; + +const char *types[8]; + +int error() { + printf("Improper usage. Try:"); + + printf("\n\nnewproject { language }"); + printf("\n newproject"); + printf("\n newproject c"); + printf("\n newproject -h"); + printf("\n newproject --help"); + + printf("\n\nSupported languages/stacks:"); + for(int i = 0; i < numTypes; i++) { + printf("%s, ", types[i]); + } + + return 1; +} + +int help() { + printf("Abstracting away command line tools to create projects in various languages."); + printf("\nUser can use with or without arguments. Without arguments, 'newproject' will"); + printf("\nprompt for a supported language, project name, and if a git repository should"); + printf("\nbe created.\n\nBookmarks the new project directory using the 'mark' script."); + printf("\nDetects required tools to use based upon language selected.\n"); + printf("\n\nUsage:\nnewproject { language }"); + printf("\n newproject"); + printf("\n newproject c"); + printf("\n newproject -h"); + printf("\n newproject --help"); + + printf("\n\nSupported languages/stacks:"); + for(int i = 0; i < numTypes; i++) { + printf("%s, ", types[i]); + } + + return 0; +} + +void getName() { + printf("Project name: "); + fgets(name, 25, stdin); +} + +int initC() { + getName(); + mkdir(name, S_IRWXU); + chdir(name); + system("cp -r ~/templates/c/main.c"); + system("mark"); + return 0; +} + +void initRust() { + getName(); + char arduino[1]; + printf("Is this an Arduino project? (y/N): "); + scanf("%s", arduino); + + if(strcmp("y", arduino)) system("cargo generate --git https://github.com/Rahix/avr-hal-template.git"); + else if(strcmp("N", arduino) || strcmp("n", arduino)) { + char cmd[15]; + strcpy(cmd, "cargo new "); + strcat(cmd, name); + + system(cmd); + } else { + printf("\nThe choice is y, N, or n. Please try again."); + initRust(); + } +} + +void initCSharp() { + getName(); + mkdir(name, S_IRWXU); + chdir(name); + system("mark"); + system("dotnet new console"); +} + +void initJava() { + getName(); + mkdir(name, S_IRWXU); + chdir(name); + system("mark"); + system("gradle init"); +} + +void initHtml() { + getName(); + mkdir(name, S_IRWXU); + chdir(name); + + system("cp -r ~/templates/web/public_html"); + chdir("public_html"); + system("mark"); +} + +void initJs() { + getName(); + mkdir(name, S_IRWXU); + chdir(name); + system("mark"); + system("touch main.js"); +} + +void initPython() { + getName(); + mkdir(name, S_IRWXU); + chdir(name); + system("touch main.py"); + system("mark"); +} + +void initFlutter() { + getName(); + char cmd[25]; + strcpy(cmd, "flutter create "); + strcat(cmd, name); + system(cmd); + + chdir(name); + system("mark"); +} + +void initT3() { + system("npm create t3-app@latest"); +} + +void determineLang(char *argv[]) { + printf("determining lang"); + if(strcmp(argv[1], types[0]) == 0) initC(); + else if(strcmp(argv[1], types[1]) == 0) initRust(); + else if(strcmp(argv[1], types[2]) == 0) initCSharp(); + else if(strcmp(argv[1], types[3]) == 0) initJava(); + else if(strcmp(argv[1], types[4]) == 0) initJs(); + else if(strcmp(argv[1], types[5]) == 0) initT3(); + else if(strcmp(argv[1], types[6]) == 0) initPython(); + else if(strcmp(argv[1], types[7]) == 0) initFlutter(); +} + +int main(int argc, char *argv[]) { + types[0] = "c"; + types[1] = "rust"; + types[2] = "c-sharp"; + types[3] = "java"; + types[4] = "js"; + types[5] = "t3"; + types[6] = "python"; + types[7] = "flutter"; + + switch (argc) { + case 1: + printf("Language: "); + char *cmd[25]; + scanf("%s", *cmd); + + determineLang(cmd); + + break; + + case 2: + if(strcmp(argv[1], "-h") == 0) return help(); + else if(strcmp(argv[1], "--help") == 0) return help(); + else determineLang(argv[1]); + + break; + + default: + return error(); + } + return 0; +}