diff --git a/cheat.py b/cheat.py index 230b248..145e16c 100755 --- a/cheat.py +++ b/cheat.py @@ -16,10 +16,10 @@ def main(workflow): parser=Parser(config.getPath()) options=Options(parser, workflow) - tokens=query.strip().split(" ",2) + tokens=query.strip().split(" ",1) tokens=[i.strip() for i in tokens if i!=""] - if len(tokens)!=2: + if len(tokens)<2: sheetName="" if len(tokens)==0 else tokens[0] handler=options.showAvailable if sheetName not in parser.availableSheets() else options.list handler(sheetName) diff --git a/lib/options.py b/lib/options.py index 7807caa..a086928 100644 --- a/lib/options.py +++ b/lib/options.py @@ -9,16 +9,23 @@ def __init__(self, parser, workflow): return None def search(self, sheetName, keyword): + if sheetName not in self._parser.availableSheets(): + Options.warning("Cheat sheet not found.","", self._workflow) + return None if sheetName==None: ret=self._parser.searchAcrossAll(keyword, self._workflow) else: ret=self._parser.searchInSheet(keyword, sheetName, self._workflow) if ret==[]: Options.warning("Not found", "No match found for search {}".format(keyword), self._workflow) + return None for item in ret: self._workflow.add_item( title=item["command"], - subtitle=item["comment"] + subtitle=item["comment"], + copytext=item.get("command"), + valid=True, + arg=item.get("command") ) return None @@ -28,7 +35,9 @@ def list(self, sheetName): self._workflow.add_item( title=item.get("command"), subtitle=item.get("comment"), - valid=False + valid=True, + copytext=item.get("command"), + arg=item.get("command") ) return None diff --git a/lib/parser.py b/lib/parser.py index 95e9cd1..7f698a7 100644 --- a/lib/parser.py +++ b/lib/parser.py @@ -1,5 +1,6 @@ #!/usr/bin/python import os +from workflow import MATCH_ALL, MATCH_ALLCHARS class Parser: def __init__(self,path): @@ -47,4 +48,4 @@ def __parseSheet(self, filename): def filter(self, content, keyword, workflow): def searchIndex(item): return u" ".join([item["comment"],item["command"]]) - return workflow.filter(keyword, content,key=searchIndex, match_on=33, min_score=40) + return workflow.filter(keyword, content,key=searchIndex, match_on=MATCH_ALL ^ MATCH_ALLCHARS, min_score=50)