~gpanders/wk

cce144c2e8388b6b9845f9877c949c7cb3fbc3de — Gregory Anders 17 days ago 582e052 v0.1.1
Update shell completion files

Only awk files with a valid id. This both prevents parsing non-wiki
files (which is wasteful) and attempting to parse any subdirectories
(which causes an error).
2 files changed, 13 insertions(+), 6 deletions(-)

M contrib/completions/bash/wk
M contrib/completions/fish/wk.fish
M contrib/completions/bash/wk => contrib/completions/bash/wk +6 -2
@@ 29,8 29,12 @@ _wk () {
            done < <(printf '%s\n' "$pages" | grep -iF "$cur")
            ;;
        t|tag|tags)
            local tags
            tags=$(awk '/^tags:/ {$1="";print}' "$WIKI_DIR"/* | tr ',' '\n' | awk '{$1=$1}1' | sort -u)
            local tags files
            files=()
            while IFS='' read -r line; do
                files+=("$line")
            done < <(compgen -f "$WIKI_DIR/" | sed -E '/\/[0-9]{14}/!d')
            tags=$(awk '/^tags:/ {$1="";print}' "${files[@]}" | tr ',' '\n' | awk '{$1=$1}1' | sort -u)

            # Prioritize prefix matches but if none exist, fallback to matching
            # any substring

M contrib/completions/fish/wk.fish => contrib/completions/fish/wk.fish +7 -4
@@ 6,14 6,17 @@ function __wiki_dir
    end
end

function __fish_complete_wiki_pages
function __wiki_list_pages
    set -q WIKI_DIR; or set -l WIKI_DIR (__wiki_dir)
    printf '%s\n' (command ls $WIKI_DIR | sed -E -e '/[0-9]{14}/!d' -e 's/\.[^.]*$//')
    command ls -d $WIKI_DIR/* | sed -E '/[0-9]{14}/!d'
end

function __fish_complete_wiki_pages
    printf '%s\n' (__wiki_list_pages | sed -E 's/\.[^.]*$//')
end

function __fish_complete_wiki_tags
    set -q WIKI_DIR; or set -l WIKI_DIR (__wiki_dir)
    awk -- '/^tags:/ {$1=""; print}' $WIKI_DIR/* | tr ',' '\n' | awk '{$1=$1}1' | sort -u
    awk -- '/^tags:/ {$1=""; print}' (__wiki_list_pages) | tr ',' '\n' | awk '{$1=$1}1' | sort -u
end

complete -k -x -c wk -n '__fish_seen_subcommand_from bl backlinks' -a '(__fish_complete_wiki_pages)'