Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • rspencer/awit-zsh-superawesome
1 result
Show changes
Showing
with 0 additions and 1549 deletions
per-directory-history.zsh
\ No newline at end of file
#!/usr/bin/env zsh
#
# This is a implementation of per directory history for zsh, some
# implementations of which exist in bash[1,2]. It also implements
# a per-directory-history-toggle-history function to change from using the
# directory history to using the global history. In both cases the history is
# always saved to both the global history and the directory history, so the
# toggle state will not effect the saved histories. Being able to switch
# between global and directory histories on the fly is a novel feature as far
# as I am aware.
#
#-------------------------------------------------------------------------------
# Configuration
#-------------------------------------------------------------------------------
#
# HISTORY_BASE a global variable that defines the base directory in which the
# directory histories are stored
#
#-------------------------------------------------------------------------------
# History
#-------------------------------------------------------------------------------
#
# The idea/inspiration for a per directory history is from Stewart MacArthur[1]
# and Dieter[2], the implementation idea is from Bart Schaefer on the the zsh
# mailing list[3]. The implementation is by Jim Hester in September 2012.
#
# [1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
# [2]: http://dieter.plaetinck.be/per_directory_bash
# [3]: http://www.zsh.org/mla/users/1997/msg00226.html
#
################################################################################
#
# Copyright (c) 2012 Jim Hester
#
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the
# use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not claim
# that you wrote the original software. If you use this software in a product,
# an acknowledgment in the product documentation would be appreciated but is
# not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source distribution..
#
################################################################################
#-------------------------------------------------------------------------------
# configuration, the base under which the directory histories are stored
#-------------------------------------------------------------------------------
[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
#-------------------------------------------------------------------------------
# toggle global/directory history used for searching - ctrl-G by default
#-------------------------------------------------------------------------------
function per-directory-history-toggle-history() {
if [[ $_per_directory_history_is_global == true ]]; then
_per-directory-history-set-directory-history
print -n "\nusing local history"
else
_per-directory-history-set-global-history
print -n "\nusing global history"
fi
zle .push-line
zle .accept-line
}
autoload per-directory-history-toggle-history
zle -N per-directory-history-toggle-history
bindkey '^G' per-directory-history-toggle-history
#-------------------------------------------------------------------------------
# implementation details
#-------------------------------------------------------------------------------
_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
function _per-directory-history-change-directory() {
_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
mkdir -p ${_per_directory_history_directory:h}
if [[ $_per_directory_history_is_global == false ]]; then
#save to the global history
fc -AI $HISTFILE
#save history to previous file
local prev="$HISTORY_BASE${OLDPWD:A}/history"
mkdir -p ${prev:h}
fc -AI $prev
#discard previous directory's history
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
#read history in new file
if [[ -e $_per_directory_history_directory ]]; then
fc -R $_per_directory_history_directory
fi
fi
}
function _per-directory-history-addhistory() {
print -Sr -- ${1%%$'\n'}
fc -p $_per_directory_history_directory
}
function _per-directory-history-set-directory-history() {
if [[ $_per_directory_history_is_global == true ]]; then
fc -AI $HISTFILE
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
if [[ -e "$_per_directory_history_directory" ]]; then
fc -R "$_per_directory_history_directory"
fi
fi
_per_directory_history_is_global=false
}
function _per-directory-history-set-global-history() {
if [[ $_per_directory_history_is_global == false ]]; then
fc -AI $_per_directory_history_directory
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
if [[ -e "$HISTFILE" ]]; then
fc -R "$HISTFILE"
fi
fi
_per_directory_history_is_global=true
}
#add functions to the exec list for chpwd and zshaddhistory
chpwd_functions=(${chpwd_functions[@]} "_per-directory-history-change-directory")
zshaddhistory_functions=(${zshaddhistory_functions[@]} "_per-directory-history-addhistory")
#start in directory mode
mkdir -p ${_per_directory_history_directory:h}
_per_directory_history_is_global=true
_per-directory-history-set-directory-history
# https://github.com/dbbolton
#
# Below are some useful Perl-related aliases/functions that I use with zsh.
# Aliases ###################################################################
# perlbrew ########
alias pbi='perlbrew install'
alias pbl='perlbrew list'
alias pbo='perlbrew off'
alias pbs='perlbrew switch'
alias pbu='perlbrew use'
# Perl ############
# perldoc`
alias pd='perldoc'
# use perl like awk/sed
alias ple='perl -wlne'
# show the latest stable release of Perl
alias latest-perl='curl -s http://www.perl.org/get.html | perl -wlne '\''if (/perl\-([\d\.]+)\.tar\.gz/) { print $1; exit;}'\'
# Functions #################################################################
# newpl - creates a basic Perl script file and opens it with $EDITOR
newpl () {
# set $EDITOR to 'vim' if it is undefined
[[ -z $EDITOR ]] && EDITOR=vim
# if the file exists, just open it
[[ -e $1 ]] && print "$1 exists; not modifying.\n" && $EDITOR $1
# if it doesn't, make it, and open it
[[ ! -e $1 ]] && print '#!/usr/bin/perl'"\n"'use strict;'"\n"'use warnings;'\
"\n\n" > $1 && $EDITOR $1
}
# pgs - Perl Global Substitution
# find pattern = 1st arg
# replace pattern = 2nd arg
# filename = 3rd arg
pgs() { # [find] [replace] [filename]
perl -i.orig -pe 's/'"$1"'/'"$2"'/g' "$3"
}
# Perl grep, because 'grep -P' is terrible. Lets you work with pipes or files.
prep() { # [pattern] [filename unless STDOUT]
perl -nle 'print if /'"$1"'/;' $2
}
_phing_does_target_list_need_generating () {
[ ! -f .phing_targets ] && return 0;
[ build.xml -nt .phing_targets ] && return 0;
return 1;
}
_phing () {
if [ -f build.xml ]; then
if _phing_does_target_list_need_generating; then
phing -l|grep -v "\[property\]"|grep -v "Buildfile"|sed 1d|grep -v ":$" |grep -v "^\-*$"|awk '{print $1}' > .phing_targets
fi
compadd `cat .phing_targets`
fi
}
compdef _phing phing
#compdef pip pip2 pip-2.7 pip3 pip-3.2 pip-3.3 pip-3.4
#autoload
# pip zsh completion, based on homebrew completion
_pip_all() {
# we cache the list of packages (originally from the macports plugin)
if (( ! $+piplist )); then
zsh-pip-cache-packages
piplist=($(cat $ZSH_PIP_CACHE_FILE))
fi
}
_pip_installed() {
installed_pkgs=(`pip freeze | cut -d '=' -f 1`)
}
local -a _1st_arguments
_1st_arguments=(
'bundle:create pybundles (archives containing multiple packages)'
'freeze:output all currently installed packages (exact versions) to stdout'
'help:show available commands'
'show:show information about installed packages'
'install:install packages'
'search:search PyPI'
'uninstall:uninstall packages'
'unzip:unzip individual packages'
'zip:zip individual packages'
)
local expl
local -a all_pkgs installed_pkgs
_arguments \
'(--version)--version[show version number of program and exit]' \
'(-h --help)'{-h,--help}'[show help]' \
'(-E --environment)'{-E,--environment}'[virtualenv environment to run pip in]' \
'(-s --enable-site-packages)'{-s,--enable-site-packages}'[include site-packages in virtualenv]' \
'(-v --verbose)'{-v,--verbose}'[give more output]' \
'(-q --quiet)'{-q,--quiet}'[give less output]' \
'(--log)--log[log file location]' \
'(--proxy)--proxy[proxy in form user:passwd@proxy.server:port]' \
'(--timeout)--timeout[socket timeout (default 15s)]' \
'*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "pip subcommand" _1st_arguments
return
fi
case "$words[1]" in
search)
_arguments \
'(--index)--index[base URL of Python Package Index]' ;;
freeze)
_arguments \
'(-l --local)'{-l,--local}'[report only virtualenv packages]' ;;
install)
_arguments \
'(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
'(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
'(-r --requirement)'{-r,--requirement}'[Requirements file for packages to install]:File:_files' \
'(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
'(--no-install)--no-install[only download packages]' \
'(--no-download)--no-download[only install downloaded packages]' \
'(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
'(--single-version-externally-managed)--single-version-externally-managed[do not download/install dependencies. requires --record or --root]'\
'(--root)--root[treat this path as a fake chroot, installing into it. implies --single-version-externally-managed]'\
'(--record)--record[file to record all installed files to.]'\
'(-r --requirement)'{-r,--requirement}'[requirements file]: :_files'\
'(-e --editable)'{-e,--editable}'[path of or url to source to link to instead of installing.]: :_files -/'\
'1: :->packages' && return 0
if [[ "$state" == packages ]]; then
_pip_all
_wanted piplist expl 'packages' compadd -a piplist
fi ;;
uninstall)
_pip_installed
_wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
show)
_pip_installed
_wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
esac
# Usage:
# Just add pip to your installed plugins.
# If you would like to change the cheeseshops used for autocomplete set
# ZSH_PIP_INDEXES in your zshrc. If one of your indexes are bogus you won't get
# any kind of error message, pip will just not autocomplete from them. Double
# check!
#
# If you would like to clear your cache, go ahead and do a
# "zsh-pip-clear-cache".
ZSH_PIP_CACHE_FILE=~/.pip/zsh-cache
ZSH_PIP_INDEXES=(https://pypi.python.org/simple/)
zsh-pip-clear-cache() {
rm $ZSH_PIP_CACHE_FILE
unset piplist
}
zsh-pip-clean-packages() {
sed -n '/<a href/ s/.*>\([^<]\{1,\}\).*/\1/p'
}
zsh-pip-cache-packages() {
if [[ ! -d ${ZSH_PIP_CACHE_FILE:h} ]]; then
mkdir -p ${ZSH_PIP_CACHE_FILE:h}
fi
if [[ ! -f $ZSH_PIP_CACHE_FILE ]]; then
echo -n "(...caching package index...)"
tmp_cache=/tmp/zsh_tmp_cache
for index in $ZSH_PIP_INDEXES ; do
# well... I've already got two problems
curl $index 2>/dev/null | \
zsh-pip-clean-packages \
>> $tmp_cache
done
sort $tmp_cache | uniq | tr '\n' ' ' > $ZSH_PIP_CACHE_FILE
rm $tmp_cache
fi
}
# A test function that validates the regex against known forms of the simple
# index. If you modify the regex to make it work for you, you should add a test
# case in here and make sure that your changes don't break things for someone
# else.
zsh-pip-test-clean-packages() {
local expected
local actual
expected="0x10c-asm
1009558_nester"
actual=$(echo -n "<html><head><title>Simple Index</title><meta name=\"api-version\" value=\"2\" /></head><body>
<a href='0x10c-asm'>0x10c-asm</a><br/>
<a href='1009558_nester'>1009558_nester</a><br/>
</body></html>" | zsh-pip-clean-packages)
if [[ $actual != $expected ]] ; then
echo -e "python's simple index is broken:\n$actual\n !=\n$expected"
else
echo "python's simple index is fine"
fi
actual=$(echo -n '<html>
<head>
<title>Simple Package Index</title>
</head>
<body>
<a href="0x10c-asm">0x10c-asm</a><br/>
<a href="1009558_nester">1009558_nester</a><br/>
</body></html>' | zsh-pip-clean-packages)
if [[ $actual != $expected ]] ; then
echo -e "the djangopypi2 index is broken:\n$actual\n !=\n$expected"
else
echo "the djangopypi2 index is fine"
fi
}
#!/bin/zsh
#
# Original idea by DefV (Jan De Poorter)
# Source: https://gist.github.com/pjaspers/368394#comment-1016
#
# Usage:
# - Set `$PROJECT_PATHS` in your ~/.zshrc
# e.g.: PROJECT_PATHS=(~/src ~/work)
# - In ZSH you now can open a project directory with the command: `pj my-project`
# the plugin will locate the `my-project` directory in one of the $PROJECT_PATHS
# Also tab completion is supported.
# - `pjo my-project` will open the directory in $EDITOR
#
function pj() {
cmd="cd"
file=$1
if [[ "open" == "$file" ]] then
shift
file=$*
cmd=(${(s: :)EDITOR})
else
file=$*
fi
for project in $PROJECT_PATHS; do
if [[ -d $project/$file ]] then
$cmd "$project/$file"
unset project # Unset project var
return
fi
done
echo "No such project $1"
}
alias pjo="pj open"
function _pj () {
# might be possible to improve this using glob, without the basename trick
typeset -a projects
projects=($PROJECT_PATHS/*)
projects=$projects:t
_arguments "*:file:($projects)"
}
compdef _pj pj
#compdef pod
#autoload
# setopt XTRACE VERBOSE
# vim: ft=zsh sw=2 ts=2 et
# -----------------------------------------------------------------------------
# FILE: _pod
# DESCRIPTION: Cocoapods (0.33.1) autocomplete plugin for Oh-My-Zsh
# http://cocoapods.org
# Generated with `pod --completion-script
# AUTHOR: Alexandre Joly (alexandre.joly@mekanics.ch)
# GITHUB: https://github.com/mekanics
# TWITTER: @jolyAlexandre
# VERSION: 0.0.5
# -----------------------------------------------------------------------------
local -a _subcommands
local -a _options
case "$words[2]" in
help)
case "$words[3]" in
*) # pod help
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod help options" _options
;;
esac
;;
ipc)
case "$words[3]" in
list)
case "$words[4]" in
*) # pod ipc list
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod ipc list options" _options
;;
esac
;;
podfile)
case "$words[4]" in
*) # pod ipc podfile
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod ipc podfile options" _options
;;
esac
;;
repl)
case "$words[4]" in
*) # pod ipc repl
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod ipc repl options" _options
;;
esac
;;
spec)
case "$words[4]" in
*) # pod ipc spec
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod ipc spec options" _options
;;
esac
;;
update-search-index)
case "$words[4]" in
*) # pod ipc update-search-index
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod ipc update-search-index options" _options
;;
esac
;;
*) # pod ipc
_subcommands=(
"list:Lists the specifications known to CocoaPods."
"podfile:Converts a Podfile to YAML."
"repl:The repl listens to commands on standard input."
"spec:Converts a podspec to JSON."
"update-search-index:Updates the search index."
)
_describe -t commands "pod ipc subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod ipc options" _options
;;
esac
;;
init)
case "$words[3]" in
*) # pod init
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod init options" _options
;;
esac
;;
install)
case "$words[3]" in
*) # pod install
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--no-clean:Leave SCM dirs like \`.git\` and \`.svn\` intact after downloading"
"--no-integrate:Skip integration of the Pods libraries in the Xcode project(s)"
"--no-repo-update:Skip running \`pod repo update\` before install"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod install options" _options
;;
esac
;;
lib)
case "$words[3]" in
create)
case "$words[4]" in
*) # pod lib create
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod lib create options" _options
;;
esac
;;
lint)
case "$words[4]" in
*) # pod lib lint
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--no-clean:Lint leaves the build directory intact for inspection"
"--no-subspecs:Lint skips validation of subspecs"
"--only-errors:Lint validates even if warnings are present"
"--quick:Lint skips checks that would require to download and build the spec"
"--silent:Show nothing"
"--subspec=NAME:Lint validates only the given subspec"
"--verbose:Show more debugging information"
)
_describe -t options "pod lib lint options" _options
;;
esac
;;
*) # pod lib
_subcommands=(
"create:Creates a new Pod"
"lint:Validates a Pod"
)
_describe -t commands "pod lib subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod lib options" _options
;;
esac
;;
list)
case "$words[3]" in
new)
case "$words[4]" in
*) # pod list new
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--update:Run \`pod repo update\` before listing"
"--verbose:Show more debugging information"
)
_describe -t options "pod list new options" _options
;;
esac
;;
*) # pod list
_subcommands=(
"new:Lists pods introduced in the master spec-repo since the last check"
)
_describe -t commands "pod list subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--update:Run \`pod repo update\` before listing"
"--verbose:Show more debugging information"
)
_describe -t options "pod list options" _options
;;
esac
;;
outdated)
case "$words[3]" in
*) # pod outdated
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--no-repo-update:Skip running \`pod repo update\` before install"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod outdated options" _options
;;
esac
;;
plugins)
case "$words[3]" in
create)
case "$words[4]" in
*) # pod plugins create
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod plugins create options" _options
;;
esac
;;
list)
case "$words[4]" in
*) # pod plugins list
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--verbose:Show more debugging information"
)
_describe -t options "pod plugins list options" _options
;;
esac
;;
search)
case "$words[4]" in
*) # pod plugins search
_options=(
"--full:Search by name, author, and description"
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--verbose:Show more debugging information"
)
_describe -t options "pod plugins search options" _options
;;
esac
;;
*) # pod plugins
_subcommands=(
"create:Creates a new plugin"
"list:List all known plugins"
"search:Search for known plugins"
)
_describe -t commands "pod plugins subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod plugins options" _options
;;
esac
;;
push)
case "$words[3]" in
*) # pod push
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod push options" _options
;;
esac
;;
repo)
case "$words[3]" in
add)
case "$words[4]" in
*) # pod repo add
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--shallow:Create a shallow clone (fast clone, but no push capabilities)"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod repo add options" _options
;;
esac
;;
lint)
case "$words[4]" in
*) # pod repo lint
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--only-errors:Lint presents only the errors"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod repo lint options" _options
;;
esac
;;
push)
case "$words[4]" in
*) # pod repo push
_options=(
"--allow-warnings:Allows pushing even if there are warnings"
"--help:Show help banner of specified command"
"--local-only:Does not perform the step of pushing REPO to its remote"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod repo push options" _options
;;
esac
;;
remove)
case "$words[4]" in
*) # pod repo remove
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod repo remove options" _options
;;
esac
;;
update)
case "$words[4]" in
*) # pod repo update
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod repo update options" _options
;;
esac
;;
*) # pod repo
_subcommands=(
"add:Add a spec repo."
"lint:Validates all specs in a repo."
"push:Push new specifications to a spec-repo"
"remove:Remove a spec repo"
"update:Update a spec repo."
)
_describe -t commands "pod repo subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod repo options" _options
;;
esac
;;
search)
case "$words[3]" in
*) # pod search
_options=(
"--full:Search by name, summary, and description"
"--help:Show help banner of specified command"
"--ios:Restricts the search to Pods supported on iOS"
"--no-ansi:Show output without ANSI codes"
"--osx:Restricts the search to Pods supported on OS X"
"--stats:Show additional stats (like GitHub watchers and forks)"
"--verbose:Show more debugging information"
"--web:Searches on cocoapods.org"
)
_describe -t options "pod search options" _options
;;
esac
;;
setup)
case "$words[3]" in
*) # pod setup
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--no-shallow:Clone full history so push will work"
"--push:Use this option to enable push access once granted"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod setup options" _options
;;
esac
;;
spec)
case "$words[3]" in
cat)
case "$words[4]" in
*) # pod spec cat
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--show-all:Pick from all versions of the given podspec"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod spec cat options" _options
;;
esac
;;
create)
case "$words[4]" in
*) # pod spec create
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod spec create options" _options
;;
esac
;;
edit)
case "$words[4]" in
*) # pod spec edit
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--show-all:Pick which spec to edit from all available versions of the given podspec"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod spec edit options" _options
;;
esac
;;
lint)
case "$words[4]" in
*) # pod spec lint
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--no-clean:Lint leaves the build directory intact for inspection"
"--no-subspecs:Lint skips validation of subspecs"
"--only-errors:Lint validates even if warnings are present"
"--quick:Lint skips checks that would require to download and build the spec"
"--silent:Show nothing"
"--subspec=NAME:Lint validates only the given subspec"
"--verbose:Show more debugging information"
)
_describe -t options "pod spec lint options" _options
;;
esac
;;
which)
case "$words[4]" in
*) # pod spec which
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--show-all:Print all versions of the given podspec"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod spec which options" _options
;;
esac
;;
*) # pod spec
_subcommands=(
"cat:Prints a spec file."
"create:Create spec file stub."
"edit:Edit a spec file."
"lint:Validates a spec file."
"which:Prints the path of the given spec."
)
_describe -t commands "pod spec subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod spec options" _options
;;
esac
;;
trunk)
case "$words[3]" in
add-owner)
case "$words[4]" in
*) # pod trunk add-owner
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod trunk add-owner options" _options
;;
esac
;;
me)
case "$words[4]" in
clean-sessions)
case "$words[5]" in
*) # pod trunk me clean-sessions
_options=(
"--all:Removes all your sessions, except for the current one"
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod trunk me clean-sessions options" _options
;;
esac
;;
*) # pod trunk me
_subcommands=(
"clean-sessions:Remove sessions"
)
_describe -t commands "pod trunk me subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod trunk me options" _options
;;
esac
;;
push)
case "$words[4]" in
*) # pod trunk push
_options=(
"--allow-warnings:Allows push even if there are lint warnings"
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod trunk push options" _options
;;
esac
;;
register)
case "$words[4]" in
*) # pod trunk register
_options=(
"--description=DESCRIPTION:An arbitrary description to easily identify your session later on."
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod trunk register options" _options
;;
esac
;;
*) # pod trunk
_subcommands=(
"add-owner:Add an owner to a pod"
"me:Display information about your sessions"
"push:Publish a podspec"
"register:Manage sessions"
)
_describe -t commands "pod trunk subcommands" _subcommands
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod trunk options" _options
;;
esac
;;
try)
case "$words[3]" in
*) # pod try
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod try options" _options
;;
esac
;;
update)
case "$words[3]" in
*) # pod update
_options=(
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--no-clean:Leave SCM dirs like \`.git\` and \`.svn\` intact after downloading"
"--no-integrate:Skip integration of the Pods libraries in the Xcode project(s)"
"--no-repo-update:Skip running \`pod repo update\` before install"
"--silent:Show nothing"
"--verbose:Show more debugging information"
)
_describe -t options "pod update options" _options
;;
esac
;;
*) # pod
_subcommands=(
"help:Show help for the given command."
"ipc:Inter-process communication"
"init:Generate a Podfile for the current directory."
"install:Install project dependencies"
"lib:Develop pods"
"list:List pods"
"outdated:Show outdated project dependencies"
"plugins:Show available CocoaPods plugins"
"push:Temporary alias for the \`pod repo push\` command"
"repo:Manage spec-repositories"
"search:Searches for pods"
"setup:Setup the CocoaPods environment"
"spec:Manage pod specs"
"trunk:Interact with the CocoaPods API (e.g. publishing new specs)"
"try:Try a Pod!"
"update:Update outdated project dependencies"
)
_describe -t commands "pod subcommands" _subcommands
_options=(
"--completion-script:Print the auto-completion script"
"--help:Show help banner of specified command"
"--no-ansi:Show output without ANSI codes"
"--silent:Show nothing"
"--verbose:Show more debugging information"
"--version:Show the version of the tool"
)
_describe -t options "pod options" _options
;;
esac
# Aliases to control Postgres
# Paths noted below are for Postgres installed via Homebrew on OSX
alias startpost='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias stoppost='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
alias restartpost='stoppost && sleep 1 && startpost'
alias reloadpost='pg_ctl reload -D /usr/local/var/postgres -s'
alias statuspost='pg_ctl status -D /usr/local/var/postgres -s'
\ No newline at end of file
# Restart a rack app running under pow
# http://pow.cx/
#
# Adds a kapow command that will restart an app
#
# $ kapow myapp
#
# Supports command completion.
#
# If you are not already using completion you might need to enable it with
#
# autoload -U compinit compinit
#
# Changes:
#
# Defaults to the current application, and will walk up the tree to find
# a config.ru file and restart the corresponding app
#
# Will Detect if a app does not exist in pow and print a (slightly) helpful
# error message
rack_root(){
setopt chaselinks
local orgdir="$PWD"
local basedir="$PWD"
while [[ $basedir != '/' ]]; do
test -e "$basedir/config.ru" && break
builtin cd ".." 2>/dev/null
basedir="$PWD"
done
builtin cd "$orgdir" 2>/dev/null
[[ ${basedir} == "/" ]] && return 1
echo $basedir
}
rack_root_detect(){
basedir=$(rack_root)
echo `basename $basedir | sed -E "s/.(com|net|org)//"`
}
kapow(){
local vhost=$1
[ ! -n "$vhost" ] && vhost=$(rack_root_detect)
if [ ! -h ~/.pow/$vhost ]
then
echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first."
return 1
fi
[ ! -d ~/.pow/${vhost}/tmp ] && mkdir -p ~/.pow/$vhost/tmp
touch ~/.pow/$vhost/tmp/restart.txt;
[ $? -eq 0 ] && echo "pow: restarting $vhost.dev"
}
compctl -W ~/.pow -/ kapow
powit(){
local basedir="$PWD"
local vhost=$1
[ ! -n "$vhost" ] && vhost=$(rack_root_detect)
if [ ! -h ~/.pow/$vhost ]
then
echo "pow: Symlinking your app with pow. ${vhost}"
[ ! -d ~/.pow/${vhost} ] && ln -s "$basedir" ~/.pow/$vhost
return 1
fi
}
powed(){
local basedir="$(rack_root)"
find ~/.pow/ -type l -lname "*$basedir*" -exec basename {}'.dev' \;
}
# Restart pow process
# taken from http://www.matthewratzloff.com/blog/2011/12/23/restarting-pow-when-dns-stops-responding
repow(){
lsof | grep 20560 | awk '{print $2}' | xargs kill -9
launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist
echo "restarted pow"
}
# View the standard out (puts) from any pow app
alias kaput="tail -f ~/Library/Logs/Pow/apps/*"
#compdef powder
#autoload
compadd `powder help | grep powder | cut -d " " -f 4`
#compdef powify
_powify_all_servers() {
all_servers=(`ls $HOME/.pow/ 2>/dev/null`)
}
local -a all_servers
local -a _1st_arguments
_1st_arguments=(
'server:server specific commands'
'utils:manage powify'
'create:creates a pow app from the current directory (to change the name append name as an argument)'
'destroy:destroys the pow app linked to the current directory'
'restart:restarts the pow app linked to the current directory'
'always_restart:reload the pow app after each request'
'always_restart_off:do not reload the pow app after each request'
'rename:rename the current pow app to [NAME] or renmae [OLD] to [NEW]'
'environment:run the this pow app in a different environment (aliased `env`)'
'browse:opens and navigates the default browser to this app'
'logs:tail the application logs'
)
_arguments '*:: :->command'
if (( CURRENT == 1 )); then
_describe -t commands "powify command" _1st_arguments
return
fi
case "$words[1]" in
server)
_values , \
'install[install pow server]' \
'reinstall[reinstall pow server]' \
'update[update pow server]' \
'uninstall[uninstall pow server]' \
'list[list all pow apps]' \
'start[start the pow server]' \
'stop[stop the pow server]' \
'restart[restart the pow server]' \
'host[adds all pow apps to /etc/hosts file]' \
'unhost[removes all pow apps from /etc/hosts file]' \
'status[print the current server status]' \
'config[print the current server configuration]' \
'logs[tails the pow server logs]' ;;
utils)
_values , \
'install[install powify.dev server management tool]' \
'reinstall[reinstall powify.dev server management tool]' \
'uninstall[uninstall powify.dev server management tool]' ;;
destroy|restart|always_restart|always_restart_off|rename|browse|logs)
_powify_all_servers
_wanted all_servers expl 'all pow servers' compadd -a all_servers ;;
esac
# You will probably want to list this plugin as the first in your .zshrc.
# This will look for a custom profile for the local machine and each domain or
# subdomain it belongs to. (e.g. com, example.com and foo.example.com)
parts=(${(s:.:)HOST})
for i in {${#parts}..1}; do
profile=${(j:.:)${parts[$i,${#parts}]}}
file=$ZSH_CUSTOM/profiles/$profile
if [ -f $file ]; then
source $file
fi
done
_homebrew-installed() {
type brew &> /dev/null
}
_pyenv-from-homebrew-installed() {
brew --prefix pyenv &> /dev/null
}
FOUND_PYENV=0
pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv")
if _homebrew-installed && _pyenv-from-homebrew-installed ; then
pyenvdirs=($(brew --prefix pyenv) "${pyenvdirs[@]}")
fi
for pyenvdir in "${pyenvdirs[@]}" ; do
if [ -d $pyenvdir/bin -a $FOUND_PYENV -eq 0 ] ; then
FOUND_PYENV=1
export PYENV_ROOT=$pyenvdir
export PATH=${pyenvdir}/bin:$PATH
eval "$(pyenv init --no-rehash - zsh)"
function pyenv_prompt_info() {
echo "$(pyenv version-name)"
}
fi
done
unset pyenvdir
if [ $FOUND_PYENV -eq 0 ] ; then
function pyenv_prompt_info() { echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" }
fi
#compdef pylint
#
# this is zsh completion function file.
# generated by genzshcomp(ver: 0.5.1)
#
typeset -A opt_args
local context state line
_arguments -s -S \
"--help[show this help message and exit]:" \
"-h[show this help message and exit]:" \
"--version[show program's version number and exit]:" \
"--long-help[more verbose help.]" \
"--rcfile[Specify a configuration file.]::<file>:_files" \
"--errors-only[In error mode, checkers without error messages are disabled and for others, only the ERROR messages are displayed, and no reports are done by default]" \
"-E[In error mode, checkers without error messages are disabled and for others, only the ERROR messages are displayed, and no reports are done by default]" \
"--ignore[Add files or directories to the blacklist. They should be base names, not paths. \[current: CVS\]]::<file>[,<file>...]:_files" \
"--help-msg[Display a help message for the given message id and exit. The value may be a comma separated list of message ids.]::<msg-id>:_files" \
"--generate-rcfile[Generate a sample configuration file according to the current configuration. You can put other options before this one to get them in the generated configuration.]" \
"--enable[Enable the message, report, category or checker with the given id(s). You can either give multiple identifier separated by comma (,) or put this option multiple time.]::<msg ids>:_files" \
"-e[Enable the message, report, category or checker with the given id(s). You can either give multiple identifier separated by comma (,) or put this option multiple time.]::<msg ids>:_files" \
"--disable[Disable the message, report, category or checker with the given id(s). You can either give multiple identifier separated by comma (,) or put this option multiple time (only on the command line, not in the configuration file where it should appear only once).]::<msg ids>:_files" \
"-d[Disable the message, report, category or checker with the given id(s). You can either give multiple identifier separated by comma (,) or put this option multiple time (only on the command line, not in the configuration file where it should appear only once).]::<msg ids>:_files" \
"--output-format[Set the output format. Available formats are text, parseable, colorized, msvs (visual studio) and html \[current: text\]]::<format>:_files" \
"-f[Set the output format. Available formats are text, parseable, colorized, msvs (visual studio) and html \[current: text\]]::<format>:_files" \
"--include-ids[Include message's id in output \[current: no\]]::<y_or_n>:_files" \
"-i[Include message's id in output \[current: no\]]::<y_or_n>:_files" \
"--reports[Tells whether to display a full report or only the messages \[current: yes\]]::<y_or_n>:_files" \
"-r[Tells whether to display a full report or only the messages \[current: yes\]]::<y_or_n>:_files" \
"*::args:_files"
# Aliases
alias pylint-quick='pylint --reports=n --include-ids=y'
compdef _pylint-quick pylint-quick='pylint --reports=n --include-ids=y'
\ No newline at end of file
#compdef python
# Python 2.6
# Python 3.0
local curcontext="$curcontext" state line expl
typeset -A opt_args
local -a args
if _pick_variant python3=Python\ 3 python2 --version; then
args=(
'(-bb)-b[issue warnings about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str]'
'(-b)-bb[issue errors about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str]'
)
else
args=(
'-Q+[division options]:division option:(old warn warnall new)'
'(-tt)-t[issue warnings about inconsistent tab usage]'
'(-t)-tt[issue errors about inconsistent tab usage]'
'-3[warn about Python 3.x incompatibilities]'
)
fi
_arguments -C -s -S "$args[@]" \
"-B[don't write .py\[co\] files on import]" \
'(1 -)-c+[program passed in as string (terminates option list)]:python command:' \
'-d[debug output from parser]' \
'-E[ignore PYTHON* environment variables (such as PYTHONPATH)]' \
'(1 * -)-h[display help information]' \
'-i[inspect interactively after running script]' \
'(1 * -)-m[run library module as a script (terminates option list)]:module:->modules' \
'-O[optimize generated bytecode slightly]' \
'-OO[remove doc-strings in addition to the -O optimizations]' \
"-s[don't add user site directory to sys.path]" \
"-S[don't imply 'import site' on initialization]" \
'-u[unbuffered binary stdout and stderr]' \
'-v[verbose (trace import statements)]' \
'(1 * -)'{-V,--version}'[display version information]' \
'-W+[warning control]:warning filter (action\:message\:category\:module\:lineno):(default always ignore module once error)' \
'-x[skip first line of source, allowing use of non-Unix forms of #!cmd]' \
'(-)1:script file:_files -g "*.py(|c|o)(-.)"' \
'*::script argument: _normal' && return
if [[ "$state" = modules ]]; then
local -a modules
modules=(
${${=${(f)"$(_call_program modules $words[1] -c \
'from\ pydoc\ import\ help\;\ help\(\"modules\"\)')"}[2,-3]}:#\(package\)}
)
_wanted modules expl module compadd -a modules && return
fi
return 1
# Find python file
alias pyfind='find . -name "*.py"'
# Remove python compiled byte-code in either current directory or in a
# list of specified directories
function pyclean() {
ZSH_PYCLEAN_PLACES=${*:-'.'}
find ${ZSH_PYCLEAN_PLACES} -type f -name "*.py[co]" -delete
find ${ZSH_PYCLEAN_PLACES} -type d -name "__pycache__" -delete
}
# Grep among .py files
alias pygrep='grep --include="*.py"'
#compdef rails
#autoload
local -a _1st_arguments
_1st_arguments=(
'generate:Generate new code (short-cut alias: "g")'
'console:Start the Rails console (short-cut alias: "c")'
'server:Start the Rails server (short-cut alias: "s")'
'dbconsole:Start a console for the database specified in config/database.yml (short-cut alias: "db")'
'new:Create a new Rails application. "rails new my_app" creates a new application called MyApp in "./my_app"'
'application:Generate the Rails application code'
'destroy:Undo code generated with "generate"'
'benchmarker:See how fast a piece of code runs'
'profiler:Get profile information from a piece of code'
'plugin:Install a plugin'
'plugin new:Generates skeleton for developing a Rails plugin'
'runner:Run a piece of code in the application environment (short-cut alias: "r")'
)
_rails_generate_arguments() {
generate_arguments=(
assets
controller
decorator
generator
helper
integration_test
mailer
migration
model
observer
performance_test
plugin
resource
scaffold
scaffold_controller
session_migration
stylesheets
task
)
}
_arguments \
'(--version)--version[show version]' \
'(--help)--help[show help]' \
'*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "rails subcommand" _1st_arguments
return
fi
case "$words[1]" in
g|generate)
_rails_generate_arguments
_wanted generate_arguments expl 'all generate' compadd -a generate_arguments ;;
d|destroy)
_rails_generate_arguments
_wanted generate_arguments expl 'all generate' compadd -a generate_arguments ;;
esac
function _rails_command () {
if [ -e "bin/rails" ]; then
bin/rails $@
elif [ -e "script/rails" ]; then
ruby script/rails $@
elif [ -e "script/server" ]; then
ruby script/$@
else
command rails $@
fi
}
function _rake_command () {
if [ -e "bin/rake" ]; then
bin/rake $@
else
command rake $@
fi
}
alias rails='_rails_command'
compdef _rails_command=rails
alias rake='_rake_command'
compdef _rake_command=rake
alias devlog='tail -f log/development.log'
alias prodlog='tail -f log/production.log'
alias testlog='tail -f log/test.log'
alias -g RED='RAILS_ENV=development'
alias -g REP='RAILS_ENV=production'
alias -g RET='RAILS_ENV=test'
# Rails aliases
alias rc='rails console'
alias rd='rails destroy'
alias rdb='rails dbconsole'
alias rg='rails generate'
alias rgm='rails generate migration'
alias rp='rails plugin'
alias ru='rails runner'
alias rs='rails server'
alias rsd='rails server --debugger'
# Rake aliases
alias rdm='rake db:migrate'
alias rdms='rake db:migrate:status'
alias rdr='rake db:rollback'
alias rdc='rake db:create'
alias rds='rake db:seed'
alias rdd='rake db:drop'
alias rdrs='rake db:reset'
alias rdtc='rake db:test:clone'
alias rdtp='rake db:test:prepare'
alias rdmtc='rake db:migrate db:test:clone'
alias rlc='rake log:clear'
alias rn='rake notes'
alias rr='rake routes'
# legacy stuff
alias sstat='thin --stats "/thin/stats" start'
alias sg='ruby script/generate'
alias sd='ruby script/destroy'
alias sp='ruby script/plugin'
alias sr='ruby script/runner'
alias ssp='ruby script/spec'
alias sc='ruby script/console'
alias sd='ruby script/server --debugger'
function remote_console() {
/usr/bin/env ssh $1 "( cd $2 && ruby script/console production )"
}