Add -E to open editor on completion
This commit is contained in:
1
TODO
1
TODO
@@ -2,7 +2,6 @@ VX yait --- TODO
|
||||
|
||||
Todo:
|
||||
* Polish for v1 release
|
||||
* -E to open editor
|
||||
* --extra
|
||||
* --extra-build
|
||||
* --extra-build=nob
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
typedef struct {
|
||||
bool git;
|
||||
bool clang;
|
||||
bool editor;
|
||||
} flag_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -34,6 +35,7 @@ typedef struct {
|
||||
|
||||
char *project;
|
||||
char *name;
|
||||
char *editor;
|
||||
} manifest_t;
|
||||
|
||||
int create_project(manifest_t manifest);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
int create_project(manifest_t manifest)
|
||||
{
|
||||
int status;
|
||||
char buffer[BUFSIZ];
|
||||
char buffer[BUFSIZ], *main_source;
|
||||
|
||||
status = mkdir_p(manifest.project);
|
||||
if (status)
|
||||
@@ -41,6 +41,9 @@ int create_project(manifest_t manifest)
|
||||
|
||||
flast = true;
|
||||
cfprintf(buffer, "");
|
||||
|
||||
snprintf(buffer, BUFSIZ, "%s.c", manifest.project);
|
||||
main_source = str_dup(buffer);
|
||||
break;
|
||||
|
||||
case POSIX:
|
||||
@@ -59,6 +62,8 @@ int create_project(manifest_t manifest)
|
||||
|
||||
flast = true;
|
||||
cfprintf("doc/WHATNEXT", what_next);
|
||||
|
||||
main_source = "src/main.c";
|
||||
break;
|
||||
case FASM:
|
||||
snprintf(buffer, BUFSIZ, "%s.txt", manifest.project);
|
||||
@@ -74,6 +79,8 @@ int create_project(manifest_t manifest)
|
||||
cfprintf("TOOLS/build.sh",
|
||||
"#!/bin/sh\n\ncc SOURCE/main.c -o %s",
|
||||
manifest.project);
|
||||
|
||||
main_source = "SOURCE/main.c";
|
||||
break;
|
||||
case GNU:
|
||||
cfprintf("AUTHORS", "%s", manifest.name);
|
||||
@@ -108,6 +115,8 @@ int create_project(manifest_t manifest)
|
||||
".TH %s 1 \"%s\" \"0.1\" \"User Commands\"\n.SH NAME\n%s \\- a program that does a thing\n.SH SYNOPSIS\n.B %s\n.SH DESCRIPTION\nThis is a program that does a thing.\n.SH AUTHOR\nWritten by %s.",
|
||||
manifest.project, date, manifest.project,
|
||||
manifest.project, manifest.name);
|
||||
|
||||
main_source = "src/main.c";
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
@@ -124,5 +133,10 @@ int create_project(manifest_t manifest)
|
||||
if (manifest.libraries.linenoise)
|
||||
system("git submodule add --quiet https://github.com/antirez/linenoise");
|
||||
|
||||
if (manifest.flags.editor) {
|
||||
snprintf(buffer, BUFSIZ, "nvim %s", main_source);
|
||||
system(buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
10
src/main.c
10
src/main.c
@@ -61,8 +61,8 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
||||
{ 0, 0, 0, 0 } };
|
||||
// clang-format on
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "s:gcn:L:l:", long_opts, NULL)) !=
|
||||
-1) {
|
||||
while ((opt = getopt_long(argc, argv, "s:gcn:L:l:E", long_opts,
|
||||
NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 's':
|
||||
if (strcmp(optarg, "list") == 0) {
|
||||
@@ -103,6 +103,10 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
||||
"warning: %s is not a support library",
|
||||
optarg);
|
||||
break;
|
||||
case 'E':
|
||||
conf->flags.editor = true;
|
||||
conf->editor = getenv("EDITOR");
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
@@ -157,6 +161,7 @@ int main(int argc, char **argv)
|
||||
manifest_t manifest = {
|
||||
.project = "Project",
|
||||
.name = "author",
|
||||
.editor = "nano",
|
||||
.licence = UNL,
|
||||
.style = SIMPLE,
|
||||
|
||||
@@ -168,6 +173,7 @@ int main(int argc, char **argv)
|
||||
|
||||
.flags.git = true,
|
||||
.flags.clang = false,
|
||||
.flags.editor = false,
|
||||
};
|
||||
|
||||
status = parse_standard_options(usage, argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user