-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
54 lines (44 loc) · 1.71 KB
/
Rakefile
File metadata and controls
54 lines (44 loc) · 1.71 KB
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
require 'highline/import'
require 'plist'
CODE_SNIPPET_PATH = File.expand_path('~/Library/Developer/Xcode/UserData/CodeSnippets/')
DST_SNIPPET_PATH = File.expand_path('./snippets/')
desc 'Copies all the snippets into Xcode'
task :default do
copy_local_snippets_to_xcode!
puts "Snippets have been copied to #{CODE_SNIPPET_PATH}"
end
desc 'Show the most recently edited snippet in Xcode'
task :show_recent do
most_recent = get_most_recent_snippet_path
puts `cat #{most_recent}`
puts "==========================="
puts most_recent
end
desc 'Move the most recently edited snippet from Xcode to the repo, then copy back to Xcode'
task :sync_recent do
most_recent = get_most_recent_snippet_path
puts `cat #{most_recent}`
puts "==========================="
puts most_recent
plist = Plist.parse_xml(most_recent)
suggested_name = plist['IDECodeSnippetCompletionPrefix']
base_name = ask("Enter a name for this snippet, without the extension: ") { |q| q.default = suggested_name }
filename = "#{base_name}.codesnippet"
exit(1) unless HighLine.agree("About to move this snippet from XCode to this repo, rename it #{filename}, and copy back to Xcode. Please confirm. y/n")
cmd = "cp #{most_recent} ./snippets/#{filename}"
puts cmd
puts `#{cmd}`
puts "✅ Snippet #{filename} has been copied to local repo"
copy_local_snippets_to_xcode!
puts "✅ Snippets have been copied to #{CODE_SNIPPET_PATH}"
end
def copy_local_snippets_to_xcode!
cmd = "cp #{DST_SNIPPET_PATH}/*.codesnippet #{CODE_SNIPPET_PATH}/."
puts cmd
result = `#{cmd}`
end
def get_most_recent_snippet_path
files_sorted_by_time = Dir.glob("#{CODE_SNIPPET_PATH}/*").sort_by{ |f| File.mtime(f) }.reverse
most_recent = files_sorted_by_time.first
return most_recent
end