---
I don't think I got any comments from the maintainer on this
Is it something you'd be willing to add to pass ?

v2 -> v3 The fish completion had a syntax error

 contrib/dmenu/passmenu              |  2 +-
 man/pass.1                          | 30 +++++++++++++++++------------
 src/completion/pass.bash-completion |  4 ++--
 src/completion/pass.fish-completion | 11 ++---------
 src/completion/pass.zsh-completion  |  3 ++-
 src/password-store.sh               | 19 +++++++++++++++++-
 6 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 83268bc..dcdeadc 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -8,7 +8,7 @@ if [[ $1 == "--type" ]]; then
        shift
 fi
 
-prefix=${PASSWORD_STORE_DIR-~/.password-store}
+prefix="$(pass prefix)"
 password_files=( "$prefix"/**/*.gpg )
 password_files=( "${password_files[@]#"$prefix"/}" )
 password_files=( "${password_files[@]%.gpg}" )
diff --git a/man/pass.1 b/man/pass.1
index a555dcb..964b3f8 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -19,7 +19,7 @@ pass - stores, retrieves, generates, and synchronizes 
passwords securely
 is a very simple password store that keeps passwords inside 
 .BR gpg2 (1)
 encrypted files inside a simple directory tree residing at 
-.IR ~/.password-store .
+.IR $XDG_DATA_HOME/password-store .
 The
 .B pass
 utility provides a series of commands for manipulating the password store,
@@ -174,6 +174,9 @@ is set to \fItrue\fP, then all commits will be signed using 
\fIuser.signingkey\f
 default git signing key. This config key may be turned on using:
 .B `pass git config --bool --add pass.signcommits true`
 .TP
+\fBprefix\fP
+Show the password storage path.
+.TP
 \fBhelp\fP
 Show usage message.
 .TP
@@ -186,7 +189,7 @@ Show version information.
 Initialize password store
 .B zx2c4@laptop ~ $ pass init [email protected] 
 .br
-mkdir: created directory \[u2018]/home/zx2c4/.password-store\[u2019] 
+mkdir: created directory 
\[u2018]/home/zx2c4/.local/share/password-store\[u2019]
 .br
 Password store initialized for [email protected].
 .TP
@@ -294,9 +297,9 @@ Copied Email/jasondonenfeld.com to clipboard. Will clear in 
45 seconds.
 Remove password from store
 .B zx2c4@laptop ~ $ pass remove Business/cheese-whiz-factory 
 .br
-rm: remove regular file 
\[u2018]/home/zx2c4/.password-store/Business/cheese-whiz-factory.gpg\[u2019]? y 
+rm: remove regular file 
\[u2018]/home/zx2c4/.local/share/password-store/Business/cheese-whiz-factory.gpg\[u2019]?
 y
 .br
-removed 
\[u2018]/home/zx2c4/.password-store/Business/cheese-whiz-factory.gpg\[u2019]
+removed 
\[u2018]/home/zx2c4/.local/share/password-store/Business/cheese-whiz-factory.gpg\[u2019]
 
 .SH EXTENDED GIT EXAMPLE
 Here, we initialize new password store, create a git repository, and then 
manipulate and sync passwords. Make note of the arguments to the first call of 
\fBpass git push\fP; consult
@@ -305,13 +308,13 @@ for more information.
 
 .B zx2c4@laptop ~ $ pass init [email protected] 
 .br
-mkdir: created directory \[u2018]/home/zx2c4/.password-store\[u2019] 
+mkdir: created directory 
\[u2018]/home/zx2c4/.local/share/password-store\[u2019]
 .br
 Password store initialized for [email protected]. 
 
 .B zx2c4@laptop ~ $ pass git init 
 .br
-Initialized empty Git repository in /home/zx2c4/.password-store/.git/
+Initialized empty Git repository in 
/home/zx2c4/.local/share/password-store/.git/
 .br
 [master (root-commit) 998c8fd] Added current contents of password store.
 .br
@@ -323,7 +326,7 @@ Initialized empty Git repository in 
/home/zx2c4/.password-store/.git/
 
 .B zx2c4@laptop ~ $ pass generate Amazon/[email protected] 21 
 .br
-mkdir: created directory \[u2018]/home/zx2c4/.password-store/Amazon\[u2019] 
+mkdir: created directory 
\[u2018]/home/zx2c4/.local/share/password-store/Amazon\[u2019]
 .br
 [master 30fdc1e] Added generated password for Amazon/[email protected] to 
store.
 .br
@@ -365,9 +368,9 @@ create mode 100644 Amazon/[email protected]
 
 .B zx2c4@laptop ~ $ pass rm Amazon/[email protected] 
 .br
-rm: remove regular file 
\[u2018]/home/zx2c4/.password-store/Amazon/[email protected]\[u2019]? y 
+rm: remove regular file 
\[u2018]/home/zx2c4/.local/share/password-store/Amazon/[email protected]\[u2019]?
 y
 .br
-removed 
\[u2018]/home/zx2c4/.password-store/Amazon/[email protected]\[u2019] 
+removed 
\[u2018]/home/zx2c4/.local/share/password-store/Amazon/[email protected]\[u2019]
 .br
 rm 'Amazon/[email protected]' 
 .br
@@ -394,16 +397,19 @@ To kexec.com:pass-store
 .SH FILES
 
 .TP
-.B ~/.password-store
+.B $XDG_DATA_HOME/password-store
 The default password storage directory.
 .TP
-.B ~/.password-store/.gpg-id
+.B ~/.password-store
+The legacy password storage directory.
+.TP
+.B $XDG_DATA_HOME/password-store/.gpg-id
 Contains the default gpg key identification used for encryption and decryption.
 Multiple gpg keys may be specified in this file, one per line. If this file
 exists in any sub directories, passwords inside those sub directories are
 encrypted using those keys. This should be set using the \fBinit\fP command.
 .TP
-.B ~/.password-store/.extensions
+.B $XDG_DATA_HOME/password-store/.extensions
 The directory containing extension files.
 
 .SH ENVIRONMENT VARIABLES
diff --git a/src/completion/pass.bash-completion 
b/src/completion/pass.bash-completion
index 95d3e1e..11530d2 100644
--- a/src/completion/pass.bash-completion
+++ b/src/completion/pass.bash-completion
@@ -5,7 +5,7 @@
 # This file is licensed under the GPLv2+. Please see COPYING for more 
information.
 
 _pass_complete_entries () {
-       local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}"
+       local prefix="$(pass prefix)"
        prefix="${prefix%/}/"
        local suffix=".gpg"
        local autoexpand=${1:-0}
@@ -84,7 +84,7 @@ _pass()
 {
        COMPREPLY=()
        local cur="${COMP_WORDS[COMP_CWORD]}"
-       local commands="init ls find grep show insert generate edit rm mv cp 
git help version ${PASSWORD_STORE_EXTENSION_COMMANDS[*]}"
+       local commands="init ls find grep show insert generate edit rm mv cp 
git prefix help version ${PASSWORD_STORE_EXTENSION_COMMANDS[*]}"
        if [[ $COMP_CWORD -gt 1 ]]; then
                local lastarg="${COMP_WORDS[$COMP_CWORD-1]}"
                case "${COMP_WORDS[1]}" in
diff --git a/src/completion/pass.fish-completion 
b/src/completion/pass.fish-completion
index 3e70af1..e5eae89 100644
--- a/src/completion/pass.fish-completion
+++ b/src/completion/pass.fish-completion
@@ -5,14 +5,6 @@
 
 set -l PROG 'pass'
 
-function __fish_pass_get_prefix
-    set -l prefix "$PASSWORD_STORE_DIR"
-    if [ -z "$prefix" ]
-        set prefix "$HOME/.password-store"
-    end
-    echo "$prefix"
-end
-
 function __fish_pass_needs_command
     [ (count (commandline -opc)) -eq 1 ]
 end
@@ -34,7 +26,7 @@ end
 function __fish_pass_print
     set -l ext $argv[1]
     set -l strip $argv[2]
-    set -l prefix (__fish_pass_get_prefix)
+    set -l prefix (pass prefix)
     set -l matches $prefix/**$ext
     printf '%s\n' $matches | sed "s#$prefix/\(.*\)$strip#\1#"
 end
@@ -115,3 +107,4 @@ complete -c $PROG -f -n '__fish_pass_uses_command grep' -a 
'(begin
     set -e cmd[1 2] # Drop "pass grep".
     complete -C"grep $cmd"
 end)'
+complete -c $PROG -f -n '__fish_pass_needs_command' -a prefix -d 'Command: 
show the password storage path'
diff --git a/src/completion/pass.zsh-completion 
b/src/completion/pass.zsh-completion
index 27ce15a..8c51b61 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -103,6 +103,7 @@ _pass () {
                        "cp:Copy the password"
                        "rm:Remove the password"
                        "git:Call git on the password store"
+                       "prefix:Output the password storage path"
                        "version:Output version information"
                        "help:Output help message"
                )
@@ -123,7 +124,7 @@ _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="$(pass 
prefix)"
        _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..81626f9 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -12,7 +12,17 @@ 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" )
 
-PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
+get_prefix(){
+       if [[ ! -z "$PASSWORD_STORE_DIR" ]] && [[ -d "$PASSWORD_STORE_DIR" ]]; 
then
+               echo $PASSWORD_STORE_DIR
+       elif [[ -d "$HOME/.password-store" ]]; then
+               echo "$HOME/.password-store"
+       else
+               echo ${XDG_DATA_HOME:-$HOME/.local/share}/password-store
+       fi
+}
+
+PREFIX="$(get_prefix)"
 EXTENSIONS="${PASSWORD_STORE_EXTENSIONS_DIR:-$PREFIX/.extensions}"
 X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
 CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
@@ -307,6 +317,8 @@ cmd_usage() {
            $PROGRAM git git-command-args...
                If the password store is a git repository, execute a git command
                specified by git-command-args.
+           $PROGRAM prefix
+               Outputs the password-store path.
            $PROGRAM help
                Show this text.
            $PROGRAM version
@@ -693,6 +705,10 @@ cmd_extension() {
        return 0
 }
 
+cmd_prefix() {
+       get_prefix
+}
+
 #
 # END subcommand functions
 #
@@ -714,6 +730,7 @@ case "$1" in
        rename|mv) shift;               cmd_copy_move "move" "$@" ;;
        copy|cp) shift;                 cmd_copy_move "copy" "$@" ;;
        git) shift;                     cmd_git "$@" ;;
+       prefix) shift;                  cmd_prefix "$@" ;;
        *)                              cmd_extension_or_show "$@" ;;
 esac
 exit 0
-- 
2.28.0

Reply via email to