This commit is contained in:
Josh Ashton
2023-07-12 15:16:18 -06:00
parent d85367c819
commit fbf5b4308d
9 changed files with 100 additions and 6 deletions
Executable
BIN
View File
Binary file not shown.
+60
View File
@@ -0,0 +1,60 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
void error() {
printf("\nImproper usage: goto[ keyword ]\n"
" Usage:\n"
" goto downloads\n"
" goto school\n"
" goto portfolio\n"
" goto -h\n"
" goto --help"
);
}
void help() {
printf("\nQuickly navigate to saved bookmarks in the terminal.\n"
" Usage:\n"
" goto downloads\n"
" goto school\n"
" goto portfolio\n"
" goto -h\n"
" goto --help"
);
}
void validateDir(char input[]) {
//char * bookmarksFile = strcat(getenv("HOME"), "/.bookmarks");
char * bookmarksFile = "/home/jashton/.bookmarks";
FILE * f = fopen(bookmarksFile, "r");
// Unable to access file.
if(f == NULL) {
printf("Error accessing file located at %s.\n", bookmarksFile);
return;
}
else {
char cwd[PATH_MAX];
if(getcwd(cwd, sizeof(cwd)) != NULL) {
printf("cwd: %s\n", cwd);
}
chdir("..");
printf("cwd: %s", cwd);
}
}
int main(int argc, char *argv[]) {
// Invalid number of arguments.
if(argc != 2) {
error();
return 1;
}
// Display help.
else if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) help();
else validateDir(argv[1]);
}
+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, getcwd(cwd, sizeof(cwd)));
fprintf(f, "%s", getcwd(cwd, sizeof(cwd)));
printf("Successfully bookmarked %s.", cwd);
}
Executable
BIN
View File
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main() {
printf("%s", getenv("CWD"));
chdir("/home/jashton/dev");
printf("%s", getenv("CWD"));
}