merge upstream

This commit is contained in:
Carlos Cardoso 2013-11-12 22:43:28 -02:00
commit 7062f131f0
43 changed files with 1662 additions and 52 deletions

6
.gitignore vendored
View file

@ -1,9 +1,9 @@
locals.zsh locals.zsh
log/.zsh_history log/.zsh_history
projects.zsh projects.zsh
custom/* -custom/*
!custom/example -!custom/example
!custom/example.zsh -!custom/example.zsh
*.swp *.swp
*.un~ *.un~
!custom/example.zshcache !custom/example.zshcache

View file

@ -1,3 +1,5 @@
!https://s3.amazonaws.com/ohmyzsh/oh-my-zsh-logo.png!
oh-my-zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes, and few things that make you shout... oh-my-zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes, and few things that make you shout...
bq. "OH MY ZSHELL!" bq. "OH MY ZSHELL!"

View file

@ -38,10 +38,20 @@ for plugin ($plugins); do
fi fi
done done
# Figure out the SHORT hostname
if [ -n "$commands[scutil]" ]; then
# OS X
SHORT_HOST=$(scutil --get ComputerName)
else
SHORT_HOST=${HOST/.*/}
fi
# Save the location of the current completion dump file.
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
# Load and run compinit # Load and run compinit
autoload -U compinit autoload -U compinit
compinit -i compinit -i -d "${ZSH_COMPDUMP}"
# Load all of the plugins that were defined in ~/.zshrc # Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do for plugin ($plugins); do

View file

@ -28,6 +28,7 @@ _1st_arguments=(
'missing:check all installed formuale for missing dependencies.' 'missing:check all installed formuale for missing dependencies.'
'outdated:list formulas for which a newer version is available' 'outdated:list formulas for which a newer version is available'
'prune:remove dead links' 'prune:remove dead links'
'reinstall:reinstall a formula'
'remove:remove a formula' 'remove:remove a formula'
'search:search for a formula (/regex/ or string)' 'search:search for a formula (/regex/ or string)'
'server:start a local web app that lets you browse formulae (requires Sinatra)' 'server:start a local web app that lets you browse formulae (requires Sinatra)'
@ -75,7 +76,7 @@ case "$words[1]" in
install|home|homepage|log|info|abv|uses|cat|deps|edit|options|versions) install|home|homepage|log|info|abv|uses|cat|deps|edit|options|versions)
_brew_all_formulae _brew_all_formulae
_wanted formulae expl 'all formulae' compadd -a formulae ;; _wanted formulae expl 'all formulae' compadd -a formulae ;;
remove|rm|uninstall|unlink|cleanup|link|ln) reinstall|remove|rm|uninstall|unlink|cleanup|link|ln)
_brew_installed_formulae _brew_installed_formulae
_wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;; _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
esac esac

View file

@ -1,13 +1,25 @@
alias be="bundle exec" alias be="bundle exec"
alias bi="bundle install"
alias bl="bundle list" alias bl="bundle list"
alias bp="bundle package" alias bp="bundle package"
alias bo="bundle open" alias bo="bundle open"
alias bu="bundle update" alias bu="bundle update"
bundler_version=`bundle version | cut -d' ' -f3`
if [[ $bundler_version > '1.4.0' || $bundler_version = '1.4.0' ]]; then
if [[ "$(uname)" == 'Darwin' ]]
then
local cores_num="$(sysctl hw.ncpu | awk '{print $2}')"
else
local cores_num="$(nproc)"
fi
eval "alias bi='bundle install --jobs=$cores_num'"
else
alias bi='bundle install'
fi
# The following is based on https://github.com/gma/bundler-exec # The following is based on https://github.com/gma/bundler-exec
bundled_commands=(annotate berks cap capify cucumber foodcritic foreman guard jekyll kitchen knife middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor thin thor unicorn unicorn_rails puma) bundled_commands=(annotate berks cap capify cucumber foodcritic foreman guard jekyll kitchen knife middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor taps thin thor unicorn unicorn_rails puma)
## Functions ## Functions
@ -42,3 +54,4 @@ for cmd in $bundled_commands; do
compdef _$cmd bundled_$cmd=$cmd compdef _$cmd bundled_$cmd=$cmd
fi fi
done done

View file

@ -4,7 +4,7 @@
if [[ -f config/deploy.rb || -f Capfile ]]; then if [[ -f config/deploy.rb || -f Capfile ]]; then
if [[ ! -f .cap_tasks~ || config/deploy.rb -nt .cap_tasks~ ]]; then if [[ ! -f .cap_tasks~ || config/deploy.rb -nt .cap_tasks~ ]]; then
echo "\nGenerating .cap_tasks~..." > /dev/stderr echo "\nGenerating .cap_tasks~..." > /dev/stderr
cap --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~ cap -v --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~
fi fi
compadd `cat .cap_tasks~` compadd `cat .cap_tasks~`
fi fi

19
plugins/docker/README.md Normal file
View file

@ -0,0 +1,19 @@
## Docker autocomplete plugin
- Adds autocomplete options for all docker commands.
- Will also show containerIDs and Image names where applicable
####Shows help for all commands
![General Help](http://i.imgur.com/tUBO9jh.png "Help for all commands")
####Shows your downloaded images where applicable
![Images](http://i.imgur.com/R8ZsWO1.png "Images")
####Shows your running containers where applicable
![Containers](http://i.imgur.com/WQtbheg.png "Containers")
Maintainer : Ahmed Azaan ([@aeonazaan](https://twitter.com/aeonazaan))

290
plugins/docker/_docker Normal file
View file

@ -0,0 +1,290 @@
#compdef docker
# Docker autocompletion for oh-my-zsh
# Requires: Docker installed
# Author : Azaan (@aeonazaan)
# ----- Helper functions
# Output a selectable list of all running docker containers
__docker_containers() {
declare -a cont_cmd
cont_cmd=($(docker ps | awk 'NR>1{print $1":[CON("$1")"$2"("$3")]"}'))
_describe 'containers' cont_cmd
}
# output a selectable list of all docker images
__docker_images() {
declare -a img_cmd
img_cmd=($(docker images | awk 'NR>1{print $1}'))
_describe 'images' img_cmd
}
# ----- Commands
# Seperate function for each command, makes extension easier later
# ---------------------------
__attach() {
__docker_containers
}
__build() {
_arguments \
'-q=false[Suppress verbose build output]' \
'-t="[fuck to be applied to the resulting image in case of success]' \
'*:files:_files'
}
__commit() {
_arguments \
'-author="[Author]' \
'-m="[Commit message]' \
'-run="[Config automatically applied when the image is run.\n]'
__docker_containers
}
__diff() {
__docker_containers
}
__export() {
__docker_containers
}
__history() {
__docker_images
}
__images() {
_arguments \
'-a[show all images]' \
'-notrunc[dont truncate output]' \
'-q[only show numeric IDs]' \
'-viz[output graph in graphviz format]'
__docker_images
}
__import() {
_arguments '*:files:_files'
}
__info() {
# no arguments
}
__insert() {
__docker_images
_arguments '*:files:_files'
}
__inspect() {
__docker_images
__docker_containers
}
__kill() {
__docker_containers
}
__login() {
_arguments \
'-e="[email]' \
'-p="[password]' \
'-u="[username]' \
}
__logs() {
__docker_containers
}
__port() {
__docker_containers
}
__top() {
__docker_containers
}
__ps() {
_arguments \
'-a[Show all containers. Only running containers are shown by default.]' \
'-beforeId="[Show only container created before Id, include non-running ones.]' \
'-l[Show only the latest created container, include non-running ones.]' \
'-n=[Show n last created containers, include non-running ones.]' \
'-notrurrrrnc[Dont truncate output]' \
'-q[Only display numeric IDs]' \
'-s[Display sizes]' \
'-sinceId="[Show only containers created since Id, include non-running ones.]'
}
__pull() {
_arguments '-t="[Download tagged image in repository]'
}
__push() {
}
__restart() {
_arguments '-t=[number of seconds to try to stop before killing]'
__docker_containers
}
__rm() {
_arguments '-v[Remove the volumes associated to the container]'
__docker_containers
}
__rmi() {
__docker_images
}
__run() {
_arguments \
'-a=[Attach to stdin, stdout or stderr.]' \
'-c=[CPU shares (relative weight)]' \
'-d[Detached mode: leave the container running in the background]' \
'-dns=[Set custom dns servers]' \
'-e=[Set environment variables]' \
'-entrypoint="[Overwrite the default entrypoint of the image]' \
'-h="[Container host name]' \
'-i[Keep stdin open even if not attached]' \
'-m=[Memory limit (in bytes)]' \
'-p=[Expose a containers port to the host (use docker port to see the actual mapping)]' \
'-t[Allocate a pseudo-tty]' \
'-u="[Username or UID]' \
'-v=[Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)]' \
'-volumes-from="[Mount volumes from the specified container]'
__docker_images
}
__search() {
_arguments '-notrunc[Dont truncate output]'
}
__start() {
__docker_containers
}
__stop() {
_arguments '-t=[number of seconds to try to stop before killing]'
__docker_containers
}
__tag() {
_arguments '-f[Force]'
__docker_images
}
__version() {
}
__wait() {
__docker_containers
}
# end commands ---------
# ----------------------
local -a _1st_arguments
_1st_arguments=(
"attach":"Attach to a running container"
"build":"Build a container from a Dockerfile"
"commit":"Create a new image from a container's changes"
"diff":"Inspect changes on a container's filesystem"
"export":"Stream the contents of a container as a tar archive"
"history":"Show the history of an image"
"images":"List images"
"import":"Create a new filesystem image from the contents of a tarball"
"info":"Display system-wide information"
"insert":"Insert a file in an image"
"inspect":"Return low-level information on a container"
"kill":"Kill a running container"
"login":"Register or Login to the docker registry server"
"logs":"Fetch the logs of a container"
"port":"Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"
"top":"Lookup the running processes of a container"
"ps":"List containers"
"pull":"Pull an image or a repository from the docker registry server"
"push":"Push an image or a repository to the docker registry server"
"restart":"Restart a running container"
"rm":"Remove one or more containers"
"rmi":"Remove one or more images"
"run":"Run a command in a new container"
"search":"Search for an image in the docker index"
"start":"Start a stopped container"
"stop":"Stop a running container"
"tag":"Tag an image into a repository"
"version":"Show the docker version information"
"wait":"Block until a container stops, then print its exit code"
)
_arguments '*:: :->command'
if (( CURRENT == 1 )); then
_describe -t commands "docker command" _1st_arguments
return
fi
local -a _command_args
case "$words[1]" in
attach)
__docker_containers ;;
build)
__build ;;
commit)
__commit ;;
diff)
__diff ;;
export)
__export ;;
history)
__history ;;
images)
__images ;;
import)
__import ;;
info)
__info ;;
insert)
__insert ;;
inspect)
__inspect ;;
kill)
__kill ;;
login)
__login ;;
logs)
__logs ;;
port)
__port ;;
top)
__top ;;
ps)
__ps ;;
pull)
__pull ;;
push)
__push ;;
restart)
__restart ;;
rm)
__rm ;;
rmi)
__rmi ;;
run)
__run ;;
search)
__search ;;
start)
__start ;;
stop)
__stop ;;
tag)
__tag ;;
version)
__version ;;
wait)
__wait ;;
esac

View file

@ -52,7 +52,7 @@ function extract() {
(*.xz) unxz "$1" ;; (*.xz) unxz "$1" ;;
(*.lzma) unlzma "$1" ;; (*.lzma) unlzma "$1" ;;
(*.Z) uncompress "$1" ;; (*.Z) uncompress "$1" ;;
(*.zip) unzip "$1" -d $extract_dir ;; (*.zip|*.war|*.jar) unzip "$1" -d $extract_dir ;;
(*.rar) unrar x -ad "$1" ;; (*.rar) unrar x -ad "$1" ;;
(*.7z) 7za x "$1" ;; (*.7z) 7za x "$1" ;;
(*.deb) (*.deb)

View file

@ -1,5 +1,6 @@
# Open folder in ForkLift.app from console # Open folder in ForkLift.app of ForkLift2.app from console
# Author: Adam Strzelecki nanoant.com, modified by Bodo Tasche bitboxer.de # Author: Adam Strzelecki nanoant.com, modified by Bodo Tasche bitboxer.de
# Updated to support ForkLift2 by Johan Kaving
# #
# Usage: # Usage:
# fl [<folder>] # fl [<folder>]
@ -22,9 +23,33 @@ function fl {
fi fi
fi fi
osascript 2>&1 1>/dev/null <<END osascript 2>&1 1>/dev/null <<END
tell application "ForkLift"
activate try
end tell tell application "Finder"
set appName to name of application file id "com.binarynights.ForkLift2"
end tell
on error err_msg number err_num
tell application "Finder"
set appName to name of application file id "com.binarynights.ForkLift"
end tell
end try
if application appName is running
tell application appName
activate
end tell
else
tell application appName
activate
end tell
repeat until application appName is running
delay 1
end repeat
tell application appName
activate
end tell
end if
tell application "System Events" tell application "System Events"
tell application process "ForkLift" tell application process "ForkLift"
try try
@ -36,7 +61,7 @@ function fl {
keystroke "g" using {command down, shift down} keystroke "g" using {command down, shift down}
tell sheet 1 of topWindow tell sheet 1 of topWindow
set value of text field 1 to "$PWD" set value of text field 1 to "$PWD"
keystroke return keystroke return
end tell end tell
end tell end tell
end tell end tell

View file

@ -9,8 +9,9 @@ _gem_installed() {
local -a _1st_arguments local -a _1st_arguments
_1st_arguments=( _1st_arguments=(
'build:Build a gem from a gemspec'
'cert:Manage RubyGems certificates and signing settings' 'cert:Manage RubyGems certificates and signing settings'
'check:Check installed gems' 'check:Check a gem repository for added or missing files'
'cleanup:Clean up old versions of installed gems in the local repository' 'cleanup:Clean up old versions of installed gems in the local repository'
'contents:Display the contents of the installed gems' 'contents:Display the contents of the installed gems'
'dependency:Show the dependencies of an installed gem' 'dependency:Show the dependencies of an installed gem'
@ -21,7 +22,7 @@ _1st_arguments=(
'install:Install a gem into the local repository' 'install:Install a gem into the local repository'
'list:Display gems whose name starts with STRING' 'list:Display gems whose name starts with STRING'
'lock:Generate a lockdown list of gems' 'lock:Generate a lockdown list of gems'
'mirror:Mirror a gem repository' 'mirror:Mirror all gem files (requires rubygems-mirror)'
'outdated:Display all gems that need updates' 'outdated:Display all gems that need updates'
'owner:Manage gem owners on RubyGems.org.' 'owner:Manage gem owners on RubyGems.org.'
'pristine:Restores installed gems to pristine condition from files located in the gem cache' 'pristine:Restores installed gems to pristine condition from files located in the gem cache'
@ -35,8 +36,9 @@ _1st_arguments=(
'stale:List gems along with access times' 'stale:List gems along with access times'
'uninstall:Uninstall gems from the local repository' 'uninstall:Uninstall gems from the local repository'
'unpack:Unpack an installed gem to the current directory' 'unpack:Unpack an installed gem to the current directory'
'update:Update the named gems (or all installed gems) in the local repository' 'update:Update installed gems to the latest version'
'which:Find the location of a library file you can require' 'which:Find the location of a library file you can require'
'yank:Remove a specific gem version release from RubyGems.org'
) )
local expl local expl

View file

@ -20,6 +20,12 @@
# c. Or, use this file as a oh-my-zsh plugin. # c. Or, use this file as a oh-my-zsh plugin.
# #
#Alias
alias gf='git flow'
alias gcd='git checkout develop'
alias gch='git checkout hotfix'
alias gcr='git checkout release'
_git-flow () _git-flow ()
{ {
local curcontext="$curcontext" state line local curcontext="$curcontext" state line

View file

@ -60,3 +60,24 @@ _git-branch ()
"($l $c $m -d)-D[delete a branch]" \ "($l $c $m -d)-D[delete a branch]" \
$dependent_deletion_args $dependent_deletion_args
} }
(( $+functions[__git_ignore_line] )) ||
__git_ignore_line () {
declare -a ignored
ignored=()
((CURRENT > 1)) &&
ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
((CURRENT < $#line)) &&
ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
$* -F ignored
}
(( $+functions[__git_ignore_line_inside_arguments] )) ||
__git_ignore_line_inside_arguments () {
declare -a compadd_opts
zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
__git_ignore_line $* $compadd_opts
}

View file

@ -5,6 +5,8 @@ alias gst='git status'
compdef _git gst=git-status compdef _git gst=git-status
alias gd='git diff' alias gd='git diff'
compdef _git gd=git-diff compdef _git gd=git-diff
alias gdc='git diff --cached'
compdef _git gdc=git-diff
alias gl='git pull' alias gl='git pull'
compdef _git gl=git-pull compdef _git gl=git-pull
alias gup='git pull --rebase' alias gup='git pull --rebase'
@ -22,6 +24,8 @@ alias gca='git commit -v -a'
compdef _git gc=git-commit compdef _git gc=git-commit
alias gca!='git commit -v -a --amend' alias gca!='git commit -v -a --amend'
compdef _git gca!=git-commit compdef _git gca!=git-commit
alias gcmsg='git commit -m'
compdef _git gcmsg=git-commit
alias gco='git checkout' alias gco='git checkout'
compdef _git gco=git-checkout compdef _git gco=git-checkout
alias gcm='git checkout master' alias gcm='git checkout master'
@ -52,9 +56,9 @@ compdef gcount=git
alias gcl='git config --list' alias gcl='git config --list'
alias gcp='git cherry-pick' alias gcp='git cherry-pick'
compdef _git gcp=git-cherry-pick compdef _git gcp=git-cherry-pick
alias glg='git log --stat --max-count=5' alias glg='git log --stat --max-count=10'
compdef _git glg=git-log compdef _git glg=git-log
alias glgg='git log --graph --max-count=5' alias glgg='git log --graph --max-count=10'
compdef _git glgg=git-log compdef _git glgg=git-log
alias glgga='git log --graph --decorate --all' alias glgga='git log --graph --decorate --all'
compdef _git glgga=git-log compdef _git glgga=git-log
@ -70,7 +74,10 @@ alias grh='git reset HEAD'
alias grhh='git reset HEAD --hard' alias grhh='git reset HEAD --hard'
alias gclean='git reset --hard && git clean -dfx' alias gclean='git reset --hard && git clean -dfx'
alias gwc='git whatchanged -p --abbrev-commit --pretty=medium' alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
alias gf='git ls-files | grep'
#remove the gf alias
#alias gf='git ls-files | grep'
alias gpoat='git push origin --all && git push origin --tags' alias gpoat='git push origin --all && git push origin --tags'
alias gmt='git mergetool --no-prompt' alias gmt='git mergetool --no-prompt'
compdef _git gm=git-mergetool compdef _git gm=git-mergetool
@ -78,7 +85,11 @@ compdef _git gm=git-mergetool
alias gg='git gui citool' alias gg='git gui citool'
alias gga='git gui citool --amend' alias gga='git gui citool --amend'
alias gk='gitk --all --branches' alias gk='gitk --all --branches'
alias gsts='git stash show --text' alias gsts='git stash show --text'
alias gsta='git stash'
alias gstp='git stash pop'
alias gstd='git stash drop'
# Will cd into the top of the current repository # Will cd into the top of the current repository
# or submodule. # or submodule.
@ -124,3 +135,17 @@ function _git_log_prettily(){
} }
alias glp="_git_log_prettily" alias glp="_git_log_prettily"
compdef _git glp=git-log compdef _git glp=git-log
# Work In Progress (wip)
# These features allow to pause a branch development and switch to another one (wip)
# When you want to go back to work, just unwip it
#
# This function return a warning if the current branch is a wip
function work_in_progress() {
if $(git log -n 1 | grep -q -c wip); then
echo "WIP!!"
fi
}
# these alias commit and uncomit wip branches
alias gwip='git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m "wip"'
alias gunwip='git log -n 1 | grep -q -c wip && git reset HEAD~1'

View file

@ -0,0 +1,12 @@
function gi() { curl http://gitignore.io/api/$@ ;}
_gitignireio_get_command_list() {
curl -s http://gitignore.io/api/list | tr "," "\n"
}
_gitignireio () {
compset -P '*,'
compadd -S '' `_gitignireio_get_command_list`
}
compdef _gitignireio gi

View file

@ -19,6 +19,9 @@ if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then
# source settings of old agent, if applicable # source settings of old agent, if applicable
if [ -f "${GPG_ENV}" ]; then if [ -f "${GPG_ENV}" ]; then
. ${GPG_ENV} > /dev/null . ${GPG_ENV} > /dev/null
export GPG_AGENT_INFO
export SSH_AUTH_SOCK
export SSH_AGENT_PID
fi fi
# check again if another agent is running using the newly sourced settings # check again if another agent is running using the newly sourced settings

View file

@ -0,0 +1,58 @@
# Easily jump around the file system by manually adding marks
# marks are stored as symbolic links in the directory $MARKPATH (default $HOME/.marks)
#
# jump FOO: jump to a mark named FOO
# mark FOO: create a mark named FOO
# unmark FOO: delete a mark
# marks: lists all marks
#
export MARKPATH=$HOME/.marks
jump() {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
mark() {
if (( $# == 0 )); then
MARK=$(basename "$(pwd)")
else
MARK="$1"
fi
if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK"
fi
}
unmark() {
rm -i "$MARKPATH/$1"
}
autoload colors
marks() {
for link in $MARKPATH/*(@); do
local markname="$fg[cyan]${link:t}$reset_color"
local markpath="$fg[blue]$(readlink $link)$reset_color"
printf "%s\t" $markname
printf "-> %s \t\n" $markpath
done
}
_completemarks() {
if [[ $(ls "${MARKPATH}" | wc -l) -gt 1 ]]; then
reply=($(ls $MARKPATH/**/*(-) | grep : | sed -E 's/(.*)\/([_\da-zA-Z\-]*):$/\2/g'))
else
if readlink -e "${MARKPATH}"/* &>/dev/null; then
reply=($(ls "${MARKPATH}"))
fi
fi
}
compctl -K _completemarks jump
compctl -K _completemarks unmark
_mark_expansion() {
setopt extendedglob
autoload -U modify-current-argument
modify-current-argument '$(readlink "$MARKPATH/$ARG")'
}
zle -N _mark_expansion
bindkey "^g" _mark_expansion

View file

@ -0,0 +1,18 @@
function knife_ssh() {
grep -q $1 ~/.knife_comp~ 2> /dev/null || rm -f ~/.knife_comp~;
ssh $(knife node show $1 | awk '/IP:/{print $2}')
}
_knife_ssh() {
if hash knife 2>/dev/null; then
if [[ ! -f ~/.knife_comp~ ]]; then
echo "\nGenerating ~/.knife_comp~..." >/dev/stderr
knife node list > ~/.knife_comp~
fi
compadd $(<~/.knife_comp~)
else
echo "Could not find knife" > /dev/stderr;
fi
}
compdef _knife_ssh knife_ssh

63
plugins/mix/_mix Normal file
View file

@ -0,0 +1,63 @@
#compdef mix
#autoload
# Elixir mix zsh completion
local -a _1st_arguments
_1st_arguments=(
'archive:Archive this project into a .ez file'
'clean:Clean generated application files'
'compile:Compile source files'
'deps:List dependencies and their status'
"deps.clean:Remove dependencies' files"
'deps.compile:Compile dependencies'
'deps.get:Get all out of date dependencies'
'deps.unlock:Unlock the given dependencies'
'deps.update:Update dependencies'
'do:Executes the commands separated by comma'
'escriptize:Generates an escript for the project'
'help:Print help information for tasks'
'local:List local tasks'
'local.install:Install a task or an archive locally'
'local.rebar:Install rebar locally'
'local.uninstall:Uninstall local tasks or archives'
'new:Creates a new Elixir project'
'run:Run the given file or expression'
"test:Run a project's tests"
'--help:Describe available tasks'
'--version:Prints the Elixir version information'
)
__task_list ()
{
local expl
declare -a tasks
tasks=(archive clean compile deps deps.clean deps.compile deps.get deps.unlock deps.update do escriptize help local local.install local.rebar local.uninstall new run test)
_wanted tasks expl 'help' compadd $tasks
}
local expl
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "mix subcommand" _1st_arguments
return
;;
(options)
case $line[1] in
(help)
_arguments ':feature:__task_list'
esac
;;
esac

View file

@ -0,0 +1,2 @@
# Allow SSH tab completion for mosh hostnames
compdef mosh=ssh

View file

@ -1,5 +1,13 @@
# Open the node api for your current version to the optional section. # Open the node api for your current version to the optional section.
# TODO: Make the section part easier to use. # TODO: Make the section part easier to use.
function node-docs { function node-docs {
open "http://nodejs.org/docs/$(node --version)/api/all.html#all_$1" # get the open command
local open_cmd
if [[ $(uname -s) == 'Darwin' ]]; then
open_cmd='open'
else
open_cmd='xdg-open'
fi
$open_cmd "http://nodejs.org/docs/$(node --version)/api/all.html#all_$1"
} }

26
plugins/nvm/_nvm Normal file
View file

@ -0,0 +1,26 @@
#compdef nvm
#autoload
[[ -s ~/.nvm/nvm.sh ]] || return 0
local -a _1st_arguments
_1st_arguments=(
'help:show help'
'install:download and install a version'
'uninstall:uninstall a version'
'use:modify PATH to use version'
'run:run version with given arguments'
'ls:list installed versions or versions matching a given description'
'ls-remote:list remote versions available for install'
'deactivate:undo effects of NVM on current shell'
'alias:show or set aliases'
'unalias:deletes an alias'
'copy-packages:install global NPM packages to current version'
)
_arguments -C '*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "nvm subcommand" _1st_arguments
return
fi

View file

@ -0,0 +1,3 @@
# The addition 'nvm install' attempts in ~/.profile
[[ -s ~/.nvm/nvm.sh ]] && . ~/.nvm/nvm.sh

View file

@ -157,3 +157,37 @@ function trash() {
function vncviewer() { function vncviewer() {
open vnc://$@ open vnc://$@
} }
# iTunes control function
function itunes() {
local opt=$1
shift
case "$opt" in
launch|play|pause|stop|rewind|resume|quit)
;;
mute)
opt="set mute to true"
;;
unmute)
opt="set mute to false"
;;
next|previous)
opt="$opt track"
;;
""|-h|--help)
echo "Usage: itunes <option>"
echo "option:"
echo "\tlaunch|play|pause|stop|rewind|resume|quit"
echo "\tmute|unmute\tcontrol volume set"
echo "\tnext|previous\tplay next or previous track"
echo "\thelp\tshow this message and exit"
return 0
;;
*)
print "Unkonwn option: $opt"
return 1
;;
esac
osascript -e "tell application \"iTunes\" to $opt"
}

View file

@ -6,8 +6,8 @@
_pip_all() { _pip_all() {
# we cache the list of packages (originally from the macports plugin) # we cache the list of packages (originally from the macports plugin)
if (( ! $+piplist )); then if (( ! $+piplist )); then
echo -n " (caching package index...)" echo -n " (caching package index...)"
piplist=($(pip search * | cut -d ' ' -f 1 | tr '[A-Z]' '[a-z]')) piplist=($(pip search * | cut -d ' ' -f 1 | tr '[A-Z]' '[a-z]'))
fi fi
} }
@ -62,8 +62,13 @@ case "$words[1]" in
'(--no-install)--no-install[only download packages]' \ '(--no-install)--no-install[only download packages]' \
'(--no-download)--no-download[only install downloaded packages]' \ '(--no-download)--no-download[only install downloaded packages]' \
'(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \ '(--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 '1: :->packages' && return 0
if [[ "$state" == packages ]]; then if [[ "$state" == packages ]]; then
_pip_all _pip_all
_wanted piplist expl 'packages' compadd -a piplist _wanted piplist expl 'packages' compadd -a piplist

381
plugins/pod/_pod Normal file
View file

@ -0,0 +1,381 @@
#compdef pod
#autoload
# -----------------------------------------------------------------------------
# FILE: _pod
# DESCRIPTION: Cocoapods autocomplete plugin for Oh-My-Zsh
# http://cocoapods.org
# AUTHOR: Alexandre Joly (alexandre.joly@mekanics.ch)
# GITHUB: https://github.com/mekanics
# TWITTER: @jolyAlexandre
# VERSION: 0.0.1
# LICENSE: MIT
# -----------------------------------------------------------------------------
local -a _1st_arguments
_1st_arguments=(
'help:Show help for the given command.'
'install:Install project dependencies'
'ipc:Inter-process communication'
'list:List pods'
'outdated:Show outdated project dependencies'
'podfile-info:Shows information on installed Pods'
'push:Push new specifications to a spec-repo'
'repo:Manage spec-repositories'
'search:Searches for pods'
'setup:Setup the CocoaPods environment'
'spec:Manage pod specs'
'update:Update outdated project dependencies'
)
local -a _repo_arguments
_repo_arguments=(
'add:Add a spec repo'
'lint:Validates all specs in a repo'
'update:Update a spec repo'
)
local -a _spec_arguments
_spec_arguments=(
'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'
)
local -a _ipc_arguments
_ipc_arguments=(
'list:Lists the specifications know to CocoaPods'
'podfile:Converts a Podfile to YAML'
'repl:The repl listens to commands on standard input'
'spec:Converts a podspec to YAML'
'update-search-index:Updates the search index'
)
local -a _list_arguments
_list_arguments=(
'new:Lists pods introduced in the master spec-repo since the last check'
)
local -a _inherited_options
_inherited_options=(
'(--silent)--silent[Show nothing]' \
'(--version)--version[Show the version of CocoaPods]' \
'(--no-color)--no-color[Show output without color]' \
'(--verbose)--verbose[Show more debugging information]' \
'(--help)--help[Show help banner of specified command]'
)
local -a _install_options
_install_options=(
'(--no-clean)--no-clean[Leave SCM dirs like `.git` and `.svn` intact after downloading]' \
'(--no-integrate)--no-integrate[Skip integration of the Pods libraries in the Xcode project(s)]' \
'(--no-repo-update)--no-repo-update[Skip running `pod repo update` before install]'
)
local -a _update_options
_update_options=(
'(--no-clean)--no-clean[Leave SCM dirs like `.git` and `.svn intact after downloading]' \
'(--no-integrate)--no-integrate[Skip integration of the Pods libraries in the Xcode project(s)]' \
'(--no-repo-update)--no-repo-update[Skip running `pod repo update before install]'
)
local -a _outdated_options
_outdated_options=(
'(--no-repo-update)--no-repo-update[Skip running `pod repo update` before install]'
)
local -a _search_options
_search_options=(
'(--full)--full[Search by name, summary, and description]' \
'(--stats)--stats[Show additional stats (like GitHub watchers and forks)]' \
'(--ios)--ios[Restricts the search to Pods supported on iOS]' \
'(--osx)--osx[Restricts the search to Pods supported on OS X]'
)
local -a _list_options
_list_options=(
'(--update)--update[Run `pod repo update` before listing]'
)
local -a _podfile_info_options
_podfile_info_options=(
'(--all)--all[Show information about all Pods with dependencies that are used in a project]' \
'(--md)--md[Output information in Markdown format]' \
'*:script or directory:_files'
)
local -a _push_options
_push_options=(
'(--allow-warnings)--allow-warnings[Allows pushing even if there are warnings]' \
'(--local-only)--local-only[Does not perform the step of pushing REPO to its remote]' \
'*:script or directory:_files'
)
local -a _repo_lint_options
_repo_lint_options=(
'(--only-errors)--only-errors[Lint presents only the errors]'
)
local -a _setup_options
_setup_options=(
'(--push)--push[Use this option to enable push access once granted]'
)
local -a _spec_lint_options
_spec_lint_options=(
'(--quick)--quick[Lint skips checks that would require to download and build the spec]' \
'(--only-errors)--only-errors[Lint validates even if warnings are present]' \
'(--no-clean)--no-clean[Lint leaves the build directory intact for inspection]' \
'*:script or directory:_files'
)
local -a _spec_cat_options
_spec_cat_options=(
'(--show-all)--show-all[Pick from all versions of the given podspec]'
)
local -a _spec_which_options
_spec_which_options=(
'(--show-all)--show-all[Print all versions of the given podspec]'
)
local -a _spec_edit_options
_spec_edit_options=(
'(--show-all)--show-all[Pick which spec to edit from all available versions of the given podspec]'
)
__first_command_list ()
{
local expl
declare -a tasks
tasks=(install ipc list outdated podfile-info push repo search setup spec update)
_wanted tasks expl 'help' compadd $tasks
}
__repo_list() {
_wanted application expl 'repo' compadd $(command ls -1 ~/.cocoapods 2>/dev/null | sed -e 's/ /\\ /g')
}
__pod-repo() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "pod repo" _repo_arguments
return
;;
(options)
case $line[1] in
(lint)
_arguments \
$_inherited_options \
$_repo_lint_options \
':feature:__repo_list'
;;
(update)
_arguments \
$_inherited_options \
':feature:__repo_list'
;;
(add)
_arguments \
$_inherited_options
esac
;;
esac
}
__pod-spec() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "pod spec" _spec_arguments
return
;;
(options)
case $line[1] in
(create)
_arguments \
$_inherited_options
;;
(lint)
_arguments \
$_inherited_options \
$_spec_lint_options
;;
(cat)
_arguments \
$_inherited_options \
$_spec_cat_options
;;
(which)
_arguments \
$_inherited_options \
$_spec_which_options
;;
(edit)
_arguments \
$_inherited_options \
$_spec_edit_options
;;
esac
return
;;
esac
}
__pod-ipc() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "pod ipc" _ipc_arguments
return
;;
(options)
_arguments -C \
$_inherited_options
return
;;
esac
}
__pod-list() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
$_inherited_options \
$_list_options \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "pod list" _list_arguments
return
;;
(options)
_arguments -C \
$_inherited_options \
$_list_options
return
;;
esac
}
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
$_inherited_options \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "pod" _1st_arguments
return
;;
(options)
case $line[1] in
(help)
_arguments \
$_inherited_options \
':help:__first_command_list'
;;
(push)
_arguments \
$_inherited_options \
$_push_options \
':repo:__repo_list'
;;
(repo)
__pod-repo
;;
(spec)
__pod-spec
;;
(ipc)
__pod-ipc
;;
(list)
__pod-list
;;
(install)
_arguments \
$_inherited_options \
$_install_options
;;
(update)
_arguments \
$_inherited_options \
$_update_options
;;
(outdated)
_arguments \
$_inherited_options \
$_outdated_options
;;
(search)
_arguments \
$_inherited_options \
$_search_options
;;
(podfile-info)
_arguments \
$_inherited_options \
$_podfile_info_options
;;
(setup)
_arguments \
$_inherited_options \
$_setup_options
;;
esac
;;
esac

View file

@ -4,7 +4,11 @@ function _rails_command () {
if [ -e "script/server" ]; then if [ -e "script/server" ]; then
ruby script/$@ ruby script/$@
else else
ruby script/rails $@ if [ -e "bin/rails" ]; then
bin/rails $@
else
rails $@
fi
fi fi
} }

View file

@ -31,7 +31,7 @@ compdef _rb19 rb19
function rb20 { function rb20 {
if [ -z "$1" ]; then if [ -z "$1" ]; then
rvm use "$ruby" rvm use "$ruby20"
else else
rvm use "$ruby20@$1" rvm use "$ruby20@$1"
fi fi

View file

@ -0,0 +1,28 @@
# ------------------------------------------------------------------------------
# FILE: sfffe.plugin.zsh
# DESCRIPTION: search file for FE
# AUTHOR: yleo77 (ylep77@gmail.com)
# VERSION: 0.1
# REQUIRE: ack
# ------------------------------------------------------------------------------
if [ ! -x $(which ack) ]; then
echo \'ack\' is not installed!
exit -1
fi
ajs() {
ack "$@" --type js
}
acss() {
ack "$@" --type css
}
fjs() {
find ./ -name "$@*" -type f | grep '\.js'
}
fcss() {
find ./ -name "$@*" -type f | grep '\.css'
}

View file

@ -9,7 +9,7 @@
# To load multiple identities use the identities style, For # To load multiple identities use the identities style, For
# example: # example:
# #
# zstyle :omz:plugins:ssh-agent id_rsa id_rsa2 id_github # zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github
# #
# To set the maximum lifetime of the identities, use the # To set the maximum lifetime of the identities, use the
# lifetime style. The lifetime may be specified in seconds # lifetime style. The lifetime may be specified in seconds
@ -57,7 +57,7 @@ if [[ ${_plugin__forwarding} == "yes" && -n "$SSH_AUTH_SOCK" ]]; then
elif [ -f "${_plugin__ssh_env}" ]; then elif [ -f "${_plugin__ssh_env}" ]; then
# Source SSH settings, if applicable # Source SSH settings, if applicable
. ${_plugin__ssh_env} > /dev/null . ${_plugin__ssh_env} > /dev/null
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { ps x | grep ${SSH_AGENT_PID} | grep ssh-agent > /dev/null || {
_plugin__start_agent; _plugin__start_agent;
} }
else else

View file

@ -21,7 +21,8 @@ elif [[ $('uname') == 'Darwin' ]]; then
for _sublime_path in $_sublime_darwin_paths; do for _sublime_path in $_sublime_darwin_paths; do
if [[ -a $_sublime_path ]]; then if [[ -a $_sublime_path ]]; then
alias st="'$_sublime_path'" alias subl="'$_sublime_path'"
alias st=subl
break break
fi fi
done done

View file

@ -1,7 +1,7 @@
# symfony basic command completion # symfony basic command completion
_symfony_get_command_list () { _symfony_get_command_list () {
./symfony | sed "1,/Available tasks/d" | awk 'BEGIN { cat=null; } /^[A-Za-z]+$/ { cat = $1; } /^ :[a-z]+/ { print cat $1; }' php symfony | sed "1,/Available tasks/d" | awk 'BEGIN { cat=null; } /^[A-Za-z]+$/ { cat = $1; } /^ :[a-z]+/ { print cat $1; }'
} }
_symfony () { _symfony () {

View file

@ -1,3 +1,11 @@
#
# Aliases
#
alias ta='tmux attach -t'
alias ts='tmux new-session -s'
alias tl='tmux list-sessions'
# Only run if tmux is actually installed # Only run if tmux is actually installed
if which tmux &> /dev/null if which tmux &> /dev/null
then then

View file

@ -11,7 +11,7 @@ function web_search() {
fi fi
# check whether the search engine is supported # check whether the search engine is supported
if [[ ! $1 =~ '(google|bing|yahoo)' ]]; if [[ ! $1 =~ '(google|bing|yahoo|duckduckgo)' ]];
then then
echo "Search engine $1 not supported." echo "Search engine $1 not supported."
return 1 return 1
@ -24,8 +24,12 @@ function web_search() {
$open_cmd "$url" $open_cmd "$url"
return return
fi fi
if [[ $1 == 'duckduckgo' ]]; then
url="${url}/search?q=" #slightly different search syntax for DDG
url="${url}/?q="
else
url="${url}/search?q="
fi
shift # shift out $1 shift # shift out $1
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@ -34,10 +38,19 @@ function web_search() {
done done
url="${url%?}" # remove the last '+' url="${url%?}" # remove the last '+'
$open_cmd "$url" $open_cmd "$url"
} }
alias bing='web_search bing' alias bing='web_search bing'
alias google='web_search google' alias google='web_search google'
alias yahoo='web_search yahoo' alias yahoo='web_search yahoo'
alias ddg='web_search duckduckgo'
#add your own !bang searches here
alias wiki='web_search duckduckgo \!w'
alias news='web_search duckduckgo \!n'
alias youtube='web_search duckduckgo \!yt'
alias map='web_search duckduckgo \!m'
alias image='web_search duckduckgo \!i'
alias ducky='web_search duckduckgo \!'

4
plugins/z/Makefile Normal file
View file

@ -0,0 +1,4 @@
readme:
@groff -man -Tascii z.1 | col -bx
.PHONY: readme

135
plugins/z/README Normal file
View file

@ -0,0 +1,135 @@
Z(1) User Commands Z(1)
NAME
z - jump around
SYNOPSIS
z [-chlrt] [regex1 regex2 ... regexn]
AVAILABILITY
bash, zsh
DESCRIPTION
Tracks your most used directories, based on 'frecency'.
After a short learning phase, z will take you to the most 'frecent'
directory that matches ALL of the regexes given on the command line.
OPTIONS
-c restrict matches to subdirectories of the current directory.
-h show a brief help message
-l list only
-r match by rank only
-t match by recent access only
EXAMPLES
z foo cd to most frecent dir matching foo
z foo bar cd to most frecent dir matching foo and bar
z -r foo cd to highest ranked dir matching foo
z -t foo cd to most recently accessed dir matching foo
z -l foo list all dirs matching foo (by frecency)
NOTES
Installation:
Put something like this in your $HOME/.bashrc or $HOME/.zshrc:
. /path/to/z.sh
cd around for a while to build up the db.
PROFIT!!
Optionally:
Set $_Z_CMD to change the command name (default z).
Set $_Z_DATA to change the datafile (default $HOME/.z).
Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd your-
self.
Set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
(These settings should go in .bashrc/.zshrc before the lines
added above.)
Install the provided man page z.1 somewhere like
/usr/local/man/man1.
Aging:
The rank of directories maintained by z undergoes aging based on a sim-
ple formula. The rank of each entry is incremented every time it is
accessed. When the sum of ranks is greater than 6000, all ranks are
multiplied by 0.99. Entries with a rank lower than 1 are forgotten.
Frecency:
Frecency is a portmantaeu of 'recent' and 'frequency'. It is a weighted
rank that depends on how often and how recently something occured. As
far as I know, Mozilla came up with the term.
To z, a directory that has low ranking but has been accessed recently
will quickly have higher rank than a directory accessed frequently a
long time ago.
Frecency is determined at runtime.
Common:
When multiple directories match all queries, and they all have a common
prefix, z will cd to the shortest matching directory, without regard to
priority. This has been in effect, if undocumented, for quite some
time, but should probably be configurable or reconsidered.
Tab Completion:
z supports tab completion. After any number of arguments, press TAB to
complete on directories that match each argument. Due to limitations of
the completion implementations, only the last argument will be com-
pleted in the shell.
Internally, z decides you've requested a completion if the last argu-
ment passed is an absolute path to an existing directory. This may
cause unexpected behavior if the last argument to z begins with /.
ENVIRONMENT
A function _z() is defined.
The contents of the variable $_Z_CMD is aliased to _z 2>&1. If not set,
$_Z_CMD defaults to z.
The environment variable $_Z_DATA can be used to control the datafile
location. If it is not defined, the location defaults to $HOME/.z.
The environment variable $_Z_NO_RESOLVE_SYMLINKS can be set to prevent
resolving of symlinks. If it is not set, symbolic links will be
resolved when added to the datafile.
In bash, z prepends a command to the PROMPT_COMMAND environment vari-
able to maintain its database. In zsh, z appends a function _z_precmd
to the precmd_functions array.
The environment variable $_Z_NO_PROMPT_COMMAND can be set if you want
to handle PROMPT_COMMAND or precmd yourself.
The environment variable $_Z_EXCLUDE_DIRS can be set to an array of
directories to exclude from tracking. $HOME is always excluded. Direc-
tories must be full paths without trailing slashes.
FILES
Data is stored in $HOME/.z. This can be overridden by setting the
$_Z_DATA environment variable. When initialized, z will raise an error
if this path is a directory, and not function correctly.
A man page (z.1) is provided.
SEE ALSO
regex(7), pushd, popd, autojump, cdargs
Please file bugs at https://github.com/rupa/z/
z January 2013 Z(1)

155
plugins/z/z.1 Normal file
View file

@ -0,0 +1,155 @@
.TH "Z" "1" "January 2013" "z" "User Commands"
.SH
NAME
z \- jump around
.SH
SYNOPSIS
z [\-chlrt] [regex1 regex2 ... regexn]
.SH
AVAILABILITY
bash, zsh
.SH
DESCRIPTION
Tracks your most used directories, based on 'frecency'.
.P
After a short learning phase, \fBz\fR will take you to the most 'frecent'
directory that matches ALL of the regexes given on the command line.
.SH
OPTIONS
.TP
\fB\-c\fR
restrict matches to subdirectories of the current directory.
.TP
\fB\-h\fR
show a brief help message
.TP
\fB\-l\fR
list only
.TP
\fB\-r\fR
match by rank only
.TP
\fB\-t\fR
match by recent access only
.SH EXAMPLES
.TP 14
\fBz foo\fR
cd to most frecent dir matching foo
.TP 14
\fBz foo bar\fR
cd to most frecent dir matching foo and bar
.TP 14
\fBz -r foo\fR
cd to highest ranked dir matching foo
.TP 14
\fBz -t foo\fR
cd to most recently accessed dir matching foo
.TP 14
\fBz -l foo\fR
list all dirs matching foo (by frecency)
.SH
NOTES
.SS
Installation:
.P
Put something like this in your \fB$HOME/.bashrc\fR or \fB$HOME/.zshrc\fR:
.RS
.P
\fB. /path/to/z.sh\fR
.RE
.P
\fBcd\fR around for a while to build up the db.
.P
PROFIT!!
.P
Optionally:
.RS
Set \fB$_Z_CMD\fR to change the command name (default \fBz\fR).
.RE
.RS
Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR).
.RE
.RS
Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution.
.RE
.RS
Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself.
.RE
.RS
Set \fB$_Z_EXCLUDE_DIRS\fR to an array of directories to exclude.
.RE
.RS
(These settings should go in .bashrc/.zshrc before the lines added above.)
.RE
.RS
Install the provided man page \fBz.1\fR somewhere like \fB/usr/local/man/man1\fR.
.RE
.SS
Aging:
The rank of directories maintained by \fBz\fR undergoes aging based on a simple
formula. The rank of each entry is incremented every time it is accessed. When
the sum of ranks is greater than 6000, all ranks are multiplied by 0.99. Entries
with a rank lower than 1 are forgotten.
.SS
Frecency:
Frecency is a portmantaeu of 'recent' and 'frequency'. It is a weighted rank
that depends on how often and how recently something occured. As far as I
know, Mozilla came up with the term.
.P
To \fBz\fR, a directory that has low ranking but has been accessed recently
will quickly have higher rank than a directory accessed frequently a long time
ago.
.P
Frecency is determined at runtime.
.SS
Common:
When multiple directories match all queries, and they all have a common prefix,
\fBz\fR will cd to the shortest matching directory, without regard to priority.
This has been in effect, if undocumented, for quite some time, but should
probably be configurable or reconsidered.
.SS
Tab Completion:
\fBz\fR supports tab completion. After any number of arguments, press TAB to
complete on directories that match each argument. Due to limitations of the
completion implementations, only the last argument will be completed in the
shell.
.P
Internally, \fBz\fR decides you've requested a completion if the last argument
passed is an absolute path to an existing directory. This may cause unexpected
behavior if the last argument to \fBz\fR begins with \fB/\fR.
.SH
ENVIRONMENT
A function \fB_z()\fR is defined.
.P
The contents of the variable \fB$_Z_CMD\fR is aliased to \fB_z 2>&1\fR. If not
set, \fB$_Z_CMD\fR defaults to \fBz\fR.
.P
The environment variable \fB$_Z_DATA\fR can be used to control the datafile
location. If it is not defined, the location defaults to \fB$HOME/.z\fR.
.P
The environment variable \fB$_Z_NO_RESOLVE_SYMLINKS\fR can be set to prevent
resolving of symlinks. If it is not set, symbolic links will be resolved when
added to the datafile.
.P
In bash, \fBz\fR prepends a command to the \fBPROMPT_COMMAND\fR environment
variable to maintain its database. In zsh, \fBz\fR appends a function
\fB_z_precmd\fR to the \fBprecmd_functions\fR array.
.P
The environment variable \fB$_Z_NO_PROMPT_COMMAND\fR can be set if you want to
handle \fBPROMPT_COMMAND\fR or \fBprecmd\fR yourself.
.P
The environment variable \fB$_Z_EXCLUDE_DIRS\fR can be set to an array of
directories to exclude from tracking. \fB$HOME\fR is always excluded.
Directories must be full paths without trailing slashes.
.SH
FILES
Data is stored in \fB$HOME/.z\fR. This can be overridden by setting the
\fB$_Z_DATA\fR environment variable. When initialized, \fBz\fR will raise an
error if this path is a directory, and not function correctly.
.P
A man page (\fBz.1\fR) is provided.
.SH
SEE ALSO
regex(7), pushd, popd, autojump, cdargs
.P
Please file bugs at https://github.com/rupa/z/

6
plugins/z/z.plugin.zsh Normal file
View file

@ -0,0 +1,6 @@
_load_z() {
source $1/z.sh
}
[[ -f $ZSH_CUSTOM/plugins/z/z.plugin.zsh ]] && _load_z $ZSH_CUSTOM/plugins/z
[[ -f $ZSH/plugins/z/z.plugin.zsh ]] && _load_z $ZSH/plugins/z

228
plugins/z/z.sh Normal file
View file

@ -0,0 +1,228 @@
# Copyright (c) 2009 rupa deadwyler under the WTFPL license
# maintains a jump-list of the directories you actually use
#
# INSTALL:
# * put something like this in your .bashrc/.zshrc:
# . /path/to/z.sh
# * cd around for a while to build up the db
# * PROFIT!!
# * optionally:
# set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).
# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
#
# USE:
# * z foo # cd to most frecent dir matching foo
# * z foo bar # cd to most frecent dir matching foo and bar
# * z -r foo # cd to highest ranked dir matching foo
# * z -t foo # cd to most recently accessed dir matching foo
# * z -l foo # list matches instead of cd
# * z -c foo # restrict matches to subdirs of $PWD
case $- in
*i*) ;;
*) echo 'ERROR: z.sh is meant to be sourced, not directly executed.'
esac
[ -d "${_Z_DATA:-$HOME/.z}" ] && {
echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory."
}
_z() {
local datafile="${_Z_DATA:-$HOME/.z}"
# bail out if we don't own ~/.z (we're another user but our ENV is still set)
[ -f "$datafile" -a ! -O "$datafile" ] && return
# add entries
if [ "$1" = "--add" ]; then
shift
# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return
# don't track excluded dirs
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
[ "$*" = "$exclude" ] && return
done
# maintain the file
local tempfile
tempfile="$(mktemp "$datafile.XXXXXX")" || return
while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '
BEGIN {
rank[path] = 1
time[path] = now
}
$2 >= 1 {
if( $1 == path ) {
rank[$1] = $2 + 1
time[$1] = now
} else {
rank[$1] = $2
time[$1] = $3
}
count += $2
}
END {
if( count > 6000 ) {
for( i in rank ) print i "|" 0.99*rank[i] "|" time[i] # aging
} else for( i in rank ) print i "|" rank[i] "|" time[i]
}
' 2>/dev/null >| "$tempfile"
if [ $? -ne 0 -a -f "$datafile" ]; then
env rm -f "$tempfile"
else
env mv -f "$tempfile" "$datafile"
fi
# tab completion
elif [ "$1" = "--complete" ]; then
while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v q="$2" -F"|" '
BEGIN {
if( q == tolower(q) ) nocase = 1
split(substr(q,3),fnd," ")
}
{
if( nocase ) {
for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = ""
} else {
for( i in fnd ) $1 !~ fnd[i] && $1 = ""
}
if( $1 ) print $1
}
' 2>/dev/null
else
# list/go
while [ "$1" ]; do case "$1" in
--) while [ "$1" ]; do shift; local fnd="$fnd $1";done;;
-*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in
c) local fnd="^$PWD $fnd";;
h) echo "${_Z_CMD:-z} [-chlrt] args" >&2; return;;
l) local list=1;;
r) local typ="rank";;
t) local typ="recent";;
esac; opt=${opt:1}; done;;
*) local fnd="$fnd $1";;
esac; local last=$1; shift; done
[ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1
# if we hit enter on a completion just go there
case "$last" in
# completions will always start with /
/*) [ -z "$list" -a -d "$last" ] && cd "$last" && return;;
esac
# no file yet
[ -f "$datafile" ] || return
local cd
cd="$(while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" '
function frecent(rank, time) {
dx = t-time
if( dx < 3600 ) return rank*4
if( dx < 86400 ) return rank*2
if( dx < 604800 ) return rank/2
return rank/4
}
function output(files, toopen, override) {
if( list ) {
cmd = "sort -n >&2"
for( i in files ) if( files[i] ) printf "%-10s %s\n", files[i], i | cmd
if( override ) printf "%-10s %s\n", "common:", override > "/dev/stderr"
} else {
if( override ) toopen = override
print toopen
}
}
function common(matches) {
# shortest match
for( i in matches ) {
if( matches[i] && (!short || length(i) < length(short)) ) short = i
}
if( short == "/" ) return
# shortest match must be common to each match. escape special characters in
# a copy when testing, so we can return the original.
clean_short = short
gsub(/[\(\)\[\]\|]/, "\\\\&", clean_short)
for( i in matches ) if( matches[i] && i !~ clean_short ) return
return short
}
BEGIN { split(q, a, " "); oldf = noldf = -9999999999 }
{
if( typ == "rank" ) {
f = $2
} else if( typ == "recent" ) {
f = $3-t
} else f = frecent($2, $3)
wcase[$1] = nocase[$1] = f
for( i in a ) {
if( $1 !~ a[i] ) delete wcase[$1]
if( tolower($1) !~ tolower(a[i]) ) delete nocase[$1]
}
if( wcase[$1] && wcase[$1] > oldf ) {
cx = $1
oldf = wcase[$1]
} else if( nocase[$1] && nocase[$1] > noldf ) {
ncx = $1
noldf = nocase[$1]
}
}
END {
if( cx ) {
output(wcase, cx, common(wcase))
} else if( ncx ) output(nocase, ncx, common(nocase))
}
')"
[ $? -gt 0 ] && return
[ "$cd" ] && cd "$cd"
fi
}
alias ${_Z_CMD:-z}='_z 2>&1'
[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P"
if compctl &> /dev/null; then
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# zsh populate directory list, avoid clobbering any other precmds
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
_z --add "${PWD:a}"
}
else
_z_precmd() {
_z --add "${PWD:A}"
}
fi
precmd_functions+=(_z_precmd)
}
# zsh tab completion
_z_zsh_tab_completion() {
local compl
read -l compl
reply=(${(f)"$(_z --complete "$compl")"})
}
compctl -U -K _z_zsh_tab_completion _z
elif complete &> /dev/null; then
# bash tab completion
complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z}
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# bash populate directory list. avoid clobbering other PROMPT_COMMANDs.
echo $PROMPT_COMMAND | grep -q "_z --add" || {
PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND"
}
}
fi

View file

@ -90,7 +90,7 @@ prompt_git() {
zstyle ':vcs_info:*' formats ' %u%c' zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats '%u%c' zstyle ':vcs_info:*' actionformats '%u%c'
vcs_info vcs_info
echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_}" echo -n "${ref/refs\/heads\//± }${vcs_info_msg_0_}"
fi fi
} }
@ -110,7 +110,7 @@ prompt_hg() {
# if working copy is clean # if working copy is clean
prompt_segment green black prompt_segment green black
fi fi
echo -n $(hg prompt " {rev}@{branch}") $st echo -n $(hg prompt " {rev}@{branch}") $st
else else
st="" st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g') rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
@ -137,7 +137,7 @@ prompt_dir() {
# Virtualenv: current working virtualenv # Virtualenv: current working virtualenv
prompt_virtualenv() { prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV" local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path ]]; then if [[ -n $virtualenv_path && -z $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment blue black "(`basename $virtualenv_path`)" prompt_segment blue black "(`basename $virtualenv_path`)"
fi fi
} }

View file

@ -7,12 +7,12 @@ ZSH_THEME_GIT_PROMPT_CLEAN=""
git_custom_status() { git_custom_status() {
local cb=$(current_branch) local cb=$(current_branch)
if [ -n "$cb" ]; then if [ -n "$cb" ]; then
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX" echo "$(parse_git_dirty)%{$fg_bold[yellow]%}$(work_in_progress)%{$reset_color%}$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi fi
} }
#RVM and git settings #RVM and git settings
if [[ -s ~/.rvm/scripts/rvm ]] ; then if [[ -s ~/.rvm/scripts/rvm ]] ; then
RPS1='$(git_custom_status)%{$fg[red]%}[`~/.rvm/bin/rvm-prompt`]%{$reset_color%} $EPS1' RPS1='$(git_custom_status)%{$fg[red]%}[`~/.rvm/bin/rvm-prompt`]%{$reset_color%} $EPS1'
else else
if which rbenv &> /dev/null; then if which rbenv &> /dev/null; then

View file

@ -5,16 +5,15 @@
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Color shortcuts # Color shortcuts
R=$fg[red] R=$fg_no_bold[red]
G=$fg[green] G=$fg_no_bold[green]
M=$fg[magenta] M=$fg_no_bold[magenta]
RB=$fg_bold[red] Y=$fg_no_bold[yellow]
YB=$fg_bold[yellow] B=$fg_no_bold[blue]
BB=$fg_bold[blue]
RESET=$reset_color RESET=$reset_color
if [ "$(whoami)" = "root" ]; then if [ "$(whoami)" = "root" ]; then
PROMPTCOLOR="%{$RB%}" PREFIX="-!-"; PROMPTCOLOR="%{$R%}" PREFIX="-!-";
else else
PROMPTCOLOR="" PREFIX="---"; PROMPTCOLOR="" PREFIX="---";
fi fi
@ -73,13 +72,14 @@ function custom_git_prompt() {
PROMPT='%B$PREFIX %2~ $(custom_git_prompt)%{$M%}%B»%b%{$RESET%} ' PROMPT='%B$PREFIX %2~ $(custom_git_prompt)%{$M%}%B»%b%{$RESET%} '
RPS1="${return_code}" RPS1="${return_code}"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$YB%}" ZSH_THEME_GIT_PROMPT_PREFIX="%{$Y%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$YB%}%{$RESET%} " ZSH_THEME_GIT_PROMPT_SUFFIX="%{$Y%}%{$RESET%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$R%}*" ZSH_THEME_GIT_PROMPT_DIRTY="%{$R%}*"
ZSH_THEME_GIT_PROMPT_CLEAN="" ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_AHEAD="%{$BB%}➔" ZSH_THEME_GIT_PROMPT_AHEAD="%{$B%}➔"
ZSH_THEME_GIT_STATUS_PREFIX=" " ZSH_THEME_GIT_STATUS_PREFIX=" "
@ -90,7 +90,7 @@ ZSH_THEME_GIT_PROMPT_STAGED_RENAMED="%{$G%}R"
ZSH_THEME_GIT_PROMPT_STAGED_DELETED="%{$G%}D" ZSH_THEME_GIT_PROMPT_STAGED_DELETED="%{$G%}D"
# Not-staged # Not-staged
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$R%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$R%}?"
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$R%}M" ZSH_THEME_GIT_PROMPT_MODIFIED="%{$R%}M"
ZSH_THEME_GIT_PROMPT_DELETED="%{$R%}D" ZSH_THEME_GIT_PROMPT_DELETED="%{$R%}D"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$R%}UU" ZSH_THEME_GIT_PROMPT_UNMERGED="%{$R%}UU"

View file

@ -24,7 +24,8 @@ function theme_preview() {
THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//` THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color" print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color"
source "$THEMES_DIR/$THEME" source "$THEMES_DIR/$THEME"
print -P $PROMPT cols=$(tput cols)
print -P "$PROMPT $RPROMPT"
} }
function banner() { function banner() {