dotfiles

Alpine Linux dotfiles

git clone git://git.lin.moe/dotfiles.git

 1#!/usr/bin/env python3
 2
 3import os
 4import sys
 5import argparse
 6import subprocess
 7
 8INPUT_CMD='xdotool type "{}"'
 9
10
11
12def main():
13    parser = argparse.ArgumentParser(description='pass input tool for rofi')
14    parser.add_argument('-p', '--password',
15                        action='store_true',
16                        default=False,
17                        help='copy password')
18
19    parser.add_argument('-o', '--otp',
20                        action='store_true',
21                        default=False,
22                        help='copy otp')
23
24    args = parser.parse_args()
25
26    os.system('sway-msg mode default &> /dev/null')
27
28    pw_pathes = subprocess.check_output('find ~/.password-store -type f -name "*.gpg"', shell=True).decode('utf-8')
29    pw_pathes = '\n'.join([i.strip().rstrip('.gpg').split(".password-store/")[-1] for i in pw_pathes.split('\n')])
30    try:
31        pw_path = subprocess.check_output('printf "%s\n" "{}" | rofi -dmenu "$@"'.format(pw_pathes), shell=True).decode('utf-8').strip()
32    except subprocess.CalledProcessError as err:
33        exit(err.returncode)
34
35    if args.otp:
36        try:
37            os.system('pass otp -c "{}"'.format(pw_path))
38        except subprocess.CalledProcessError as err:
39            exit(err.returncode)
40    if args.password:
41        try:
42            os.system('pass show -c "{}"'.format(pw_path))
43        except subprocess.CalledProcessError as err:
44            exit(err.returncode)
45
46if __name__ == '__main__':
47    main()