Implement 'quiet' sh(cmd)

This commit is contained in:
Henrik Lissner 2014-06-16 01:24:05 -04:00
parent 36ba9f1877
commit cad2a7ef42
5 changed files with 56 additions and 39 deletions

View file

@ -1,10 +1,13 @@
require_relative "lib/output"
require_relative "lib/homebrew"
require_relative "lib/sh"
desc "Ensure homebrew is installed and up to date"
task :homebrew => 'homebrew:update'
verbose(false)
namespace :homebrew do
task :install do
@ -32,13 +35,11 @@ namespace :homebrew do
%w{
dropbox
firefox
appcleaner
vagrant
virtualbox
growlnotify
iterm2
launchbar
java
}.each { |app| Homebrew.install_cask app }

View file

@ -1,3 +1,5 @@
require_relative 'sh'
include Rake::DSL
module Homebrew
@ -5,36 +7,36 @@ module Homebrew
def self.bootstrap
unless self.is_installed?
sh 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"'
sh 'exec $SHELL -l'
sh_safe 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"'
sh_safe 'exec $SHELL -l'
end
end
def self.destroy
if self.is_installed?
sh 'rm -rf /usr/local/Cellar /usr/local/.git ~/Library/Caches/Homebrew'
sh 'brew prune'
sh_safe 'rm -rf /usr/local/Cellar /usr/local/.git ~/Library/Caches/Homebrew'
sh_safe 'brew prune'
['Library/Homebrew', 'Library/Aliases', 'Library/Formula', 'Library/Contributions'].each do |dir|
sh "rm -r #{dir}"
sh_safe "rm -r #{dir}"
end
end
end
def self.install(keg, options=nil)
sh "#{BIN} install #{keg} #{options}" unless self.is_keg_installed?(keg)
sh_safe "#{BIN} install #{keg} #{options}" unless self.is_keg_installed?(keg)
end
def self.install_cask(cask, options=nil)
sh "#{BIN} cask install #{cask} #{options}" unless self.is_cask_installed?(cask)
sh_safe "#{BIN} cask install #{cask} #{options}" unless self.is_cask_installed?(cask)
end
def self.tap(tap)
sh "#{BIN} tap #{tap}" unless self.is_tapped? tap
sh_safe "#{BIN} tap #{tap}" unless self.is_tapped? tap
end
def self.remove(keg)
sh "#{BIN} remove #{keg}"
sh_safe "#{BIN} remove #{keg}"
end
def self.has_keg?(keg)
@ -63,9 +65,9 @@ module Homebrew
def self.update(*args)
if args.length > 0
sh "#{BIN} upgrade #{args.join(' ')}"
sh_safe "#{BIN} upgrade #{args.join(' ')}"
else
sh "#{BIN} update && #{BIN} upgrade"
sh_safe "#{BIN} update && #{BIN} upgrade"
end
end
end

14
rake/lib/sh.rb Normal file
View file

@ -0,0 +1,14 @@
require_relative 'output'
# A 'safe' sh function that won't stop rake in its tracks
# when it encounters a problem. I'll leave it up to the
# programmer to expect problems and terminate when necessary.
def sh_safe(cmd)
begin
return sh(cmd)
rescue
echoerr $!
return false
end
end

View file

@ -8,46 +8,46 @@ task :osx do
end
echo "Applying OSX settings"
sh 'chflags nohidden "${HOME}/Library"'
sh 'defaults write NSGlobalDomain KeyRepeat -int 0'
sh_safe 'chflags nohidden "${HOME}/Library"'
sh_safe 'defaults write NSGlobalDomain KeyRepeat -int 0'
# Disable press-and-hold for keys in favor of key repeat
sh 'defaults write ApplePressAndHoldEnabled -bool false'
sh_safe 'defaults write ApplePressAndHoldEnabled -bool false'
sh 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3'
sh 'defaults write NSGlobalDomain AppleFontSmoothing -int 2'
sh 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true'
sh 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true'
sh 'defaults write com.apple.dock autohide -bool true'
sh_safe 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3'
sh_safe 'defaults write NSGlobalDomain AppleFontSmoothing -int 2'
sh_safe 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true'
sh_safe 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true'
sh_safe 'defaults write com.apple.dock autohide -bool true'
# Disable app quarantine
sh 'defaults write com.apple.LaunchServices LSQuarantine -bool false'
sh_safe 'defaults write com.apple.LaunchServices LSQuarantine -bool false'
# Disable auto-correct
sh 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false'
sh_safe 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false'
# Avoid creating .DS_Store files on network volumes
sh 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true'
sh_safe 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true'
# Disable the warning when changing a file extension
sh 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false'
sh_safe 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false'
sh 'defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true'
sh_safe 'defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true'
# Disable local Time Machine backups
# sh 'hash tmutil &> /dev/null && sudo tmutil disablelocal'
# sh_safe 'hash_safe tmutil &> /dev/null && sudo tmutil disablelocal'
# Finder: allow text selection in Quick Look
sh 'defaults write com.apple.finder QLEnableTextSelection -bool true'
sh_safe 'defaults write com.apple.finder QLEnableTextSelection -bool true'
# When performing a search, search the current folder by default
sh 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"'
sh_safe 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"'
# Use column view
sh 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"'
sh_safe 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"'
sh 'defaults write com.apple.finder ShowStatusBar -bool true'
sh 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true'
sh_safe 'defaults write com.apple.finder ShowStatusBar -bool true'
sh_safe 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true'
sh 'killall Finder'
sh 'killall Dock'
sh_safe 'killall Finder'
sh_safe 'killall Dock'
end

View file

@ -10,23 +10,23 @@ namespace :zsh do
unless Dir.exists?(File.expand_path("~/.oh-my-zsh"))
echo "Installing oh-my-zsh"
github 'robbyrussell/oh-my-zsh', '~/.oh-my-zsh'
sh '~/.oh-my-zsh/install.sh'
sh_safe '~/.oh-my-zsh/install.sh'
end
unless `printenv SHELL | grep "/bin/zsh"`
echo "Setting shell to zsh"
sh "chsh -s /bin/zsh"
sh "exec /bin/zsh -l"
sh_safe "chsh -s /bin/zsh"
sh_safe "exec /bin/zsh -l"
end
end
task :update => :install do
echo "Updating oh-my-zsh"
sh 'cd ~/.oh-my-zsh && git pull'
sh_safe 'cd ~/.oh-my-zsh && git pull'
end
task :remove do
sh 'rm -rf ~/.oh-my-zsh' if Dir.exists?(File.expand_path("~/.oh-my-zsh"))
sh_safe 'rm -rf ~/.oh-my-zsh' if Dir.exists?(File.expand_path("~/.oh-my-zsh"))
end
end