3

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}"
3
  • 1
    You probably should not move them. Also why are you even seeing them by default they are hidden.
    – David
    Sep 2, 2021 at 14:16
  • You should be leaving the dot-files alone. They aren't supposed to move to somewhere else if they were created directly in the home directory as your password DB software has no idea about the other directions. Dot files are not something you really need to be worried about with regards to legitimate applications
    – Thomas Ward
    Sep 2, 2021 at 14:42
  • No you do not move dotfiles from a /home/$USER/. Mind though that dotfiles are HIDDEN by default ls -ltra The "a" shows hidden files and is required to show those otherwise those are never shown. Same goes for file managers: by default those are hidden and control+h shows them (and hides them)
    – Rinzwind
    Sep 2, 2021 at 14:43

3 Answers 3

6

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".
2
  • Maybe add verbal link to subsection Parameter Expansion in man bash which explains these an other ${parameter:-word} features. It took me much longer to find this reference the first time I encountered this part of bash lore.
    – ojdo
    Sep 3, 2021 at 14:36
  • 1
    @ojdo nothing specific to bash here - this is part of the POSIX specification.
    – muru
    Sep 3, 2021 at 15:00
5

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.

3
  • Works fine but autocompletion broke (only for pass so I dont mind)
    – Rentib
    Sep 2, 2021 at 15:11
  • 2
    Instead of changing the script, you should set and export PASSWORD_STORE_DIR.
    – muru
    Sep 3, 2021 at 1:18
  • @muru Thanks! I now see how this construct works!
    – vanadium
    Sep 3, 2021 at 8:10
3

Leave the dot-files alone if they're created by programs directly in your home directory.

Your applications will NOT know how to map to 'alternate' locations and it is NOT atypical for a ton of dotfiles to be made by different applications. Dotfiles and dot-folders are designed to be used to store application data and not be visible to the average user (i.e. the file browser doesn't show hidden files by default).

Unless your applications you're using permit you to configure a custom data directory, leave your dot files alone. Most applications do not have the mechanism to adjust or move files around or reconfigure where they look for their data - so leave them all alone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.