Refactor global rakefiles; now ubuntu friendly

This commit is contained in:
Henrik Lissner 2014-09-20 16:37:45 -04:00
parent 4d952faadf
commit 1af5a91d58
8 changed files with 119 additions and 74 deletions

View file

@ -17,7 +17,7 @@ module Package
def installed?(package = nil) def installed?(package = nil)
return File.exists?(@@brew_bin) if !package return File.exists?(@@brew_bin) if !package
self.run("list | grep -w '#{package}' >& /dev/null") self.run("list | grep -w '^#{package.split(" ")[0]}$' >& /dev/null")
end end
def remove(package) def remove(package)
@ -42,7 +42,7 @@ module Package
end end
def tapped?(repo) def tapped?(repo)
self.run("tap | grep -w '#{repo}' >& /dev/null") self.run("tap | grep -w '^#{repo}$' >& /dev/null")
end end
# Homebrew-specific functions # Homebrew-specific functions
@ -55,12 +55,12 @@ module Package
end end
def cask_installed?(cask) def cask_installed?(cask)
self.run("cask list | grep -w '#{cask}' >& /dev/null") self.run("cask list | grep -w '^#{cask}$' >& /dev/null")
end end
def run(*args) def run(*args)
raise "Homebrew isn't installed!" unless self.installed? raise "Homebrew isn't installed!" unless self.installed?
`#{@@brew_bin} #{args.join(' ')}` system("#{@@brew_bin} #{args.join(' ')}")
end end
end end

View file

@ -1,6 +1,6 @@
desc "My main computer" desc "My main computer"
task :io do task :io do
[ "update", [ "pkg:update",
"pkg:osx", "pkg:osx",
"pkg:zsh", "pkg:zsh",
"pkg:vim", "pkg:vim",
@ -36,18 +36,4 @@ task :io do
"suspicious-package" "suspicious-package"
].each { |app| Package.cask_install app } ].each { |app| Package.cask_install app }
end end
if system("rbenv versions | grep 2.1.2 >/dev/null")
sh_safe "rbenv install 2.1.2"
sh_safe "rbenv global 2.1.2"
sh_safe "~/.rbenv/shims/gem install bundler rspec cucumber jekyll"
end
if system("pyenv versions | grep 3.4.1 >/dev/null")
sh_safe "pyenv install 3.4.1"
sh_safe "pyenv global 3.4.1"
sh_safe "~/.pyenv/shims/pip install nose cython"
end
end end

View file

@ -3,11 +3,11 @@ task :bash => 'bash:update'
namespace :bash do namespace :bash do
task :install do task :install do
if is_mac? echo "Attempting to install bash + completion"
echo "Attempting to install bash + completion" Package.install "bash"
Package.install "bash" Package.install "bash-completion"
Package.install "bash-completion"
if is_mac?
# Write the new bash into shells if it isn't already there # Write the new bash into shells if it isn't already there
bash_bin = "/usr/local/bin/bash" bash_bin = "/usr/local/bin/bash"
if `cat /etc/shells | grep "^#{bash_bin}$"` if `cat /etc/shells | grep "^#{bash_bin}$"`

View file

@ -1,26 +1,43 @@
if is_mac? if is_mac?
ENV['EMACS_D'] = File.expand_path("~/.emacs.d") ENV["EMACS_D"] = File.expand_path("~/.emacs.d")
desc "Ensure emacs is installed and up to date" def emacs_reqs
[
"emacs --HEAD --use-git-head --with-gnutls --cocoa --keep-ctags --srgb",
"aspell --with-lang-en",
"cask",
"rsense",
"node"
]
end
def emacs_installed?
Dir.exists?(ENV["EMACS_D"])
end
desc "Ensure emacs 24.4 is installed & up to date"
task :emacs => "emacs:update" task :emacs => "emacs:update"
namespace :emacs do namespace :emacs do
task :install do task :install do
unless Dir.exists? ENV[:EMACS_D] emacs_reqs.each { |pkg| Package.install pkg }
github 'hlissner/emacs.d', '~/.emacs.d' unless emacs_installed?
echo "Installing emacs dependencies"
Package.install "homebrew/dupes/tidy --HEAD" Package.install "homebrew/dupes/tidy --HEAD"
emacs_reqs.each { |pkg| Package.install pkg }
echo "Setting up Emacs"
github 'hlissner/emacs.d', '~/.emacs.d'
sh_safe "/usr/local/bin/npm install jshint -g" sh_safe "/usr/local/bin/npm install jshint -g"
sh_safe "/usr/local/bin/npm install jsonlint -g" sh_safe "/usr/local/bin/npm install jsonlint -g"
sh_safe "cd ~/.emacs.d && cask" sh_safe "cd '#{ENV["EMACS_D"]}' && cask"
end end
end end
task :update do task :update => "emacs:install" do
echo "Updating emacs.d & packages" echo "Updating emacs.d & packages"
sh_safe "cd ~/.emacs.d && git pull && cask update" sh_safe "cd '#{ENV["EMACS_D"]}' && git pull && cask update"
# Update rsense config # Update rsense config
sh_safe "~/.rbenv/shims/ruby `brew --prefix rsense`/libexec/etc/config.rb > ~/.rsense" sh_safe "~/.rbenv/shims/ruby `brew --prefix rsense`/libexec/etc/config.rb > ~/.rsense"
@ -32,17 +49,8 @@ if is_mac?
Package.remove "homebrew/dupes/tidy" Package.remove "homebrew/dupes/tidy"
emacs_reqs.each { |pkg| Package.remove pkg } emacs_reqs.each { |pkg| Package.remove pkg }
rm_rf "~/.emacs.d" if Dir.exists? ENV['EMACS_D'] rm_rf ENV["EMACS_D"] if Dir.exists? ENV["EMACS_D"]
end end
end end
def emacs_reqs
[
"emacs --with-gnutls --cocoa --keep-ctags --srgb",
"aspell --with-lang-en",
"cask",
"rsense"
]
end
end end

View file

@ -1,3 +1,4 @@
# coding: utf-8
require_relative '../lib/output' require_relative '../lib/output'
desc "Set OSX default configuration" desc "Set OSX default configuration"
@ -10,46 +11,89 @@ task :osx do
end end
echo "Applying OSX settings" echo "Applying OSX settings"
sh_safe 'chflags nohidden "${HOME}/Library"' [
sh_safe 'defaults write NSGlobalDomain KeyRepeat -int 0' 'chflags nohidden "${HOME}/Library"',
# 'defaults write NSGlobalDomain KeyRepeat -int 0',
# Disable press-and-hold for keys in favor of key repeat # Disable press-and-hold for keys in favor of key repeat
sh_safe 'defaults write ApplePressAndHoldEnabled -bool false' 'defaults write ApplePressAndHoldEnabled -bool false',
sh_safe 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3' 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3',
sh_safe 'defaults write NSGlobalDomain AppleFontSmoothing -int 2' 'defaults write NSGlobalDomain AppleFontSmoothing -int 2',
sh_safe 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true' 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true',
sh_safe 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true' 'defaults write com.apple.dock autohide -bool true',
sh_safe 'defaults write com.apple.dock autohide -bool true'
# Disable app quarantine # Expand save panel by default
sh_safe 'defaults write com.apple.LaunchServices LSQuarantine -bool false' 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true',
'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true',
# Disable auto-correct # Disable app quarantine
sh_safe 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false' 'defaults write com.apple.LaunchServices LSQuarantine -bool false',
# Avoid creating .DS_Store files on network volumes # Disable auto-correct
sh_safe 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true' 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false',
# Disable the warning when changing a file extension
sh_safe 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false'
sh_safe 'defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true' # Disable smart quotes
'defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false',
# Disable smart dashes as they're annoying when typing code
'defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false',
# Disable local Time Machine backups # Avoid creating .DS_Store files on network volumes
# sh_safe 'hash_safe tmutil &> /dev/null && sudo tmutil disablelocal' 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true',
# Disable the warning when changing a file extension
'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false',
# Finder: allow text selection in Quick Look 'defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true',
sh_safe 'defaults write com.apple.finder QLEnableTextSelection -bool true'
# When performing a search, search the current folder by default # Disable local Time Machine backups
sh_safe 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"' # sh_safe 'hash_safe tmutil &> /dev/null && sudo tmutil disablelocal'
# Prevent Time Machine from prompting to use new hard drives as backup volume
'defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true',
# Use column view # Finder: allow text selection in Quick Look
sh_safe 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"' 'defaults write com.apple.finder QLEnableTextSelection -bool true',
sh_safe 'defaults write com.apple.finder ShowStatusBar -bool true' # When performing a search, search the current folder by default
sh_safe 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true' 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"',
sh_safe 'killall Finder' ### FINDER ###
sh_safe 'killall Dock' # Use column view
'defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/"', # default location for new finder windows
'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"', # column view by default
'defaults write com.apple.finder ShowPathbar -bool true', # path bar
'defaults write com.apple.finder ShowStatusBar -bool true', # status bar
'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true', # path in window title
# Disable the warning before emptying the Trash
'defaults write com.apple.finder WarnOnEmptyTrash -bool false',
# Disable Dashboard
'defaults write com.apple.dashboard mcx-disabled -bool true',
# Dont show Dashboard as a Space
'defaults write com.apple.dock dashboard-in-overlay -bool true',
# Make Dock icons of hidden applications translucent
'defaults write com.apple.dock showhidden -bool true',
# Disable Spotlight indexing for any volume that gets mounted and has not yet
# been indexed before.
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
'sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"',
### Text edit ###
# Use plain text mode for new TextEdit documents
'defaults write com.apple.TextEdit RichText -int 0',
# Open and save files as UTF-8 in TextEdit
'defaults write com.apple.TextEdit PlainTextEncoding -int 4',
'defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4',
# Disable the sudden motion sensor as its not useful for SSDs
'sudo pmset -a sms 0',
# Load new settings before rebuilding the index
'killall mds > /dev/null 2>&1',
'killall Finder',
'killall Dock'
].each { |cmd| sh_safe cmd }
end end

View file

@ -2,6 +2,9 @@ require_relative "../lib/package"
if is_mac? if is_mac?
desc "Update/setup homebrew"
task :homebrew => "homebrew:update"
namespace :homebrew do namespace :homebrew do
task :setup do task :setup do
unless Package.installed? unless Package.installed?
@ -21,6 +24,7 @@ if is_mac?
"curl", "curl",
"tree", "tree",
"git", "git",
"hub",
"the_silver_searcher", "the_silver_searcher",
"tmux", "tmux",
"gist", "gist",
@ -55,6 +59,9 @@ if is_mac?
elsif is_linux? elsif is_linux?
desc "Update/setup aptitude"
task :aptitude => "aptitude:update"
namespace :aptitude do namespace :aptitude do
task :setup do task :setup do
echo "Updating packages..." echo "Updating packages..."

View file

@ -14,7 +14,8 @@ def pyenv_plugins
end end
def pyenv_version_installed?(version) def pyenv_version_installed?(version)
pyenv_versions.include?(version) versions = pyenv_versions
versions.include?(version) if versions
end end
### ###
@ -35,7 +36,7 @@ namespace :pyenv do
"yyuu/pyenv-virtualenv", "yyuu/pyenv-virtualenv",
"yyuu/pyenv-which-ext" "yyuu/pyenv-which-ext"
].each do |pkg| ].each do |pkg|
ech "Installing #{pkg}", 2 echo "Installing #{pkg}", 2
github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}" github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}"
end end

View file

@ -29,7 +29,6 @@ namespace :zsh do
end end
sh_safe "chsh -s #{zsh_bin}" sh_safe "chsh -s #{zsh_bin}"
sh_safe "exec /bin/zsh -l"
end end
echo "Comment out path_helper to fix PATH in emacs!" if is_mac? echo "Comment out path_helper to fix PATH in emacs!" if is_mac?