Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Forked from kossnocorp/README
Created June 1, 2010 03:18
Show Gist options
  • Save andoriyu/420523 to your computer and use it in GitHub Desktop.
Save andoriyu/420523 to your computer and use it in GitHub Desktop.
Что бы заставить zsp работать нужно добавить папку с ним в PATH (например так export PATH="/Users/koss/Projects/zsp/bin:$PATH") и сделать его исполняемым. Также надо создать папку ~/.zsp в которой будут лежать файлы проектов (пример ниже ↓).
Еще неплохо бы прописать такую строчку в .zshrc:
source "$HOME/.zsp/loader.zsh"
#compdef zsp
_get_profiles() {
profiles=(`zsp list --no-noise`)
}
local -a _1st_arguments
_1st_arguments=(
'use:use profile'
'list:show list of profiles'
)
local expl
local -a profiles
_arguments \
'(-v --version)'{-v,--version}'[version information]' \
'(-h --help)'{-h,--help}'[help]' \
'*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "gem subcommand" _1st_arguments
return
fi
case "$words[1]" in
use)
_get_profiles
_wanted profiles expl 'all profiles' compadd -a profiles ;;
esac
@ruby = 'ruby-head'
@gemset = 'rails3beta3'
@cd = '~/Projects/sparta/'
#!/usr/bin/env ruby
ZSP_HOME = '~/.zsp'
ZSP_HOME_PATH = File.expand_path('~/.zsp')
# Puts message
def say_it message, error = false
message_color = error ? 31 : 36
to_say = "\033[#{message_color}m>>#{error ? '' : "\033[0m"}"
to_say << ' ' << "B000000M!" if error
to_say << ' ' << message
puts to_say
end
# Wrap profile name to gren color and quotes
def wrap_profile_name profile_name
"\033[32m'#{profile_name}'\033[0m"
end
# Get profiles list
def profiles_list
begin
dir = Dir.new ZSP_HOME_PATH
rescue Errno::ENOENT
say_it "'#{ZSP_HOME}' folder is not exist. You should create it first", true
exit
end
profiles = []
dir.each do |file|
profiles << file unless %w[. .. loader.zsh .DS_Store].include? file
end
profiles
end
if ARGV.size == 0 or ['-h', '--help'].include? ARGV[0] or (ARGV[0] == 'use' and ARGV.size != 2)
puts <<EOF
#####################################################################
# #
# ==== == === #
# = = = = #
# = = === #
# ==== == = — zsh profile manager #
# #
# Usage: #
# #
# zsp [Options] Action #
# #
# Actions: #
# #
# list - show profiles list #
# use profile_name - use zsh profile with name profile_name #
# you also can type 'zsp profile_name' #
# #
# Options: #
# #
# -v|--version - zsp version #
# -h|--help - show this crap #
# #
# by Aleksandr Koss (http://nocorp.me) #
# #
#####################################################################
EOF
elsif ['-v', '--version'].include? ARGV[0]
say_it 0.1.to_s
elsif ARGV[0] == 'list'
profiles_list.each { |profile| say_it profile }
else
profile_name = ARGV[0] == 'use' ? ARGV[1] : ARGV[0]
say_it "Activating profile #{wrap_profile_name profile_name}"
if profiles_list.include? profile_name
begin
load File.expand_path("~/.zsp/#{profile_name}"), false
rescue LoadError
say_it 'Error while load profile', true
exit
end
unless [@ruby, @cd].include? nil
loader = File.open File.expand_path('~/.zsp/loader.zsh'), 'w'
rvm_options = [@ruby]
rvm_options << @gemset unless @gemset.nil?
`rvm --default #{rvm_options.join '@'} > /dev/null`
loader.puts "export ZSP_PROFILE=#{profile_name}"
loader.puts "cd #{File.expand_path(@cd)}"
loader.close
say_it ''
say_it "w000t! Profile #{wrap_profile_name profile_name} is activated!"
say_it 'Now you should reload all terminals. Bye!'
else
say_it 'Your profile sucks! But you can create new...', true
end
else
say_it "Profile '#{profile_name}' does not exist!", true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment