From dd3d283b39774c002c721b548069a7ff064e967a Mon Sep 17 00:00:00 2001 From: Anton Shemerey Date: Fri, 27 May 2011 17:35:25 +0300 Subject: [PATCH 1/4] add alias for update submodule, use this for update vim pathoge bundles --- aliases/git.aliases.bash | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/aliases/git.aliases.bash b/aliases/git.aliases.bash index 45d7d05f..716734a0 100644 --- a/aliases/git.aliases.bash +++ b/aliases/git.aliases.bash @@ -25,6 +25,7 @@ alias gco='git checkout' alias gexport='git archive --format zip --output' alias gdel='git branch -D' alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master' +alias gsmu="git submodule foreach 'git checkout master && git pull origin master'" alias gll='git log --graph --pretty=oneline --abbrev-commit' case $OSTYPE in @@ -44,13 +45,13 @@ esac function git-help() { echo "Git Custom Aliases Usage" echo - echo " gcl = git clone" + echo " gcl = git clone" echo " g = git" - echo " get = git" + echo " get = git" echo " ga = git add" - echo " gall = git add ." + echo " gall = git add ." echo " gst/gs = git status" - echo " gss = git status -s" + echo " gss = git status -s" echo " gl = git pull" echo " gup = git fetch && git rebase" echo " gp = git push" @@ -58,7 +59,7 @@ function git-help() { echo " gdv = git diff -w \"$@\" | vim -R -" echo " gc = git commit -v" echo " gca = git commit -v -a" - echo " gci = git commit --interactive" + echo " gci = git commit --interactive" echo " gb = git branch" echo " gba = git branch -a" echo " gcount = git shortlog -sn" @@ -68,6 +69,7 @@ function git-help() { echo " gdel = git branch -D" echo " gpo = git push origin" echo " gmu = git fetch origin -v; git fetch upstream -v; git merge upstream/master" + echo " gsmu = git submodule foreach 'git checkout master && git pull origin master'" echo " gll = git log --graph --pretty=oneline --abbrev-commit" echo } From 8e3b86a3d92362806766ace8838022294d582e97 Mon Sep 17 00:00:00 2001 From: Anton Shemerey Date: Tue, 21 Jun 2011 12:11:48 +0300 Subject: [PATCH 2/4] add rails bash completion plugin from https://github.com/jweslley/rails_completion --- plugins/available/rails.plugin.bash | 298 ++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 plugins/available/rails.plugin.bash diff --git a/plugins/available/rails.plugin.bash b/plugins/available/rails.plugin.bash new file mode 100644 index 00000000..f3d322ee --- /dev/null +++ b/plugins/available/rails.plugin.bash @@ -0,0 +1,298 @@ +# Bash completion support for Ruby on Rails. +# +# Copyright (C) 2011 Jonhnny Weslley +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# The latest version of this software can be obtained here: +# +# http://github.com/jweslley/rails_completion +# +# VERSION: 0.1.7 + + +RAILSCOMP_FILE=".rails_generators~" + +__railscomp(){ + local cur="${COMP_WORDS[COMP_CWORD]}" + COMPREPLY=( $( compgen -W "$1" -- "$cur" ) ) +} + +# +# @param $1 Name of variable to return result to +# @param $2 Command list +__railscmd(){ + any_command=$(echo $2 | sed -e 's/[[:space:]]/|/g') + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == @($any_command) ]]; then + eval $1="${COMP_WORDS[i]}" + fi + done +} + +__rails_env(){ + __railscomp "{-e,--environment=}{test,development,production}" +} + +# +# @param $1 Field's name +__rails_types(){ + __railscomp "${1%:*}:{string,text,integer,float,decimal,datetime,timestamp,date,time,binary,boolean,references}" +} + +# Generators ------------------------------------------------------------------- + +__rails_generators_create_cache(){ + echo " + require ::File.expand_path('../config/application', __FILE__) + require 'rails/generators' + + Rails::Generators.configure! + Rails::Generators.lookup! + + hidden_namespaces = Rails::Generators.hidden_namespaces + ['rails:app'] + generators = Rails::Generators.subclasses.select do |generator| + hidden_namespaces.exclude? generator.namespace + end + + shell = Thor::Shell::Basic.new + generators_opts = generators.inject({}) do |hash, generator| + options = (generator.class_options_help(shell).values.flatten + + generator.class_options.values).uniq.map do |opt| + boolean_opt = opt.type == :boolean || opt.banner.empty? + boolean_opt ? opt.switch_name : \"#{opt.switch_name}=\" + end + hash[generator.namespace.gsub(/^rails:/, '')] = options + hash + end + + File.open(File.join(Rails.root, '${RAILSCOMP_FILE}'), 'w') do |f| + YAML.dump(generators_opts, f) + end + " | ruby > /dev/null +} + +__rails_generators_opts(){ + echo " + require 'yaml' + generator = '$1' + generators_opts = YAML.load_file('${RAILSCOMP_FILE}') + opts = generator.empty? ? generators_opts.keys : generators_opts[generator] + opts.each { |opt| puts opt } + " | ruby +} + +__rails_generators(){ + recent=`ls -t "$RAILSCOMP_FILE" Gemfile 2> /dev/null | head -n 1` + if [[ $recent != "$RAILSCOMP_FILE" ]]; then + __rails_generators_create_cache + fi + __railscomp "$(__rails_generators_opts)" +} + +__rails_generator_options(){ + local cur + _get_comp_words_by_ref cur + + if [[ $cur == *:* ]]; then + __rails_types "$cur" + else + __railscomp "$(__rails_generators_opts $1)" + fi +} + +# +# @param $1 file's path +# @param $2 filename suffix +# @param $3 name's suffix +# @param $4 kind. Defaults to class. +__rails_destroy(){ + __railscomp "$(find "$1" -name "*$2.rb" -exec grep ".*${4-class}.*$3.*" {} \; \ + | awk '{ print $2 }' | sed s/$3$//g)" +} + +# end of Generators ------------------------------------------------------------ + + +# Rails commands --------------------------------------------------------------- + +_rails_generate(){ + local cur generator generators + _get_comp_words_by_ref cur + + generators=$(test -f "$RAILSCOMP_FILE" && __rails_generators_opts) + __railscmd generator "$generators" + + if [ -z "$generator" ]; then + case "$cur" in + -*) __railscomp "--help" ;; + *) __rails_generators ;; + esac + return + fi + + __rails_generator_options "$generator" +} + +_rails_destroy(){ + local cur generator generators + _get_comp_words_by_ref cur + + generators=$(test -f "$RAILSCOMP_FILE" && __rails_generators_opts) + __railscmd generator "$generators" + + if [ -z "$generator" ]; then + case "$cur" in + -*) __railscomp "--help" ;; + *) __rails_generators ;; + esac + return + fi + + case "$generator" in + model|scaffold|resource) __rails_destroy "app/models/" ;; + migration|session_migration) __rails_destroy "db/migrate/" ;; + mailer) __rails_destroy "app/mailers/" ;; + observer) __rails_destroy "app/models/" "_observer" "Observer" ;; + controller|scaffold_controller) __rails_destroy "app/controllers/" "_controller" "Controller" ;; + helper) __rails_destroy "app/helpers/" "_helper" "Helper" "module" ;; + integration_test) __rails_destroy "test/integration/" "_test" "Test" ;; + performance_test) __rails_destroy "test/performance/" "_test" "Test" ;; + generator) __rails_destroy "lib/generators/" "_generator" "Generator" ;; + *) COMPREPLY=() ;; + esac +} + +_rails_new(){ + local cur prev + _get_comp_words_by_ref cur prev + + case "$cur" in + -d*|--database=*) + __railscomp "{-d,--database=}{mysql,oracle,postgresql,sqlite3,frontbase,ibm_db}" + return + ;; + esac + + case "$prev" in + --ruby=*|--builder=*|--template=*) _filedir ;; + *) __railscomp "--skip-git --dev --edge --skip-gemfile --skip-active-record + --skip-prototype --skip-test-unit --skip --force --pretend --quiet --help + --version --builder= --template= -d --database= --ruby=" + esac +} + +_rails_server(){ + local cur prev + _get_comp_words_by_ref cur prev + + case "$cur" in + -e*|--environment=*) + __rails_env + return + ;; + esac + + case "$prev" in + --config=*|--pid=*) _filedir ;; + *) __railscomp "--help --pid= -e --environment= --debugger --daemon --config= --binding= --port=" ;; + esac +} + +_rails_console(){ + __railscomp "test development production --sandbox --debugger" +} + +_rails_profiler(){ + local cur prev + _get_comp_words_by_ref cur + + case "$cur" in + -*) __railscomp "--help" ;; + *) __railscomp "flat graph graph_html" + esac +} + +_rails_plugin(){ + local cur prev + _get_comp_words_by_ref cur prev + + case "$prev" in + --root=*) _filedir ;; + *) __railscomp "--help --verbose --root= --source= install remove" ;; + esac +} + +_rails_runner(){ + local cur prev + _get_comp_words_by_ref cur prev + + case "$cur" in + -e*|--environment=*) + __rails_env + return + ;; + esac + + case "$prev" in + runner) __railscomp "--help -e --environment=" ;; + -e*|--environment=*) _filedir ;; + *) COMPREPLY==() ;; + esac +} + +_rails_benchmarker(){ + __railscomp "--help" +} + +# end of Rails commands -------------------------------------------------------- + + +_rails(){ + local cur options command commands + _get_comp_words_by_ref cur + + options="--help --version" + if [[ -f "script/rails" ]]; then + commands="s server c console g generate destroy profiler plugin runner benchmarker db dbconsole" + else + commands="new" + fi + + __railscmd command "$commands" + + if [ -z "$command" ]; then + case "$cur" in + -*) __railscomp "$options" ;; + *) __railscomp "$commands" ;; + esac + return + fi + + case "$command" in + new) _rails_new ;; + s|server) _rails_server ;; + c|console) _rails_console ;; + g|generate) _rails_generate ;; + destroy) _rails_destroy ;; + profiler) _rails_profiler ;; + plugin) _rails_plugin ;; + runner) _rails_runner ;; + benchmarker) _rails_benchmarker ;; + db|dbconsole) COMPREPLY=() ;; + *) COMPREPLY=() ;; + esac +} + +complete -o default -o nospace -F _rails rails From 7ea787569cd0ad8e59faf59280ce57ccbd49b8cf Mon Sep 17 00:00:00 2001 From: Anton Shemerey Date: Tue, 28 Jun 2011 12:21:25 +0300 Subject: [PATCH 3/4] this should be inside completion/. Also, please be sure to merge in the latest commits. I just updated completion to use the available/ => enabled/ style of file loading. --- .../rails.plugin.bash => completion/rails.completion.bash | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/available/rails.plugin.bash => completion/rails.completion.bash (100%) diff --git a/plugins/available/rails.plugin.bash b/completion/rails.completion.bash similarity index 100% rename from plugins/available/rails.plugin.bash rename to completion/rails.completion.bash From 517a31f6efbd5ed8a9a80c66f90c1565191cc051 Mon Sep 17 00:00:00 2001 From: Anton Shemerey Date: Tue, 28 Jun 2011 12:23:30 +0300 Subject: [PATCH 4/4] move to completion/available/rails.completion.bash --- completion/{ => available}/rails.completion.bash | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename completion/{ => available}/rails.completion.bash (100%) diff --git a/completion/rails.completion.bash b/completion/available/rails.completion.bash similarity index 100% rename from completion/rails.completion.bash rename to completion/available/rails.completion.bash