1#!/usr/bin/env python323import os4import sys5import argparse6import subprocess78INPUT_CMD='xdotool type "{}"'9101112def 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')1819 parser.add_argument('-o', '--otp',20 action='store_true',21 default=False,22 help='copy otp')2324 args = parser.parse_args()2526 os.system('sway-msg mode default &> /dev/null')2728 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)3435 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)4546if __name__ == '__main__':47 main()