Source

zaw-sources / zaw-webmaterials.zsh

# -*- sh -*-
zmodload zsh/parameter

function zaw-src-webmaterials() {
    candidates=("${(ps:\n:)$(find $ZAW_WEBMATERIALS_DIR | sed -e '1d' -e s#$ZAW_WEBMATERIALS_DIR/##g -e 's#.*c4che.*##g' -e 's#.*pickle.*##g')}")
    actions=("zaw-callback-webmaterials-open" "zaw-callback-webmaterials-append-to-buffer")
    act_descriptions=("open webmaterials document" "append to edit buffer")
}

zaw-register-src -n webmaterials zaw-src-webmaterials

export ZAW_WEBMATERIALS_DIR="$HOME/repos/webmaterials/books"
export ZAW_WEBMATERIALS_OPEN=gnome-open

function zaw-callback-webmaterials-open() {
    local orig_buffer="${BUFFER}"
    BUFFER="${ZAW_WEBMATERIALS_OPEN} \"${ZAW_WEBMATERIALS_DIR}/${(j:; :)@}\""
    zle accept-line
}

function zaw-callback-webmaterials-append-to-buffer() {
    LBUFFER="${BUFFER}\"${ZAW_WEBMATERIALS_DIR}/${(j:; :)@}\""
}