Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MacOS 12 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>python pass-filter.py "{query}"</string>
<string>python3 pass-filter.py "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down
43 changes: 9 additions & 34 deletions pass-filter.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,44 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import fnmatch
import os
import sys
import string

fuzzysearch = True
try:
from fuzzywuzzy import process
except:
fuzzysearch = False
import re
# import string


QUERY = sys.argv[1]
HOME = os.environ['HOME']
PASS_DIR = os.environ.get('PASSWORD_STORE_DIR',os.path.join(HOME, '.password-store/'))
PASS_DIR = os.environ.get('PASSWORD_STORE_DIR', os.path.join(HOME, '.password-store/'))


# TODO: list_passwords creates cache of passwords for first time
def list_passwords():
ret = []

for root, dirnames, filenames in os.walk(PASS_DIR, True, None, True):
for root, _, filenames in os.walk(PASS_DIR):
for filename in fnmatch.filter(filenames, '*.gpg'):
ret.append(os.path.join(root, filename.replace('.gpg','')).replace(PASS_DIR, ''))
return sorted(ret, key=lambda s: s.lower())


def search_passwords(query):
''' Search passwords using the Fuzzy search method if fuzzywuzzy is available,
or default to the filter-based search otherwise'''
if fuzzysearch:
return search_passwords_fuzzy(query)
return search_passwords_filter(query)


def search_passwords_fuzzy(query):
''' Search passwords using the Fuzzy search method using fuzzywuzzy'''
passwords = list_passwords()
return [entry[0] for entry in process.extract(query, passwords)]


def search_passwords_filter(query):
''' Search passwords using the filter-based search, which doesn't require fuzzywuzzy'''
ret = []

terms = filter(lambda x: x, query.lower().split())
passwords = list_passwords()
regex = ".*{}.*".format(query)

for password in passwords:
for t in terms:
if t not in password.lower():
break
else:
if re.match(regex, password):
ret.append(password)

return ret


def xmlize_items(items, query):
items_a = []

for item in items:
list = string.rsplit(item, "/", 1)
list = item.split("/", 1)
name = list[-1]
path = item if len(list) == 2 else ""

Expand All @@ -88,5 +64,4 @@ def xmlize_items(items, query):


items = search_passwords(QUERY)
print xmlize_items(items, QUERY)

print (xmlize_items(items, QUERY))