Skip to content

Commit

Permalink
Finish updating paths and finish show
Browse files Browse the repository at this point in the history
  • Loading branch information
chinarjoshi committed Sep 24, 2023
1 parent 56397c8 commit de0ad37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/file_io/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ const char *AUTOENV_FNAME;
// (default: ".env"), otherwise returns the absolute path to ~/.aliases.
void setup_fname_buffers() {
const char *acronym_dirname = getenv("ACRONYM_DIRECTORY");
char *home = getenv("HOME");
if (acronym_dirname && strlen(acronym_dirname) > 0) {
snprintf(ACRONYM_DIRNAME, strlen(acronym_dirname), "%s", acronym_dirname);
} else {
snprintf(ACRONYM_DIRNAME, strlen(ACRONYM_DIRNAME), "%s/.acronym", getenv("HOME"));
snprintf(ACRONYM_DIRNAME, strlen(home) + 10, "%s/.acronym", home);
}

snprintf(TMP_FNAME, sizeof(TMP_FNAME), "%s/.tmpfile", ACRONYM_DIRNAME);
snprintf(TOML_FNAME, sizeof(TOML_FNAME), "%s/.tmpfile.toml", ACRONYM_DIRNAME);
int dirname_len = strlen(ACRONYM_DIRNAME);
snprintf(ALIAS_FNAME, dirname_len + 12, "%s/aliases.sh", ACRONYM_DIRNAME);
snprintf(TMP_FNAME, dirname_len + 10, "%s/.tmpfile", ACRONYM_DIRNAME);
snprintf(TOML_FNAME, dirname_len + 15, "%s/.tmpfile.toml", ACRONYM_DIRNAME);
AUTOENV_FNAME = getenv("AUTOENV_ENV_FILENAME");
if (!AUTOENV_FNAME)
AUTOENV_FNAME = ".env";
Expand Down
18 changes: 6 additions & 12 deletions tests/test_subcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ START_TEST(test_remove_cmd_normal) {
END_TEST

START_TEST(test_show_cmd_normal) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
setup_fname_buffers();
Cli cli = {
.type = SHOW,
.verbosity = 1,
Expand All @@ -122,8 +121,7 @@ START_TEST(test_show_cmd_normal) {
END_TEST

START_TEST(test_show_cmd_local) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
setup_fname_buffers();
Cli cli = {
.type = SHOW,
.verbosity = 1,
Expand All @@ -135,8 +133,7 @@ START_TEST(test_show_cmd_local) {
END_TEST

START_TEST(test_show_cmd_aliases) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
setup_fname_buffers();
AliasListNode b = { .data = "gp", .next = NULL };
AliasListNode a = { .data = "a", .next = &b };
Cli cli = {
Expand All @@ -150,8 +147,7 @@ START_TEST(test_show_cmd_aliases) {
END_TEST

START_TEST(test_show_cmd_commit_hash) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
setup_fname_buffers();
Cli cli = {
.type = SHOW,
.verbosity = 1,
Expand All @@ -163,8 +159,7 @@ START_TEST(test_show_cmd_commit_hash) {
END_TEST

START_TEST(test_sync_cmd_normal) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
setup_fname_buffers();
Cli cli = {
.type = SYNC,
.verbosity = 1,
Expand All @@ -175,8 +170,7 @@ START_TEST(test_sync_cmd_normal) {
END_TEST

START_TEST(test_reccomend_cmd_normal) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
setup_fname_buffers();
Cli cli = {
.type = RECCOMEND,
.verbosity = 1,
Expand Down

0 comments on commit de0ad37

Please sign in to comment.