This repository has no description
2.3 kB
67 lines
1{ self, ... }:
2{
3 perSystem =
4 { pkgs, ... }:
5 {
6 packages.passmenu = pkgs.writeShellApplication {
7 name = "passmenu";
8 runtimeInputs = with pkgs; [
9 self.packages.${pkgs.system}.menu
10 pass
11 ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
12 wtype
13 xdotool
14 ];
15 text = ''
16 set -eu
17 shopt -s nullglob globstar
18
19 typeit=0
20 if [[ $# -gt 0 && $1 == "--type" ]]; then
21 typeit=1
22 shift
23 fi
24
25 prefix=''${PASSWORD_STORE_DIR-~/.password-store}
26 password_files=( "$prefix"/**/*.gpg )
27 password_files=( "''${password_files[@]#"$prefix"/}" )
28 password_files=( "''${password_files[@]%.gpg}" )
29
30 password=$(printf '%s\n' "''${password_files[@]}" | menu "$@")
31
32 filename=$(basename "$password")
33 if [[ "$filename" == "otp" ]]; then
34 if [[ $typeit -eq 1 ]]; then
35 # Type OTP code
36 otp_code=$(pass otp "$password" | tr -d '\n')
37 if [[ "$(uname)" == "Darwin" ]]; then
38 # On macOS, use osascript to type the code
39 osascript -e "tell application \"System Events\" to keystroke \"$otp_code\"" 2>/dev/null
40 elif [[ -n "$WAYLAND_DISPLAY" ]]; then
41 echo -n "$otp_code" | wtype -d 10 -s 400 -
42 else
43 echo -n "$otp_code" | xdotool type --clearmodifiers --file -
44 fi
45 else
46 pass otp -c "$password" 2>/dev/null
47 fi
48 else
49 if [[ $typeit -eq 1 ]]; then
50 # Type password
51 pw=$(pass show "$password" | head -n1 | tr -d '\n')
52 if [[ "$(uname)" == "Darwin" ]]; then
53 # On macOS, use osascript to type the password
54 osascript -e "tell application \"System Events\" to keystroke \"$pw\"" 2>/dev/null
55 elif [[ -n "$WAYLAND_DISPLAY" ]]; then
56 echo -n "$pw" | wtype -d 10 -s 400 -
57 else
58 echo -n "$pw" | xdotool type --clearmodifiers --file -
59 fi
60 else
61 pass show -c "$password" 2>/dev/null
62 fi
63 fi
64 '';
65 };
66 };
67}