Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
34597687
Commit
34597687
authored
Mar 10, 2022
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf(dash): improve dash completion performance
parent
c4699f8e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
63 deletions
+67
-63
dash.plugin.zsh
plugins/dash/dash.plugin.zsh
+67
-63
No files found.
plugins/dash/dash.plugin.zsh
View file @
34597687
...
@@ -5,76 +5,80 @@ compdef _dash dash
...
@@ -5,76 +5,80 @@ compdef _dash dash
_dash
()
{
_dash
()
{
# No sense doing this for anything except the 2nd position and if we haven't
# No sense doing this for anything except the 2nd position and if we haven't
# specified which docset to query against
# specified which docset to query against
if
[[
$CURRENT
-eq
2
&&
!
"
$words
[2]"
=
~
":"
]]
;
then
if
[[
$CURRENT
-ne
2
||
"
$words
[2]"
=
~
":"
]]
;
then
local
-a
_all_docsets
return
_all_docsets
=()
fi
# Use defaults to get the array of docsets from preferences
# Have to smash it into one big line so that each docset is an element of
# our DOCSETS array
DOCSETS
=(
"
${
(@f)
$(
defaults
read
com.kapeli.dashdoc docsets |
tr
-d
'\n'
|
grep
-oE
'\{.*?\}'
)}
"
)
# remove all newlines since defaults prints so pretty like
local
-aU
docsets
# Now get each docset and output each on their own line
docsets
=()
for
doc
in
"
$DOCSETS
[@]"
;
do
# Use defaults to get the array of docsets from preferences
# Have to smash it into one big line so that each docset is an element of our docsets array
# Only output docsets that are actually enabled
# Only output docsets that are actually enabled
if
[[
"
`
echo
$doc
|
grep
-Eo
\"
isEnabled
=
.
*
?
;
\"
|
sed
's/[^01]//g'
`
"
==
"0"
]]
;
then
local
-a
enabled_docsets
continue
enabled_docsets
=(
"
${
(@f)
$(
defaults
read
com.kapeli.dashdoc docsets
\
fi
|
tr
-d
'\n'
|
grep
-oE
'\{.*?\}'
|
grep
-E
'isEnabled = 1;'
)}
"
)
local
docset name keyword
# Now get each docset and output each on their own line
for
docset
in
"
$enabled_docsets
[@]"
;
do
keyword
=
''
keyword
=
''
# Order of preference as explained to me by @kapeli via email
# Order of preference as explained to me by @kapeli via email
KEYWORD_LOCATORS
=(
keyword suggestedKeyword platform
)
for
locator
in
keyword suggestedKeyword platform
;
do
for
locator
in
"
$KEYWORD_LOCATORS
[@]"
;
do
# Echo the docset, try to find the appropriate keyword
# Echo the docset, try to find the appropriate keyword
# Strip doublequotes and colon from any keyword so that everything has the
# Strip doublequotes and colon from any keyword so that everything has the
# same format when output (we'll add the colon in the completion)
# same format when output (we'll add the colon in the completion)
keyword
=
`
echo
$doc
|
grep
-Eo
"
$locator
= .*?;"
|
sed
-e
"s/
$locator
=
\(
.*
\)
;/
\1
/"
-e
"s/[
\"
:]//g"
`
if
[[
"
$docset
"
=
~
"
$locator
= ([^;]*);"
]]
;
then
if
[[
!
-z
"
$keyword
"
]]
;
then
keyword
=
"
${
match
[1]//[\
":]}"
fi
if [[ -z
"
$keyword
"
]]; then
continue
fi
# if we fall back to platform, we should do some checking per @kapeli
# if we fall back to platform, we should do some checking per @kapeli
if [[
"
$locator
"
==
"platform"
]]; then
if [[
"
$locator
"
==
"platform"
]]; then
# Since these are the only special cases right now, let
's not do the
# Since these are the only special cases right now, let
's not do the
# expensive processing unless we have to
# expensive processing unless we have to
if [[ "$keyword" = (python|java|qt|cocos2d) ]]; then
if [[ "$keyword" = (python|java|qt|cocos2d) ]]; then
docsetName
=
`
echo
$doc
|
grep
-Eo
"docsetName = .*?;"
|
sed
-e
"s/docsetName =
\(
.*
\)
;/
\1
/"
-e
"s/[
\"
:]//g"
`
if [[ "$docset" =~ "docsetName = ([^;]*);" ]]; then
name="${match[1]//[\":]}"
case "$keyword" in
case "$keyword" in
python)
python)
case
"
$docsetN
ame
"
in
case "$n
ame" in
"Python 2") keyword="python2" ;;
"Python 2") keyword="python2" ;;
"Python 3") keyword="python3" ;;
"Python 3") keyword="python3" ;;
esac ;;
esac ;;
java)
java)
case
"
$docsetN
ame
"
in
case "$n
ame" in
"Java SE7") keyword="java7" ;;
"Java SE7") keyword="java7" ;;
"Java SE6") keyword="java6" ;;
"Java SE6") keyword="java6" ;;
"Java SE8") keyword="java8" ;;
"Java SE8") keyword="java8" ;;
esac ;;
esac ;;
qt)
qt)
case
"
$docsetN
ame
"
in
case "$n
ame" in
"Qt 5") keyword="qt5" ;;
"Qt 5") keyword="qt5" ;;
"Qt 4"|Qt) keyword="qt4" ;;
"Qt 4"|Qt) keyword="qt4" ;;
esac ;;
esac ;;
cocos2d)
cocos2d)
case
"
$docsetN
ame
"
in
case "$n
ame" in
Cocos3D) keyword="cocos3d" ;;
Cocos3D) keyword="cocos3d" ;;
esac ;;
esac ;;
esac
esac
fi
fi
fi
fi
fi
# Bail once we have a match
# Bail once we have a match
break
break
fi
done
done
# If we have a keyword, add it to the list!
# If we have a keyword, add it to the list!
if
[[
!
-z
"
$keyword
"
]]
;
then
if [[ -n
"$keyword" ]]; then
_all_
docsets+
=(
$keyword
)
docsets+=($keyword)
fi
fi
done
done
# special thanks to [arx] on #zsh for getting me sorted on this piece
# special thanks to [arx] on #zsh for getting me sorted on this piece
compadd
-qS
:
--
"
$_all_docsets
[@]"
compadd -qS: -- "$docsets[@]"
return
fi
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment