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