-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuick Open.tmCommand
executable file
·61 lines (56 loc) · 1.82 KB
/
Quick Open.tmCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>line=$TM_CURRENT_LINE
header=$TM_SELECTED_TEXT
# extract header from current line
if [[ -z "$header" ]] && $(egrep -q <<<"$line" '#(import|include)'); then
header=$(sed -n <<<"$line" 's/[^<"]*[<"]\([^">]*\).*/\1/p')
fi
# ask user about header
if [[ -z "$header" ]]; then
res=$(CocoaDialog inputbox --title "Open Header Quickly" --no-newline --informative-text "Header name?" --text "foobar" --button1 "Open" --button2 "Cancel")
[[ $(head -n1 <<<"$res") == "2" ]] && exit
header=$(tail -n1 <<<"$res")
fi
# If Spotlight is available, avail ourselves of it.
# otherwise, use the old 'find'-based method.
#
# The Spotlight method has the advantage of being
# both reasonably fast and catching all the corner
# cases, many of which are missed by the old method.
#
if [[ `which mdfind` != *"not found" ]]; then
# we have Spotlight
files=`ruby18 "$TM_BUNDLE_SUPPORT/SpotlightSearch.rb" "$header"`
else
# old method
arr=("/usr/include"
"${TM_PROJECT_DIRECTORY:-$TM_DIRECTORY}"
)
files=$(for dir in "${arr[@]}";
do find "$dir" -path "*/$header"; done|sort|uniq)
fi
if [[ -n "$files" ]];
then IFS=$'\n'; mate $files &>/dev/null &
else echo "No headers found."
fi
</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>@D</string>
<key>name</key>
<string>Quick Open</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.fortran</string>
<key>uuid</key>
<string>ED1485C9-393F-4B62-A8E8-62B242E4C7CF</string>
</dict>
</plist>