~gpanders/wk

d395caaa1bf0fa38fcaaa8378b081ea213da0363 — Greg Anders 2 months ago 95094c3
Few more minor updates to bash completion
1 files changed, 8 insertions(+), 11 deletions(-)

M completions/bash/zet
M completions/bash/zet => completions/bash/zet +8 -11
@@ 3,10 3,6 @@
_zet () {
    : "${ZETTEL_DIR:=${XDG_DATA_HOME:-$HOME/.local/share}/zet}"

    if [ ! -d "$ZETTEL_DIR" ]; then
        return
    fi

    local cur commands
    cur="${COMP_WORDS[COMP_CWORD]}"
    commands="backlinks show open list search sync new tags help preview"


@@ 16,6 12,10 @@ _zet () {
        return 0
    fi

    if [ ! -d "$ZETTEL_DIR" ]; then
        return
    fi

    local zettels
    zettels=$(compgen -f "$ZETTEL_DIR/" | sed -E -e 's/.*\///g' -e '/^[0-9]{14}/!d' -e 's/\..*$//')



@@ 29,12 29,12 @@ _zet () {
            done < <(printf '%s\n' "$zettels" | grep -iF "$cur")
            ;;
        t|tag|tags)
            # Prioritize prefix matches but if none exist, fallback to matching
            # any substring
            local tags
            tags=$(awk '/^tags:/ {$1=""; print}' "$ZETTEL_DIR"/* | tr ',' '\n' | awk '{$1=$1}1' | sort -u)
            tags=$(awk '/^tags:/ {$1="";print}' "$ZETTEL_DIR"/* | tr ',' '\n' | awk '{$1=$1}1' | sort -u)

            matches=$(printf '%s\n' "$tags" | grep -i "^$cur")
            # Prioritize prefix matches but if none exist, fallback to matching
            # any substring
            matches=$(compgen -W "$tags" -- "$cur")
            if [ -z "$matches" ]; then
                matches=$(printf '%s\n' "$tags" | grep -iF "$cur")
            fi


@@ 43,9 43,6 @@ _zet () {
                COMPREPLY+=("$line")
            done < <(printf '%s\n' "$matches")
            ;;
        l|ls|list|s|search|sync|n|new|h|help)
            return
            ;;
        *)
            return
            ;;