345976874550efa09fa7e9cdbe1215ce27d1541b
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/dash/dash.plugin.zsh b/plugins/dash/dash.plugin.zsh
2index 0a627cb7d24615ff520738f35cc4361c62febcc9..f6801a8709ede6b8288b03ebfad8c80c4148638e 100644
3--- a/plugins/dash/dash.plugin.zsh
4+++ b/plugins/dash/dash.plugin.zsh
5@@ -5,76 +5,80 @@ compdef _dash dash
6 _dash() {
7 # No sense doing this for anything except the 2nd position and if we haven't
8 # specified which docset to query against
9- if [[ $CURRENT -eq 2 && ! "$words[2]" =~ ":" ]]; then
10- local -a _all_docsets
11- _all_docsets=()
12- # Use defaults to get the array of docsets from preferences
13- # Have to smash it into one big line so that each docset is an element of
14- # our DOCSETS array
15- DOCSETS=("${(@f)$(defaults read com.kapeli.dashdoc docsets | tr -d '\n' | grep -oE '\{.*?\}')}")
16+ if [[ $CURRENT -ne 2 || "$words[2]" =~ ":" ]]; then
17+ return
18+ fi
19
20- # remove all newlines since defaults prints so pretty like
21- # Now get each docset and output each on their own line
22- for doc in "$DOCSETS[@]"; do
23- # Only output docsets that are actually enabled
24- if [[ "`echo $doc | grep -Eo \"isEnabled = .*?;\" | sed 's/[^01]//g'`" == "0" ]]; then
25- continue
26+ local -aU docsets
27+ docsets=()
28+
29+ # Use defaults to get the array of docsets from preferences
30+ # Have to smash it into one big line so that each docset is an element of our docsets array
31+ # Only output docsets that are actually enabled
32+ local -a enabled_docsets
33+ enabled_docsets=("${(@f)$(defaults read com.kapeli.dashdoc docsets \
34+ | tr -d '\n' | grep -oE '\{.*?\}' | grep -E 'isEnabled = 1;')}")
35+
36+ local docset name keyword
37+ # Now get each docset and output each on their own line
38+ for docset in "$enabled_docsets[@]"; do
39+ keyword=''
40+ # Order of preference as explained to me by @kapeli via email
41+ for locator in keyword suggestedKeyword platform; do
42+ # Echo the docset, try to find the appropriate keyword
43+ # Strip doublequotes and colon from any keyword so that everything has the
44+ # same format when output (we'll add the colon in the completion)
45+ if [[ "$docset" =~ "$locator = ([^;]*);" ]]; then
46+ keyword="${match[1]//[\":]}"
47 fi
48
49- keyword=''
50+ if [[ -z "$keyword" ]]; then
51+ continue
52+ fi
53
54- # Order of preference as explained to me by @kapeli via email
55- KEYWORD_LOCATORS=(keyword suggestedKeyword platform)
56- for locator in "$KEYWORD_LOCATORS[@]"; do
57- # Echo the docset, try to find the appropriate keyword
58- # Strip doublequotes and colon from any keyword so that everything has the
59- # same format when output (we'll add the colon in the completion)
60- keyword=`echo $doc | grep -Eo "$locator = .*?;" | sed -e "s/$locator = \(.*\);/\1/" -e "s/[\":]//g"`
61- if [[ ! -z "$keyword" ]]; then
62- # if we fall back to platform, we should do some checking per @kapeli
63- if [[ "$locator" == "platform" ]]; then
64- # Since these are the only special cases right now, let's not do the
65- # expensive processing unless we have to
66- if [[ "$keyword" = (python|java|qt|cocos2d) ]]; then
67- docsetName=`echo $doc | grep -Eo "docsetName = .*?;" | sed -e "s/docsetName = \(.*\);/\1/" -e "s/[\":]//g"`
68- case "$keyword" in
69- python)
70- case "$docsetName" in
71- "Python 2") keyword="python2" ;;
72- "Python 3") keyword="python3" ;;
73- esac ;;
74- java)
75- case "$docsetName" in
76- "Java SE7") keyword="java7" ;;
77- "Java SE6") keyword="java6" ;;
78- "Java SE8") keyword="java8" ;;
79- esac ;;
80- qt)
81- case "$docsetName" in
82- "Qt 5") keyword="qt5" ;;
83- "Qt 4"|Qt) keyword="qt4" ;;
84- esac ;;
85- cocos2d)
86- case "$docsetName" in
87- Cocos3D) keyword="cocos3d" ;;
88- esac ;;
89- esac
90- fi
91+ # if we fall back to platform, we should do some checking per @kapeli
92+ if [[ "$locator" == "platform" ]]; then
93+ # Since these are the only special cases right now, let's not do the
94+ # expensive processing unless we have to
95+ if [[ "$keyword" = (python|java|qt|cocos2d) ]]; then
96+ if [[ "$docset" =~ "docsetName = ([^;]*);" ]]; then
97+ name="${match[1]//[\":]}"
98+ case "$keyword" in
99+ python)
100+ case "$name" in
101+ "Python 2") keyword="python2" ;;
102+ "Python 3") keyword="python3" ;;
103+ esac ;;
104+ java)