Skip to content

Commit

Permalink
Merge pull request #19 from shtrom/fuzzywuzzy
Browse files Browse the repository at this point in the history
Use fuzzywuzzy for matching
  • Loading branch information
CGenie committed Feb 22, 2019
2 parents 7dfc1db + fe91f35 commit 86b4948
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
See [Keep a CHANGELOG](http://keepachangelog.com/) for more details.

## [Unreleased]
### Added
- use fuzzywuzzy (if available) to match input strings
### Fixed
- follow symlinks in the `password-filter.py` file [#18]
- set transient Alfred clipboard [#14]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,8 @@ To make this work you need:
`~/.password-store/`.
* `gpg-agent` -- install with `brew`
* `pinentry-mac` -- also install with `brew` (this is GUI frontend for `gpg-agent`).
* (optionally) the `fuzzywuzzy` and (also optionally) `python-Levenshtein`
Python modules (install with `pip install --user fuzzywuzzy python-Levenshtein`)

Next configure `gpg-agent` to use `pinentry-mac` and not the bundled one, editing `~/.gnupg/gpg-agent.conf`:

Expand Down
23 changes: 22 additions & 1 deletion pass-filter.py
Expand Up @@ -5,10 +5,16 @@
import sys
import string

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


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
Expand All @@ -22,6 +28,21 @@ def list_passwords():


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())
Expand Down
2 changes: 2 additions & 0 deletions requirements
Expand Up @@ -3,3 +3,5 @@ pass-otp (optional)
gpg-agent
pinentry-mac (brew: update ~/.gnupg/gpg-agent.conf to this line:
pinentry-program /usr/local/bin/pinentry-mac)
fuzzywuzzy (optional)
python-Levenshtein (optional)

0 comments on commit 86b4948

Please sign in to comment.