Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/homerours/jumper
Browse files Browse the repository at this point in the history
  • Loading branch information
homerours committed Oct 21, 2024
2 parents 4d95e50 + e2c7df9 commit 51a0c11
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
11 changes: 6 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ make install
cd "$CURRENT_DIR"

echo
read -p "Update shell configurations files? (y/n) " -r
echo "Update shell configurations files? (y/n)"
read REPLY
echo

if [[ $REPLY == 'y' ]]; then
if [ $REPLY = 'y' ]; then

# Borrowed from https://github.com/junegunn/fzf
append_line() {
Expand Down Expand Up @@ -48,21 +49,21 @@ if [[ $REPLY == 'y' ]]; then
bash_config=~/.bashrc
zsh_config=~/.zshrc
fish_config=~/.config/fish/config.fish
if [[ -f "${bash_config}" ]]; then
if [ -f "${bash_config}" ]; then
append_line 'eval "$(jumper shell bash)"' "${bash_config}"
else
echo "File ${bash_config} does not exists."
echo "Please add 'eval \"\$(jumper shell bash)\"' to your bash config file if you would like to use jumper's mappings within bash."
echo
fi
if [[ -f "${zsh_config}" ]]; then
if [ -f "${zsh_config}" ]; then
append_line 'source <(jumper shell zsh)' "${zsh_config}"
else
echo "File ${zsh_config} does not exists."
echo "Please add 'source <(jumper shell zsh)' to your zsh config file if you would like to use jumper's mappings within zsh."
echo
fi
if [[ -f "${fish_config}" ]]; then
if [ -f "${fish_config}" ]; then
append_line 'jumper shell fish | source' "${fish_config}"
else
echo "File ${fish_config} does not exists."
Expand Down
18 changes: 14 additions & 4 deletions src/jumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ static inline bool exist(const char *path, TYPE type) {
}

static void clean_database(Arguments *args) {
Textfile *f = file_open(args->file_path);
if (!f){
return;
}
char *dir = dirname(strdup(args->file_path));
char *tempname = (char *)malloc((strlen(dir) + 20) * sizeof(char));
if (!tempname) {
Expand All @@ -48,7 +52,6 @@ static void clean_database(Arguments *args) {
exit(EXIT_FAILURE);
}

Textfile *f = file_open(args->file_path);
Record rec;
while (next_line(f)) {
parse_record(f->line, &rec);
Expand Down Expand Up @@ -113,6 +116,10 @@ static void lookup(Arguments *args) {
if (args->n_results <= 0) {
return;
}
Textfile *f = file_open(args->file_path);
if (!f){
return;
}
Heap *heap = heap_create(args->n_results);
if (!heap) {
fprintf(stderr, "ERROR: Could not allocate heap memory.");
Expand All @@ -127,7 +134,6 @@ static void lookup(Arguments *args) {
queries.n = 1;
}

Textfile *f = file_open(args->file_path);
long long now = (long long)time(NULL);
double match_score;
double score;
Expand Down Expand Up @@ -162,6 +168,9 @@ static int print_stats(const char *path) {
long long now = (long long)time(NULL);

Textfile *f = file_open(path);
if (!f){
return -1;
}
Record rec;
while (next_line(f)) {
parse_record(f->line, &rec);
Expand All @@ -176,7 +185,7 @@ static int print_stats(const char *path) {

static void status_file(Arguments *args) {
if (print_stats(args->file_path) != 0) {
printf("ERROR, couldn't open %s\n", args->file_path);
printf("File %s does not exist.\n", args->file_path);
} else if (args->n_results > 0) {
printf("Top %d entries", args->n_results);
if (strlen(args->key) > 0) {
Expand All @@ -187,10 +196,11 @@ static void status_file(Arguments *args) {
lookup(args);
}
}

static void status(Arguments *args) {
if (!args->file_path) {
args->file_path = get_default_database_path(TYPE_directories);
printf("\nDIRECTORIES: ");
printf("DIRECTORIES: ");
status_file(args);
args->file_path = get_default_database_path(TYPE_files);
printf("\nFILES: ");
Expand Down
4 changes: 2 additions & 2 deletions src/textfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Textfile *file_open(const char *path) {
Textfile *f = (Textfile *)malloc(sizeof(Textfile));
f->fp = fopen(path, "r");
if (!f->fp) {
fprintf(stderr, "ERROR: File %s not found\n", path);
exit(EXIT_FAILURE);
free(f);
return NULL;
}
f->line = NULL;
return f;
Expand Down

0 comments on commit 51a0c11

Please sign in to comment.