Skip to content

Commit

Permalink
Added checks for XDG_CACHE_HOME, switched to malloc for next_director…
Browse files Browse the repository at this point in the history
…ies allocation
  • Loading branch information
mananapr committed Jan 21, 2019
1 parent 6e7f889 commit 9be9889
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ To install, simply move the generated executable to a directory that is in your
| <kbd>q</kbd> | Quit |

## Directories Used
`cfiles` uses `$HOME/.cache/cfiles` directory to store the clipboard file. This is used so that the clipboard
`cfiles` uses `$XDG_CACHE_HOME/cfiles` directory to store the clipboard file. This is used so that the clipboard
can be shared between multiple instances of `cfiles`. That's why I won't be adding tabs in `cfiles` because multiple
instances can be openend and managed by any terminal multiplexer or your window manager.
Note that this also means the selection list will persist even if all instances are closed.

`cfiles` also uses `$HOME/.local/share/Trash/files` as the Trash Directory, so make sure this directory exists before you try to delete a file.

For storing bookmarks, `cfiles` uses `$HOME/.cache/cfiles/bookmarks` file. Bookmarks are stored in the form `<key>:<path>`. You can either edit this file directly
For storing bookmarks, `cfiles` uses `$XDG_CACHE_HOME/cfiles/bookmarks` file. Bookmarks are stored in the form `<key>:<path>`. You can either edit this file directly
or press `m` in `cfiles` to add new bookmarks.

`cfiles` looks for external scripts in the `$HOME/.cache/cfiles/scripts` directory. Make sure the scripts are executable before moving them to the scripts directory.
`cfiles` looks for external scripts in the `$XDG_CACHE_HOME/cfiles/scripts` directory. Make sure the scripts are executable before moving them to the scripts directory.

If `$XDG_CACHE_HOME` is not set, then `$HOME/.cache` is used.

## Image Previews
`cfiles` uses `w3mimgdisplay` to generate imagepreviews. To setup imagepreviews, move the `displayimg` and `clearimg` scripts to wherever you like and the set the appropriate path in `config,h`.
Expand Down
22 changes: 17 additions & 5 deletions cf.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,21 @@ void init()
snprintf(editor, allocSize+1, "%s", getenv("EDITOR"));
}

// Make the cache directory
// Get the cache directory path
struct stat st = {0};
allocSize = snprintf(NULL,0,"%s/.cache/cfiles",info->pw_dir);
cache_path = malloc(allocSize+1);
snprintf(cache_path,allocSize+1,"%s/.cache/cfiles",info->pw_dir);
if( getenv("XDG_CACHE_HOME") == NULL)
{
allocSize = snprintf(NULL,0,"%s/.cache/cfiles",info->pw_dir);
cache_path = malloc(allocSize+1);
snprintf(cache_path,allocSize+1,"%s/.cache/cfiles",info->pw_dir);
}
else
{
allocSize = snprintf(NULL,0,"%s/cfiles",getenv("XDG_CACHE_HOME"));
cache_path = malloc(allocSize+1);
snprintf(cache_path,allocSize+1,"%s/cfiles",getenv("XDG_CACHE_HOME"));
}
// Make the cache directory
if (stat(cache_path, &st) == -1) {
mkdir(cache_path, 0751);
}
Expand Down Expand Up @@ -1200,7 +1210,8 @@ int main(int argc, char* argv[])
// Stores number of files in the child directory
len_preview = getNumberofFiles(next_dir);
// Stores files in the child directory
char* next_directories[len_preview];
char** next_directories;
next_directories = (char **)malloc(len_preview * sizeof(char *));
status = getFiles(next_dir, next_directories);

// Selection is a directory
Expand Down Expand Up @@ -1730,6 +1741,7 @@ int main(int argc, char* argv[])
{
free(directories[i]);
}
free(next_directories);

} while( ch != 'q');

Expand Down

0 comments on commit 9be9889

Please sign in to comment.