Ejemplo n.º 1
0
def show_snippets():
    "Input format: `key1 key2, language1 language2`"
    if not varibles_checked():
        return 0

    # Get all sorted snippets
    if not ['search_all_folders']:
        sorted_note_list = S.get_sorted_files(C["path_to_new_Snippet"])
    else:
        all_files = S.get_sorted_files(Config.FILES_PATH)
        # only search notes with code fences
        sorted_note_list = list(
            filter(lambda x: "```" in x['content'], all_files))

    # Parse input
    mode, keywords, languages = get_parsed_arg()

    if mode == "Recent":
        result = sorted_note_list
    elif mode == "Title_Search":
        result = S.title_search(keywords, sorted_note_list)
    elif mode == "And_Search" or mode == "Exact_Search":
        result = S.and_search(keywords, sorted_note_list)
    elif mode == "Or_Search":
        result = S.or_search(keywords, sorted_note_list)

    if languages:
        result = S.metric_search("language", languages, sorted_note_list)

    # Generate ScriptFilter Output
    if result:
        # show matched results
        num = int(C["result_nums"])
        display_matched_result(query, result[:num])
    else:
        # show none matched info
        Display.show({
            "title": "Nothing found ..",
            "subtitle":
            f'Presh "⌘" to create a new Snippet with title \"{query}\"',
            "arg": '',
            "mods": {
                "cmd": {
                    "arg": f'new|[Snippet>{query}]',
                    "subtitle": "Press <Enter> to confirm creating"
                }
            }
        })

    return
Ejemplo n.º 2
0
def show_notes():
    if not varibles_checked():
        return 0

    # Get all sorted notes
    if C['search_all_folders']:
        sorted_note_list = S.get_sorted_files(Config.FILES_PATH)
    else:
        sorted_note_list = S.get_sorted_files(Config.NOTES_PATH)

    # Parse input
    mode, keywords, tags = get_parsed_arg()
    if mode == "Recent":
        result = sorted_note_list
    elif mode == "Title_Search":
        result = S.title_search(keywords, sorted_note_list)
    elif mode == "And_Search" or mode == "Exact_Search":
        result = S.and_search(keywords, sorted_note_list)
    elif mode == "Or_Search":
        result = S.or_search(keywords, sorted_note_list)

    # Parse tags if needed
    if tags:
        result = S.metric_search("tag", tags, result)

    # Generate ScriptFilter Output
    if result:
        # show matched results
        num = int(C["result_nums"])
        display_matched_result(query, result[:num])
    else:
        # show none matched info
        Display.show({
            "title": "Nothing found ...",
            "subtitle":
            f'Presh "⌘" to create a new Note with title \"{query}\"',
            "arg": '',
            "mods": {
                "cmd": {
                    "arg": f'new|[Note>{query}]',
                    "subtitle": "Press 'Enter' to confirm creating"
                }
            }
        })

    return