many changes. rewritten mark, newproject, and goto in C. mark is 95% functional, with newproject and goto less so.

This commit is contained in:
Josh Ashton
2023-08-05 12:10:58 -06:00
parent c43e89cff3
commit b5136b661b
7 changed files with 225 additions and 4 deletions
Executable
+41
View File
@@ -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
-2
View File
@@ -1,2 +0,0 @@
#!/bin/zsh
BIN
View File
Binary file not shown.
-1
View File
@@ -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.
+1 -1
View File
@@ -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);
}
Executable
BIN
View File
Binary file not shown.
+183
View File
@@ -0,0 +1,183 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
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;
}