diff --git a/search.py b/search.py index d98a12d..05a9844 100644 --- a/search.py +++ b/search.py @@ -6,6 +6,10 @@ import re import stat import sys import traceback +try: + import winshell +except ImportError: + winshell = None from voussoirkit import clipext from voussoirkit import expressionmatch @@ -59,6 +63,29 @@ def search_contents_generic(filepath, content_args): yield from results yield '' +def search_contents_windows_lnk(filepath, content_args): + try: + shortcut = winshell.Shortcut(filepath.absolute_path) + except Exception: + return + + text = [ + f'Target: {shortcut.path}', + f'Start In: {shortcut.working_directory}', + f'Comment: {shortcut.description}', + ] + text = '\n'.join(text) + content_args['text'] = text + + results = search(**content_args) + results = list(results) + if not results: + return + + yield filepath.absolute_path + yield from results + yield '' + def search( *, yes_all=None, @@ -147,7 +174,10 @@ def search( if not filepath.is_file: continue - yield from search_contents_generic(filepath, content_args) + if filepath.extension.lower() == 'lnk' and winshell: + yield from search_contents_windows_lnk(filepath, content_args) + else: + yield from search_contents_generic(filepath, content_args) def argparse_to_dict(args): text = args.text