Last active
December 19, 2015 01:39
-
-
Save jeremyf/5877345 to your computer and use it in GitHub Desktop.
bashable file for creating and opening a Git repository in Sublime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
# This script assumes your Repositories are in ~/Repositories and your Sublime Projects are in ~/Projects | |
project_name = ARGV[0] | |
if !project_name && ENV['PWD'] | |
project_name = ENV['PWD'].split("/").last | |
end | |
if project_name | |
project_file_name = File.join( | |
ENV['HOME'], | |
'Projects', | |
"#{project_name}.sublime-project" | |
) | |
repository_dirname = File.join( | |
ENV['HOME'], | |
'Repositories', | |
project_name | |
) | |
unless File.exist?(repository_dirname) | |
$stdout.puts %(Missing unable to find #{project_name.inspect}) | |
$stdout.puts %( in #{File.dirname(repository_dirname)}") | |
exit(-1) | |
end | |
unless File.exist?(project_file_name) | |
File.open(project_file_name, 'w+') do |file| | |
file.puts %({) | |
file.puts %( "folders":) | |
file.puts %( [) | |
file.puts %( {) | |
file.puts %( "path": "#{repository_dirname}",) | |
file.puts %( "folder_exclude_patterns": ["doc", "coverage","tmp","jetty", ".bundle", ".yardoc"],) | |
file.puts %( "file_exclude_patterns": [".tag*", "*.gif", "*.jpg", "*.png", "*.log", "*.sqlite3", "*.sql"]) | |
file.puts %( }) | |
file.puts %( ],) | |
file.puts %( "settings":) | |
file.puts %( {) | |
file.puts %( "tab_size": 2) | |
file.puts %( }) | |
file.puts %(}) | |
end | |
sleep(1) | |
end | |
`subl #{project_file_name}` | |
$stdout.puts repository_dirname | |
exit(0) | |
else | |
$stdout.puts "Example `#{File.basename(__FILE__)} project_name`" | |
exit(-1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment