Skip to content

Commit

Permalink
Add configuration keyword and support for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Dec 21, 2017
1 parent b00d08a commit dce3a81
Show file tree
Hide file tree
Showing 21 changed files with 1,156 additions and 142 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Usage
- `⌥↩` — Set style as default for `⌥↩`.
- `zot:[<query>]` — Search a specific field.
- `` — Select a field to search against.
- `zotconf [<query>]` — View and edit workflow configuration.
- `An Update is Available` / `Workflow is Up To Date` — Whether a newer version of the workflow is available.
- `⌘↩ Style: …` and `⌥↩ Style: …` — Choose citation styles set for the `⌘↩` and `⌥↩` hotkeys (on search results).
- `Reload Zotero Cache` — Clear the workflow's cache of Zotero data. Useful if the workflow gets out of sync with Zotero.
- `View Documentation` — Open this README in your browser.
- `Report an Issue` — Open the GitHub issue tracker in your browser.


<a name="configuration"></a>
Expand All @@ -50,6 +56,8 @@ The workflow uses your Zotero database and styles, therefore it needs to know wh

If you data are stored somewhere else, you need to set `ZOTERO_DIR` in the [workflow configuration sheet][conf-sheet].

If you have set a "Linked Attachment Base Directory" in Zotero, enter its path for `ATTACHMENTS_DIR` in the [configuration sheet][conf-sheet].


<a name="citation-styles"></a>
### Citation styles ###
Expand All @@ -67,11 +75,12 @@ Theses are all settings available in the [workflow configuration sheet][conf-she
You probably shouldn't edit the `CITE_*` variables yourself, as they need to be set to the internal ID of the style. Set them using the method described [above](#citation-styles).


| Variable | Meaning |
|--------------|-------------------------------|
| `CITE_CMD` | Citation style copied by `⌘↩` |
| `CITE_OPT` | Citation style copied by `⌘⌥` |
| `ZOTERO_DIR` | Path to your Zotero data. |
| Variable | Meaning |
|-------------------|----------------------------------|
| `ATTACHMENTS_DIR` | Path to your Zotero attachments. |
| `CITE_CMD` | Citation style copied by `⌘↩` |
| `CITE_OPT` | Citation style copied by `⌘⌥` |
| `ZOTERO_DIR` | Path to your Zotero data. |


<a name="licence--thanks"></a>
Expand Down
Binary file not shown.
137 changes: 137 additions & 0 deletions bin/icons
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env zsh

set -e

# URL of icon generator
api="http://icons.deanishe.net/icon"
here="$( cd "$( dirname "$0" )"; pwd )"
root="$( cd "$here/../"; pwd )"
# where workflow icons belong
icondir="${root}/src/icons"
# icon config file
iconfile="${icondir}/icons.txt"

prog="$( basename "$0" )"

force=false
verbose=false
vopt=
icons=()

# log <arg>... | Echo arguments to STDERR
log() {
echo "$@" >&2
}

# info <arg>.. | Write args to STDERR if VERBOSE is true
info() {
$verbose && log $(print -P "%F{blue}..%f") "$@"
return 0
}

# success <arg>.. | Write green "ok" and args to STDERR if VERBOSE is true
success() {
$verbose && log $(print -P "%F{green}ok%f") "$@"
return 0
}

# error <arg>.. | Write red "error" and args to STDERR
error() {
log $(print -P '%F{red}error%f') "$@"
}

# fail <arg>.. | Write red "error" and args to STDERR, then exit with status 1
fail() {
error "$@"
exit 1
}

# load | Read configuration file from STDIN
load() {
typeset -g icons
while read line; do

# ignore lines that start with # or are empty
[[ $line =~ "#" ]] || test -z "$line" && continue

read fname font colour name <<< "$line"
icons+=($fname $font $colour $name)

done
}

usage() {
cat <<EOF
$prog [options]
Download icons from server.
Usage:
$prog [-v] [-f]
$prog -h
Options:
-f Force re-download
-h Show this help message and exit
-v Be verbose
EOF
}

while getopts ":fhv" opt; do
case $opt in
f)
force=true;;
h)
usage
exit 0;;
v)
verbose=true
vopt='-v'
;;
\?)
fail "invalid option: -$OPTARG";;
esac
done
shift $((OPTIND-1))


cat "$iconfile" | load

success "loaded config from $iconfile"

total=$(( ${#icons} / 4 ))
fetched=0
j=0
for (( i=1; i<${#icons}; i=i+4 )); do
j=$(( j + 1 ))

fname=$icons[$i]
font=$icons[$i+1]
colour=$icons[$i+2]
name=$icons[$i+3]

# info "j=$j, name=$name, font=$font, fname=$fname"

url="${api}/${font}/${colour}/${name}"
n="${fname}.png"
p="$icondir/$n"
pc="[$j/$total]"

# download source icon
copts=(-L)
$verbose && copts+=(-#) || copts+=(-sS)
$force || ! test -s "$p" && {
curl $copts -o "$p" "$url"
[[ $? -ne 0 ]] && fail "couldn't download $n"
success "downloaded $n"
fetched=$(( fetched + 1 ))
} || {
info "skipped existing $n"
}

done

verbose=true
success "downloaded $fetched icon(s)"

exit 0
Binary file added src/icons/docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/icons/icons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Icons from webfonts via http://icons.deanishe.net
#
# Script ../bin/icons reads this file and downloads the
# specified icons to this directory.
#
# Colours
# blue: 5485F3
# yellow: F8AC30
# red: B00000
# green: 03AE03
#

# filename font name colour icon name

on fontawesome 03AE03 dot-circle-o
off fontawesome B00000 circle-o
reload fontawesome F8AC30 refresh
update-available material F8AC30 cloud-download
update-ok material 03AE03 cloud-done
help material 03AE03 help
docs material 5485F3 help
issue fontawesome F8AC30 bug
Binary file added src/icons/issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/update-available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/update-ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
File renamed without changes
Loading

0 comments on commit dce3a81

Please sign in to comment.