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