~gpanders/wk

ref: 5ea9f9606b6e88ce1fe118bed6e2302748ce4ab0 wk/completions/fish/zet.fish -rw-r--r-- 1.8 KiB
5ea9f960 — Greg Anders Update 'show' command aliases in completion files 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function __zettel_dir
    if set -q XDG_DATA_HOME
        echo $XDG_DATA_HOME/zet
    else
        echo $HOME/.local/share/zet
    end
end

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

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

complete -k -x -c zet -n '__fish_seen_subcommand_from bl backlinks' -a '(__fish_complete_zettels)'
complete -k -x -c zet -n '__fish_seen_subcommand_from s sh show' -a '(__fish_complete_zettels)'
complete -k -x -c zet -n '__fish_seen_subcommand_from o open' -a '(__fish_complete_zettels)'
complete -k -x -c zet -n '__fish_seen_subcommand_from p pre prev preview' -a '(__fish_complete_zettels)'
complete -k -x -c zet -n '__fish_seen_subcommand_from t tag tags' -a '(__fish_complete_zettel_tags)'
complete -k -x -c zet -n '__fish_seen_subcommand_from l ls list'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'backlinks' -d 'Update backlinks in all zettels'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'new' -d 'Create a zettel'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'show' -d 'Display a zettel'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'open' -d 'Open a zettel in $EDITOR'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'list' -d 'List zettels'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'search' -d 'Search zettels'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'sync' -d 'Synchronize zettels'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'tag' -d 'List zettels with given tag'
complete -k -x -c zet -n '__fish_use_subcommand' -a 'preview' -d 'Preview a zettel'