tldr-pages / tldr-c-client

C command-line client for tldr pages
MIT License
296 stars 49 forks source link

Specify cache directory with TLDR_CACHE_DIR #41

Closed packrat386 closed 4 years ago

packrat386 commented 5 years ago

What does it do?

Currently the cache will always live in the home directory. This allows the user to specify a directory to store the cache in with the TLDR_CACHE_DIR environment variable. If the environment variable is not set, the default will still be the home directory.

Why the change?

Requested by #37

Also it's been too long since I got to write any C

How can this be tested?

Where to start code review?

The gethome() function in utils.c

Relevant tickets?

37

Questions?

Right now setting TLDR_CACHE_DIR to /some/path will result in populating a directory /some/path/.tldrc. Should this instead just put the cache data directly in /some/path and skip the "extra" directory?

Also is it worth computing the result of gethome() only once and caching it? I don't know if calls to getenv() are expensive.

wedens commented 5 years ago

I'd also save cache to XDG_CACHE_HOME if it's set and TLDR_CACHE_DIR is unset.