Add simple Prezto installation

This commit is contained in:
Jean Mertz 2012-08-09 20:47:45 +02:00
parent 6b98421fe1
commit 2410bf220b
3 changed files with 54 additions and 187 deletions

100
Rakefile
View File

@ -9,56 +9,18 @@ task :install => [:submodules] do
puts "be overwritten without your consent."
puts "======================================================"
puts
# this has all the linkables from this directory.
linkables = []
linkables += Dir.glob('git/*') if want_to_install?('git')
linkables += Dir.glob('irb/*') if want_to_install?('irb/pry')
linkables += Dir.glob('ruby/*') if want_to_install?('ruby (gems)')
linkables += Dir.glob('ctags/*') if want_to_install?('ctags config (better js/ruby support)')
linkables += Dir.glob('vimify/*') if want_to_install?('vimification of mysql/irb/command line')
linkables += Dir.glob('{vim,vimrc}') if want_to_install?('vim')
linkables += Dir.glob('zsh/zshrc') if want_to_install?('zsh')
Rake::Task['zsh_themes'].invoke
# this has all the runcoms from this directory.
file_operation(Dir.glob('git/*')) if want_to_install?('git')
file_operation(Dir.glob('irb/*')) if want_to_install?('irb/pry')
file_operation(Dir.glob('ruby/*')) if want_to_install?('ruby (gems)')
file_operation(Dir.glob('ctags/*')) if want_to_install?('ctags config (better js/ruby support)')
file_operation(Dir.glob('vimify/*')) if want_to_install?('vimification of mysql/irb/command line')
file_operation(Dir.glob('{vim,vimrc}')) if want_to_install?('vim')
file_operation(Dir.glob('zsh/prezto/runcoms/z*'), :copy)
skip_all = false
overwrite_all = false
backup_all = false
linkables.each do |linkable|
file = linkable.split('/').last
source = "#{ENV["PWD"]}/#{linkable}"
target = "#{ENV["HOME"]}/.#{file}"
puts "--------"
puts "file: #{file}"
puts "source: #{source}"
puts "target: #{target}"
if File.exists?(target) || File.symlink?(target)
unless skip_all || overwrite_all || backup_all
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
case STDIN.gets.chomp
when 'o' then overwrite = true
when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
end
end
FileUtils.rm_rf(target) if overwrite || overwrite_all
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" } if backup || backup_all
end
run %{ ln -s "#{source}" "#{target}" }
end
success_msg("installed")
end
task :zsh_themes do
if File.exist?("#{ENV['HOME']}/.oh-my-zsh/modules/prompt/functions")
run %{ ln -nfs #{ENV["PWD"]}/oh-my-zsh/modules/prompt/functions/* $HOME/.oh-my-zsh/modules/prompt/functions/ } if want_to_install?('zsh themes')
end
end
desc "Init and update submodules."
task :submodules do
sh('git submodule update --init')
@ -79,6 +41,52 @@ def want_to_install? (section)
STDIN.gets.chomp == 'y'
end
def file_operation(files, method = :symlink)
skip_all = false
overwrite_all = false
backup_all = false
files.each do |f|
file = f.split('/').last
source = "#{ENV["PWD"]}/#{f}"
target = "#{ENV["HOME"]}/.#{file}"
puts "--------"
puts "file: #{file}"
puts "source: #{source}"
puts "target: #{target}"
if File.exists?(target) || File.symlink?(target)
unless skip_all || overwrite_all || backup_all
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
case STDIN.gets.chomp
when 'o' then overwrite = true
when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
end
end
FileUtils.rm_rf(target) if overwrite || overwrite_all
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" } if backup || backup_all
end
if method == :symlink
run %{ ln -s "#{source}" "#{target}" }
else
run %{ cp -f "#{source}" "#{target}" }
end
# Temporary solution until we find a way to allow customization
if file == 'zshrc'
run %{ ln -s "~/.yadr/zsh/prezto" "$HOME/.oh-my-zsh" }
File.open(target, 'a') do |f|
f.write('for config_file (~/.yadr/zsh/*.zsh) source $config_file')
end
end
end
end
def success_msg(action)
puts ""
puts " _ _ _ "

View File

@ -1,94 +0,0 @@
#
# A theme based on steeef theme
# * RVM info shown on the right
# * Git branch info on the left
# * Single line prompt
#
# Authors:
# Steve Losh <steve@stevelosh.com>
# Bart Trojanowski <bart@jukie.net>
# Brian Carper <brian@carper.ca>
# steeef <steeef@gmail.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
# Yan Pritzker <yan@pritzker.ws>
function rvm_info_for_prompt {
if [[ -d ~/.rvm/ ]]; then
ruby_version=$(~/.rvm/bin/rvm-prompt)
if [ -n "$ruby_version" ]; then
echo "[$ruby_version]"
fi
fi
}
function prompt_skwp_precmd {
# Check for untracked files or updated submodules since vcs_info doesn't.
if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
fmt_branch="(${__PROMPT_SKWP_COLORS[1]}%b%f%u%c${__PROMPT_SKWP_COLORS[4]}●%f)"
else
fmt_branch="(${__PROMPT_SKWP_COLORS[1]}%b%f%u%c)"
fi
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
vcs_info 'prompt'
}
function prompt_skwp_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
add-zsh-hook precmd prompt_skwp_precmd
# Use extended color pallete if available.
if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then
__PROMPT_SKWP_COLORS=(
"%F{81}" # turquoise
"%F{166}" # orange
"%F{135}" # purple
"%F{161}" # hotpink
"%F{118}" # limegreen
)
else
__PROMPT_SKWP_COLORS=(
"%F{cyan}"
"%F{yellow}"
"%F{magenta}"
"%F{red}"
"%F{green}"
)
fi
# Enable VCS systems you use.
zstyle ':vcs_info:*' enable bzr git hg svn
# check-for-changes can be really slow.
# You should disable it if you work with large repositories.
zstyle ':vcs_info:*:prompt:*' check-for-changes true
# Formats:
# %b - branchname
# %u - unstagedstr (see below)
# %c - stagedstr (see below)
# %a - action (e.g. rebase-i)
# %R - repository path
# %S - path in the repository
local fmt_branch="(${__PROMPT_SKWP_COLORS[1]}%b%f%u%c)"
local fmt_action="(${__PROMPT_SKWP_COLORS[5]}%a%f)"
local fmt_unstaged="${__PROMPT_SKWP_COLORS[2]}●%f"
local fmt_staged="${__PROMPT_SKWP_COLORS[5]}●%f"
zstyle ':vcs_info:*:prompt:*' unstagedstr "${fmt_unstaged}"
zstyle ':vcs_info:*:prompt:*' stagedstr "${fmt_staged}"
zstyle ':vcs_info:*:prompt:*' actionformats "${fmt_branch}${fmt_action}"
zstyle ':vcs_info:*:prompt:*' formats "${fmt_branch}"
zstyle ':vcs_info:*:prompt:*' nvcsformats ""
PROMPT="${__PROMPT_SKWP_COLORS[3]}%n%f@${__PROMPT_SKWP_COLORS[2]}%m%f ${__PROMPT_SKWP_COLORS[5]}%~%f "'${vcs_info_msg_0_}'"$ "
RPROMPT="%F{blue}"'$(rvm_info_for_prompt)'""
}
prompt_skwp_setup "$@"

View File

@ -1,47 +0,0 @@
# --------------------------------
#
# DO NOT EDIT THIS FILE.
# If you want to make changes, do so in the custom/zsh directory.
# Fork and send pull requests to add features and fix bugs. Thanks!
#
# ================================
# Don't change. The following determines where YADR is installed.
yadr=`find -L ~ -type file -maxdepth 2 -name .yadr | head | sed 's:\.yadr\/::'`
# Source oh-my-zsh if it is installed.
if [[ -d $HOME/.oh-my-zsh ]]; then
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
ZSH_THEME="skwp"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(vi-mode rvm ruby bundler zsh-syntax-highlighting history-substring-search)
# source every zsh file in user's custom/zsh/before. This is useful for setting theme and plugins.
if [[ -d $yadr/custom/zsh/before ]]; then
for config_file ($yadr/custom/zsh/before/*) source $config_file
fi
# Prezto (https://github.com/sorin-ionescu/prezto)
source $yadr/zsh/prezto/prezto.zsh
fi
# Configuration
for config_file ($yadr/zsh/*.zsh) source $config_file
# ------------------
# zsh/after
# ==================
# source every zsh file in user's custom/zsh/after.
if [[ -d $yadr/custom/zsh/after ]]; then
for config_file ($yadr/custom/zsh/after/*) source $config_file
fi
# Put secret configuration settings in ~/.secrets
if [[ -a ~/.secrets ]] then
source ~/.secrets
fi