[PATCH] Add XDG Base Directory support
Nicolai Dagestad
nicolai at dagestad.fr
Thu May 21 23:26:13 CEST 2020
---
We have discussed following the xdg base dir and some concernes have been
raised. I have gone ahead and patched pass, the completions and passmenu.
It looks like the emacs files would need to be patched to but I don't know
lisp and can't even test it so i'll leave that up to somebody using it.
If people can take a look at this and see if it breaks something we could
maybe advance a little on this debat. (I have also cloned a bunch of third
party clients and patch some of them already, I'll be sending patches if
we decide to go forward with this one)
contrib/dmenu/passmenu | 3 +++
src/completion/pass.bash-completion | 3 +++
src/completion/pass.fish-completion | 8 +++++++-
src/completion/pass.zsh-completion | 5 ++++-
src/password-store.sh | 3 +++
5 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 83268bc..af3859d 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -8,6 +8,9 @@ if [[ $1 == "--type" ]]; then
shift
fi
+if [[ -z $PASSWORD_STORE_DIR ]] && [[ ! -d $HOME/.password-store ]];then
+ PASSWORD_STORE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/password-store"
+fi
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
diff --git a/src/completion/pass.bash-completion b/src/completion/pass.bash-completion
index 95d3e1e..32b7404 100644
--- a/src/completion/pass.bash-completion
+++ b/src/completion/pass.bash-completion
@@ -6,6 +6,9 @@
_pass_complete_entries () {
local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}"
+ if [ ! -d "$prefix" ]; then
+ prefix="${XDG_DATA_HOME:-$HOME/.local/share}/password-store/"
+ fi
prefix="${prefix%/}/"
local suffix=".gpg"
local autoexpand=${1:-0}
diff --git a/src/completion/pass.fish-completion b/src/completion/pass.fish-completion
index 8637874..d3fbcd9 100644
--- a/src/completion/pass.fish-completion
+++ b/src/completion/pass.fish-completion
@@ -7,9 +7,15 @@ set PROG 'pass'
function __fish_pass_get_prefix
set -l prefix "$PASSWORD_STORE_DIR"
- if [ -z "$prefix" ]
+ if [ -z "$prefix" ] || [ ! -d "$prefix" ]
set prefix "$HOME/.password-store"
end
+ if [ ! -d "$prefix" ]
+ set prefix "$XDG_DATA_HOME/password-store"
+ end
+ if [ ! -d "$prefix" ]
+ set prefix "$HOME/.local/share/password-store"
+ end
echo "$prefix"
end
diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
index 27ce15a..f93d5bb 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -123,7 +123,10 @@ _pass_cmd_show () {
_pass_complete_entries_helper () {
local IFS=$'\n'
local prefix
- zstyle -s ":completion:${curcontext}:" prefix prefix || prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
+ zstyle -s ":completion:${curcontext}:" prefix prefix || {
+ prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
+ if [ ! -d "$prefix" ] && prefix="${XDG_DATA_HOME:-$HOME/.local/share}/password-store"
+ }
_values -C 'passwords' ${$(find -L "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print 2>/dev/null | sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' -e 's#\\#\\\\#' | sort):-""}
}
diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..105a2d1 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -12,6 +12,9 @@ export GPG_TTY="${GPG_TTY:-$(tty 2>/dev/null)}"
which gpg2 &>/dev/null && GPG="gpg2"
[[ -n $GPG_AGENT_INFO || $GPG == "gpg2" ]] && GPG_OPTS+=( "--batch" "--use-agent" )
+if [[ -z $PASSWORD_STORE_DIR ]] && [[ ! -d $HOME/.password-store ]];then
+ PASSWORD_STORE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/password-store"
+fi
PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
EXTENSIONS="${PASSWORD_STORE_EXTENSIONS_DIR:-$PREFIX/.extensions}"
X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
--
2.26.2
More information about the Password-Store
mailing list