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