-
Notifications
You must be signed in to change notification settings - Fork 0
/
sublime-completion.zsh
118 lines (101 loc) · 2.35 KB
/
sublime-completion.zsh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# sp searches for projects
# opens them if one
# lists them if many
sp() {
local OLD_IFS="$IFS"
IFS=$'\n'
# The space between the name of the file here is only
# to be as fuzzy as spotlight (mdfind) cam
files=($(mdfind "kMDItemAlternateNames == '$1*.sublime-project'"))
if [ ${#files} -eq 0 ]; then
echo $fg[red] "No project found";
else
if [ ${#files} -eq 1 ]; then
subl "${files[1]}" --project
else
echo "$fg[red] ${#files} projects found";
for i in "${files[@]}"
do
echo $fg[blue] $(basename $i)
echo $fg[white] $i
done
fi
fi
IFS="$OLD_IFS"
return 0
}
# same as above but opens the parent directory
spo(){
local OLD_IFS="$IFS"
IFS=$'\n'
# The space between the name of the file here is only
# to be as fuzzy as spotlight (mdfind) cam
files=($(mdfind "kMDItemAlternateNames == '$1*.sublime-project'"))
if [ ${#files} -eq 0 ]; then
echo $fg[red] "No project found";
else
if [ ${#files} -eq 1 ]; then
open $(dirname ${files[1]})
else
echo "$fg[red] ${#files} projects found";
for i in "${files[@]}"
do
echo $fg[blue] $(basename $i)
echo $fg[white] $i
done
fi
fi
IFS="$OLD_IFS"
return 0
}
# same as above but cd to the parent directory
spcd(){
local OLD_IFS="$IFS"
IFS=$'\n'
# The space between the name of the file here is only
# to be as fuzzy as spotlight (mdfind) cam
files=($(mdfind "kMDItemAlternateNames == '$1*.sublime-project'"))
if [ ${#files} -eq 0 ]; then
echo $fg[red] "No project found";
else
if [ ${#files} -eq 1 ]; then
cd $(dirname ${files[1]})
else
echo "$fg[red] ${#files} projects found";
for i in "${files[@]}"
do
echo $fg[blue] $(basename $i)
echo $fg[white] $i
done
fi
fi
IFS="$OLD_IFS"
return 0
}
# zsh completion for the `sp` and `spo` command
_subl_complete() {
local OLD_IFS="$IFS"
IFS=$'\n'
# @todo : implement cache
# if _cache_invalid sp_completion; then
files=( $(mdfind "kMDItemAlternateNames == '$words[2]*.sublime-project'") )
# _store_cache sp_completion files
# else
# files=_retrieve_cache
# fi
if [ "${#files}" -eq 0 ]; then
echo "No project found";
else
if [ "${#files}" -eq 1 ]; then
compadd $(basename "$files[1]" .sublime-project)
else
for i in "${files[@]}"
do
compadd $(basename "$i" .sublime-project)
done
fi
fi
IFS="$OLD_IFS"
return 0
}
compdef "_subl_complete $@" sp spo spcd