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

Add support for sub directories for filtering, add autocomplete action #25

Open
wants to merge 1 commit 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
114 changes: 108 additions & 6 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@
<false/>
</dict>
</array>
<key>E51C31A6-DF82-4087-BE7B-A7A588C49BCA</key>
<array>
<dict>
<key>destinationuid</key>
<string>FD54DB02-354D-478D-A10D-AB7D69256AD9</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Przemek Kamiński</string>
Expand All @@ -76,6 +89,8 @@
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand Down Expand Up @@ -114,7 +129,7 @@
<key>uid</key>
<string>7DD3BDE5-A157-42E5-9376-F681FB50A4EE</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -147,14 +162,14 @@
<key>clipboardtext</key>
<string>{query}</string>
<key>transient</key>
<true/>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>C7B97C94-3D0B-471E-96EE-A441A1FAB184</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -207,6 +222,8 @@
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand Down Expand Up @@ -245,7 +262,7 @@
<key>uid</key>
<string>967E625E-D870-4298-9A7A-97C043740D99</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -270,10 +287,81 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>/usr/local/bin/bash pass-autocomplete.sh "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>FD54DB02-354D-478D-A10D-AB7D69256AD9</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>passa</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>python pass-filter.py "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string>Autotype</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>E51C31A6-DF82-4087-BE7B-A7A588C49BCA</string>
<key>version</key>
<integer>3</integer>
</dict>
</array>
<key>readme</key>
<string>A workflow to integrate with Pass - the standard Unix password manager.
See the README file at https://github.com/CGenie/alfred-pass for more info.</string>
<string></string>
<key>uidata</key>
<dict>
<key>06C9C4A9-38CE-441A-8D06-E2F2D8B39B60</key>
Expand Down Expand Up @@ -325,6 +413,20 @@ See the README file at https://github.com/CGenie/alfred-pass for more info.</str
<key>ypos</key>
<integer>60</integer>
</dict>
<key>E51C31A6-DF82-4087-BE7B-A7A588C49BCA</key>
<dict>
<key>xpos</key>
<integer>295</integer>
<key>ypos</key>
<integer>430</integer>
</dict>
<key>FD54DB02-354D-478D-A10D-AB7D69256AD9</key>
<dict>
<key>xpos</key>
<integer>505</integer>
<key>ypos</key>
<integer>430</integer>
</dict>
</dict>
<key>version</key>
<string>0.3.4</string>
Expand Down
52 changes: 52 additions & 0 deletions pass-autocomplete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -e


QUERY=$1
PATH=/usr/local/bin:$PATH

AUTOTYPE_field='autotype'
default_autotype="user :tab pass"
URL_field='url'
USERNAME_field='user'

allData="$(pass show $QUERY)"

function doType {
echo "tell application \"System Events\" to keystroke \"$1\"" | osascript
}

function doStroke {
echo "tell application \"System Events\" to key code $1" | osascript
}

declare -A stuff
pass_key_value=$(printf '%s\n' "${allData}" | tail -n+2 | grep ': ')
while read -r LINE; do
_id="${LINE%%: *}"
_val="${LINE#* }"
stuff["${_id}"]=${_val}
done < <(printf '%s\n' "${pass_key_value}")

password="${allData%%$'\n'*}"
stuff["pass"]=${password}

if test "${stuff['autotype']+autotype}"; then
:
else
stuff["autotype"]="${USERNAME_field} :tab pass"
fi

pass_content="$(for key in "${!stuff[@]}"; do printf '%s\n' "${key}: ${stuff[$key]}"; done)"

for word in ${stuff["$AUTOTYPE_field"]}; do
case "$word" in
":tab") doStroke 48;;
":space") doStroke 49;;
":delay") sleep "${delay}";;
":enter") doStroke 36;;
*) doType "${stuff[${word}]}";;
esac
done

38 changes: 8 additions & 30 deletions pass-filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,35 @@
import os
import sys
import string

fuzzysearch = True
try:
from fuzzywuzzy import process
except:
fuzzysearch = False
import glob


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 = []
ret = [f for f in glob.glob(PASS_DIR+ "/**/*.gpg")]
replaced = list(map(lambda x : x.replace('.gpg','').replace(PASS_DIR, ''), ret))

for root, dirnames, filenames in os.walk(PASS_DIR, True, None, True):
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())
#for root, dirnames, 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(replaced, 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()

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

return ret


Expand Down