Created
July 15, 2012 11:43
-
-
Save tijn/3116392 to your computer and use it in GitHub Desktop.
A simple script to quickly set up Sublime Text 2 to use it in Gnome 3
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 | |
# A simple script to quickly set up Sublime Text 2 to use it in Gnome 3. | |
# | |
# It will: | |
# * copy the official Sublime icons into your ~/.local/share/icons/hicolor/[...] | |
# * make a symlink to sublime_text in your ~/bin/ | |
# * create a sublime_text_2.desktop in ~/.local/share/applications/ | |
# | |
# Licence: WTFPL | |
require 'fileutils' | |
USAGE = <<-end_usage | |
Usage: | |
setup_sublime.rb <directory of sublime> | |
Example: | |
setup_sublime.rb ~/software/Sublime\ Text\ 2/ | |
end_usage | |
if ARGV[0].nil? | |
puts USAGE | |
raise ArgumentError, "missing directory argument" | |
end | |
DIR = ARGV[0] | |
unless File.directory?(DIR) | |
puts USAGE | |
raise ArgumentError, "You really need to tell me the directory Sublime Text is in." | |
end | |
SUBLIME_DOT_DESKTOP = <<-end_desktop_file | |
[Desktop Entry] | |
Categories=GNOME;GTK;Utility;TextEditor;Development;Utility; | |
Comment=Sublime Text Editor | |
Exec="sublime_text" %F | |
GenericName=Text Editor | |
Icon=sublime_text | |
MimeType=text/plain;text/x-web-markdown;text/x-chdr;text/x-csrc;text/x-c++hdr;text/x-c++src;text/x-java;text/x-dsrc;text/x-pascal;text/x-perl;text/x-python;application/x-php;application/x-httpd-php3;application/x-httpd-php4;application/x-httpd-php5;application/xml;text/html;text/css;text/x-sql;text/x-diff;x-directory/normal;inode/directory; | |
Name=Sublime Text Editor | |
StartupNotify=false | |
Terminal=false | |
Type=Application | |
end_desktop_file | |
def clean_icon_dir(dir) | |
puts "clean_icon_dir #{dir}" | |
FileUtils.cd(dir) do | |
FileUtils.mkdir 'apps', :verbose => true | |
FileUtils.mv Dir.glob('*.png'), 'apps', :verbose => true | |
end | |
end | |
def install_icons | |
icon = File.join DIR, "Icon" | |
hicolor = File.join DIR, 'hicolor' | |
FileUtils.rm_r hicolor, :noop => true | |
FileUtils.cp_r icon, hicolor, :verbose => true | |
Dir.glob(File.join(hicolor, '*')) do |f| | |
clean_icon_dir(f) if File.directory?(f) | |
end | |
FileUtils.mkdir_p File.join(Dir.home, '.local', 'share', 'icons', 'hicolor') | |
FileUtils.cp_r hicolor, File.join(Dir.home, '.local', 'share', 'icons'), :verbose => true | |
FileUtils.rm_r hicolor, :verbose => true | |
end | |
def make_symlink | |
# make symlink in ~/bin | |
FileUtils.ln_s File.join(DIR, 'sublime_text'), File.join(Dir.home, 'bin'), :noop => true, :verbose => true | |
end | |
def write_desktop_file | |
desktop_file = File.join(Dir.home, '.local', 'share', 'applications', 'sublime_text_2.desktop') | |
File.open(desktop_file, 'w') do |f| | |
f.write(SUBLIME_DOT_DESKTOP) | |
end | |
FileUtils.chmod('+x', desktop_file) | |
end | |
install_icons | |
make_symlink | |
write_desktop_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment