Managing home dotfiles created by Pass

I am kind of a beginner with Linux and just started using pass for managing my passwords. I try to keep my home directory rather clean but pass created 2 dotfiles (.gnupg and .password-store) that I don't know how to move to other directories (.local / .config / .cache). I know I can link them, but it doesn't solve the problem of dotfiles in ~/.

$ ls -a
.cache
.config  
Desktop  
Documents  
Downloads  
.gnupg  
.local  
Music  
.password-store  
Pictures
Videos  

Specified problem: is there a way to move .gnupg and .password-store to another directory and still use them?

There is PREFIX variable in binary that defines it but I do not really know how to change it.

PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"

Solution 1:

The meaning of this bit of shell code:

PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"

is: set PREFIX to the value of $PASSWORD_STORE_DIR, using the default of $HOME/.password-store if $PASSWORD_STORE_DIR is not set.

That is, you can set the environment variable PASSWORD_STORE_DIR to whatever path you want to set PREFIX to the desired value. So, say, in your .profile or wherever you prefer to manage environment variables, set:

export PASSWORD_STORE_DIR="$HOME/.config/password-store"

This is documented. Check the man 1 pass:

ENVIRONMENT VARIABLES
PASSWORD_STORE_DIR
      Overrides the default password storage directory.

Where applications provide support for moving dot files, feel free to do so. After all, they advertise this support, and if it doesn't work, it's a bug that's likely to be fixed.


The same goes for gpg, with the GNUPGHOME environment variable:

GNUPGHOME
      If set directory used instead of "~/.gnupg".

Solution 2:

Recommendation: do not bother about where an application creates its .dot configuration files. It also does not matter in your daily computer use: these configuration files are meant to be out of your sight most of the way.

Why: It is the application that decides where to put its user configuration files. The old conventions were to place configuration files directly in your home folder, like pass seems to do, i.e. $HOME/.password-store. More recently, the convention is to move such configuration under .config indeed.

If you want to take over management of where user configuration is stored, you will need to edit source code in many cases. Once you start doing that, you will need to keep patching updates of the software as well. Thus, as a general advise: leave it to the developer on where to place the configuration files. The developer in turn is behaving within current conventions: otherwise he/she can expect a lot of bug requests.

I want to change it anyway for pass: Still, for learning purposes, you could change that easily in the case of pass. This is open source. In this case, the directory is defined within the bash source code of the pass script. In principle, you could change that to:

PREFIX="${PASSWORD_STORE_DIR:-$HOME/.config/password-store}"

Because of the way the PREFIX variable is assigned in the script, there is a safer approach, not requiring to change the script (with thanks to a comment by muru). That is to set or export the variable PASSWORD_STORE_DIR before launching the pass, i.e.

PASSWORD_STORE_DIR=$HOME/.config/password-store

In the script, the variable PREFIX will assume the value of PASSWORD_STORE_DIR if it is defined, else will be set to $HOME/.password-store.

That is likely any change that is required. Any folders are created with the -p switch, so the entire folder structure will be created if .config would not yet exist (e.g. on a very freshly installed system).

This is open source, so you can try: copy the original file under a new name, make an edit and see how it works. If it does not work, you can still copy back the original version.

Note that you need to study the source code again for every app where you want to change that. In some cases, more than one line may need to be changed.

In the end, again... do not bother.