syncing
This commit is contained in:
+73
@@ -0,0 +1,73 @@
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.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);
|
||||
exit(2);
|
||||
} else {
|
||||
char cwd[PATH_MAX];
|
||||
if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
printf("cwd: %s\n", cwd);
|
||||
}
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
|
||||
while ((read = getline(&line, &len, f)) != -1) {
|
||||
printf("%s", line);
|
||||
if (strstr(line, input) != NULL) {
|
||||
printf("%s", line);
|
||||
chdir(line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Invalid number of arguments.
|
||||
if (argc != 2) {
|
||||
// error();
|
||||
printf("error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Display help.
|
||||
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
|
||||
printf("help");
|
||||
else
|
||||
validateDir(argv[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user