1 # Usage: dash [keyword:]query
2 dash() { open -a Dash.app dash://"$*" }
6 # No sense doing this for anything except the 2nd position and if we haven't
7 # specified which docset to query against
8 if [[ $CURRENT -ne 2 || "$words[2]" =~ ":" ]]; then
15 # Use defaults to get the array of docsets from preferences
16 # Have to smash it into one big line so that each docset is an element of our docsets array
17 # Only output docsets that are actually enabled
18 local -a enabled_docsets
19 enabled_docsets=("${(@f)$(defaults read com.kapeli.dashdoc docsets \
20 | tr -d '\n' | grep -oE '\{.*?\}' | grep -E 'isEnabled = 1;')}")
22 local docset name keyword
23 # Now get each docset and output each on their own line
24 for docset in "$enabled_docsets[@]"; do
26 # Order of preference as explained to me by @kapeli via email
27 for locator in keyword suggestedKeyword platform; do
28 # Echo the docset, try to find the appropriate keyword
29 # Strip doublequotes and colon from any keyword so that everything has the
30 # same format when output (we'll add the colon in the completion)
31 if [[ "$docset" =~ "$locator = ([^;]*);" ]]; then
32 keyword="${match[1]//[\":]}"
35 if [[ -z "$keyword" ]]; then
39 # if we fall back to platform, we should do some checking per @kapeli
40 if [[ "$locator" == "platform" ]]; then
41 # Since these are the only special cases right now, let's not do the
42 # expensive processing unless we have to
43 if [[ "$keyword" = (python|java|qt|cocos2d) ]]; then
44 if [[ "$docset" =~ "docsetName = ([^;]*);" ]]; then
45 name="${match[1]//[\":]}"
49 "Python 2") keyword="python2" ;;
50 "Python 3") keyword="python3" ;;
54 "Java SE7") keyword="java7" ;;
55 "Java SE6") keyword="java6" ;;
56 "Java SE8") keyword="java8" ;;
60 "Qt 5") keyword="qt5" ;;
61 "Qt 4"|Qt) keyword="qt4" ;;
65 Cocos3D) keyword="cocos3d" ;;
72 # Bail once we have a match
76 # If we have a keyword, add it to the list!
77 if [[ -n "$keyword" ]]; then
82 # special thanks to [arx] on #zsh for getting me sorted on this piece
83 compadd -qS: -- "$docsets[@]"