1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-11 00:10:08 +00:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Bob Williams 2014-03-22 21:24:52 -04:00
commit d70e732944
34 changed files with 2035 additions and 100 deletions

4
.gitignore vendored
View file

@ -1,8 +1,8 @@
locals.zsh locals.zsh
log/.zsh_history log/.zsh_history
projects.zsh projects.zsh
custom/* custom
!custom/example !custom/plugins/example
!custom/example.zsh !custom/example.zsh
*.swp *.swp
!custom/example.zshcache !custom/example.zshcache

View file

@ -59,7 +59,7 @@ If you installed manually or changed the install location, check ZSH in ~/.zshrc
h2. Usage h2. Usage
* enable the plugins you want in your @~/.zshrc@ (take a look at @plugins/@ to see what's possible) * enable the plugins you want in your @~/.zshrc@ (take a look at the @plugins/@ directory and the "wiki":https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins to see what's possible)
** example: @plugins=(git osx ruby)@ ** example: @plugins=(git osx ruby)@
* Theme support: Change the @ZSH_THEME@ environment variable in @~/.zshrc@. * Theme support: Change the @ZSH_THEME@ environment variable in @~/.zshrc@.
** Take a look at the "current themes":https://wiki.github.com/robbyrussell/oh-my-zsh/themes that come bundled with _Oh My Zsh_. ** Take a look at the "current themes":https://wiki.github.com/robbyrussell/oh-my-zsh/themes that come bundled with _Oh My Zsh_.

View file

@ -2,5 +2,11 @@
# Color grep results # Color grep results
# Examples: http://rubyurl.com/ZXv # Examples: http://rubyurl.com/ZXv
# #
export GREP_OPTIONS='--color=auto'
# avoid VCS folders
GREP_OPTIONS=
for PATTERN in .cvs .git .hg .svn; do
GREP_OPTIONS+="--exclude-dir=$PATTERN "
done
export GREP_OPTIONS+='--color=auto '
export GREP_COLOR='1;32' export GREP_COLOR='1;32'

View file

@ -5,7 +5,6 @@ fi
HISTSIZE=10000 HISTSIZE=10000
SAVEHIST=10000 SAVEHIST=10000
setopt append_history
setopt extended_history setopt extended_history
setopt hist_expire_dups_first setopt hist_expire_dups_first
setopt hist_ignore_dups # ignore duplication command history list setopt hist_ignore_dups # ignore duplication command history list

View file

@ -20,24 +20,44 @@ bindkey -e # Use emacs key bindings
bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
if [[ "${terminfo[kpp]}" != "" ]]; then
bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
fi
if [[ "${terminfo[knp]}" != "" ]]; then
bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
fi
if [[ "${terminfo[kcuu1]}" != "" ]]; then
bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
fi
if [[ "${terminfo[kcud1]}" != "" ]]; then
bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
fi
if [[ "${terminfo[khome]}" != "" ]]; then
bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
fi
if [[ "${terminfo[kend]}" != "" ]]; then
bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
fi
bindkey ' ' magic-space # [Space] - do history expansion bindkey ' ' magic-space # [Space] - do history expansion
bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards if [[ "${terminfo[kdch1]}" != "" ]]; then
bindkey "${terminfo[kdch1]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
fi
bindkey '^?' backward-delete-char # [Backspace] - delete backward bindkey '^?' backward-delete-char # [Backspace] - delete backward
if [[ "${terminfo[kdch1]}" != "" ]]; then
bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
else
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey "\e[3~" delete-char
fi
# Edit the current command line in $EDITOR # Edit the current command line in $EDITOR
autoload -U edit-command-line autoload -U edit-command-line

View file

@ -1,4 +1,14 @@
# local _atom_paths > /dev/null 2>&1
# Your guess is as good as mine. Let's just assume that we will need this... _atom_paths=(
# - For more info visit... http://atom.io/ "$HOME/Applications/Atom.app"
# "/Applications/Atom.app"
)
for _atom_path in $_atom_paths; do
if [[ -a $_atom_path ]]; then
alias at="open -a '$_atom_path'"
break
fi
done
alias att='at .'

View file

@ -71,7 +71,9 @@ elif [[ $(uname) == "Linux" ]] ; then
} }
function battery_pct() { function battery_pct() {
if (( $+commands[acpi] )) ; then
echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')"
fi
} }
function battery_pct_remaining() { function battery_pct_remaining() {
@ -147,7 +149,6 @@ function battery_level_gauge() {
filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}; filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'};
fi fi
local charging=' ' && battery_is_charging && charging=$charging_symbol; local charging=' ' && battery_is_charging && charging=$charging_symbol;
printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%} printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%}

View file

@ -6,7 +6,7 @@ alias bu="bundle update"
# 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 mailcatcher middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor taps thin thor unicorn unicorn_rails puma) bundled_commands=(annotate berks cap capify cucumber foodcritic foreman guard irb jekyll kitchen knife mailcatcher middleman nanoc puma rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor taps thin thor unicorn unicorn_rails)
# Remove $UNBUNDLED_COMMANDS from the bundled_commands list # Remove $UNBUNDLED_COMMANDS from the bundled_commands list
for cmd in $UNBUNDLED_COMMANDS; do for cmd in $UNBUNDLED_COMMANDS; do

View file

@ -71,7 +71,7 @@ if [ ${ZSH_VERSION//\./} -ge 420 ]; then
_image_fts=(jpg jpeg png gif mng tiff tif xpm) _image_fts=(jpg jpeg png gif mng tiff tif xpm)
for ft in $_image_fts ; do alias -s $ft=$XIVIEWER; done for ft in $_image_fts ; do alias -s $ft=$XIVIEWER; done
_media_fts=(avi mpg mpeg ogm mp3 wav ogg ape rm mov mkv) _media_fts=(ape avi flv mkv mov mp3 mpeg mpg ogg ogm rm wav webm)
for ft in $_media_fts ; do alias -s $ft=mplayer ; done for ft in $_media_fts ; do alias -s $ft=mplayer ; done
#read documents #read documents

View file

@ -1,39 +1,19 @@
#!/bin/zsh # Save dirstack history to .zdirs
# # adapted from:
# Make the dirstack more persistant # github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547
#
# Add dirpersist to $plugins in ~/.zshrc to load
#
# $zdirstore is the file used to persist the stack DIRSTACKSIZE=${DIRSTACKSIZE:-20}
zdirstore=~/.zdirstore dirstack_file=${dirstack_file:-${HOME}/.zdirs}
dirpersistinstall () { if [[ -f ${dirstack_file} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
if grep 'dirpersiststore' ~/.zlogout > /dev/null; then dirstack=( ${(f)"$(< $dirstack_file)"} )
else # "cd -" won't work after login by just setting $OLDPWD, so
if read -q \?"Would you like to set up your .zlogout file for use with dirspersist? (y/n) "; then [[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
echo "# Store dirs stack\n# See $ZSH/plugins/dirspersist.plugin.zsh\ndirpersiststore" >> ~/.zlogout
else
echo "If you don't want this message to appear, remove dirspersist from \$plugins"
fi
fi fi
chpwd() {
if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
local -ax my_stack
my_stack=( ${PWD} ${dirstack} )
builtin print -l ${(u)my_stack} >! ${dirstack_file}
} }
dirpersiststore () {
dirs -p | perl -e 'foreach (reverse <STDIN>) {chomp;s/([& ])/\\$1/g ;print "if [ -d $_ ]; then pushd -q $_; fi\n"}' > $zdirstore
}
dirpersistrestore () {
if [ -f $zdirstore ]; then
source $zdirstore
fi
}
DIRSTACKSIZE=10
setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups
dirpersistinstall
dirpersistrestore
# Make popd changes permanent without having to wait for logout
alias popd="popd;dirpersiststore"

View file

@ -13,6 +13,7 @@ case $state in
cmds=( cmds=(
"version:Prints Gas's version" "version:Prints Gas's version"
"use:Uses author" "use:Uses author"
"ssh:Creates a new ssh key for an existing gas author"
"show:Shows your current user" "show:Shows your current user"
"list:Lists your authors" "list:Lists your authors"
"import:Imports current user to gasconfig" "import:Imports current user to gasconfig"
@ -25,8 +26,12 @@ case $state in
args) args)
case $line[1] in case $line[1] in
(use|delete) (use|delete)
VERSION=$(gas -v)
if [[ $VERSION == <1->.*.* ]] || [[ $VERSION == 0.<2->.* ]] || [[ $VERSION == 0.1.<6-> ]] then
_values -S , 'authors' $(cat ~/.gas/gas.authors | sed -n -e 's/^.*\[\(.*\)\]/\1/p') && ret=0
else
_values -S , 'authors' $(cat ~/.gas | sed -n -e 's/^\[\(.*\)\]/\1/p') && ret=0 _values -S , 'authors' $(cat ~/.gas | sed -n -e 's/^\[\(.*\)\]/\1/p') && ret=0
;; fi
esac esac
;; ;;
esac esac

View file

@ -56,6 +56,9 @@ if (( CURRENT == 1 )); then
fi fi
case "$words[1]" in case "$words[1]" in
build)
_files -g "*.gemspec"
;;
list) list)
if [[ "$state" == forms ]]; then if [[ "$state" == forms ]]; then
_gem_installed _gem_installed

View file

@ -149,7 +149,7 @@ function work_in_progress() {
fi fi
} }
# these alias commit and uncomit wip branches # 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 gwip='git add -A; git ls-files --deleted -z | xargs -r0 git rm; git commit -m "--wip--"'
alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1' alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
# these alias ignore changes to file # these alias ignore changes to file

1150
plugins/glassfish/_asadmin Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,3 @@
# if there is a user named 'glassfish' on the system, we'll assume
# that is the user asadmin should be run as
# grep -e '^glassfish' /etc/passwd > /dev/null && alias asadmin='sudo -u glassfish asadmin'

View file

@ -31,7 +31,7 @@ _knife() {
case $state in case $state in
knifecmd) knifecmd)
compadd -Q "$@" bootstrap client configure cookbook "cookbook site" "data bag" diff exec environment index node recipe role search ssh status upload windows $cloudproviders compadd -Q "$@" bootstrap client configure cookbook "cookbook site" "data bag" diff exec environment index node recipe role search ssh status upload vault windows $cloudproviders
;; ;;
knifesubcmd) knifesubcmd)
case $words[2] in case $words[2] in
@ -65,6 +65,9 @@ _knife() {
upload) upload)
_arguments '*:file or directory:_files -g "*"' _arguments '*:file or directory:_files -g "*"'
;; ;;
vault)
compadd -Q "$@" create decrypt delete edit remove "rotate all keys" "rotate keys" show update
;;
windows) windows)
compadd "$@" bootstrap compadd "$@" bootstrap
;; ;;

View file

@ -0,0 +1,20 @@
# Laravel4 basic command completion
_laravel4_get_command_list () {
php artisan --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }'
}
_laravel4 () {
if [ -f artisan ]; then
compadd `_laravel4_get_command_list`
fi
}
compdef _laravel4 artisan
compdef _laravel4 la4
#Alias
alias la4='php artisan'
alias la4dump='php artisan dump-autoload'
alias la4cache='php artisan cache:clear'
alias la4routes='php artisan routes'

View file

@ -59,6 +59,7 @@ case "$words[1]" in
_arguments \ _arguments \
'(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \ '(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
'(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \ '(-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-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
'(--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]' \

View file

@ -19,7 +19,7 @@
# Will Detect if a app does not exist in pow and print a (slightly) helpful # Will Detect if a app does not exist in pow and print a (slightly) helpful
# error message # error message
rack_root_detect(){ rack_root(){
setopt chaselinks setopt chaselinks
local orgdir=$(pwd) local orgdir=$(pwd)
local basedir=$(pwd) local basedir=$(pwd)
@ -32,6 +32,11 @@ rack_root_detect(){
builtin cd $orgdir 2>/dev/null builtin cd $orgdir 2>/dev/null
[[ ${basedir} == "/" ]] && return 1 [[ ${basedir} == "/" ]] && return 1
echo $basedir
}
rack_root_detect(){
basedir=$(rack_root)
echo `basename $basedir | sed -E "s/.(com|net|org)//"` echo `basename $basedir | sed -E "s/.(com|net|org)//"`
} }
@ -62,5 +67,19 @@ powit(){
fi 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 # View the standard out (puts) from any pow app
alias kaput="tail -f ~/Library/Logs/Pow/apps/*" alias kaput="tail -f ~/Library/Logs/Pow/apps/*"

View file

@ -0,0 +1,51 @@
# rake-fast
# Fast rake autocompletion plugin for oh-my-zsh
# This script caches the output for later usage and significantly speeds it up.
# It generates a .rake_tasks file in parallel to the Rakefile.
# You'll want to add `.rake_tasks` to your global .git_ignore file:
# https://help.github.com/articles/ignoring-files#global-gitignore
# You can force .rake_tasks to refresh with:
# $ rake_refresh
# This is entirely based on Ullrich Schäfer's work
# (https://github.com/robb/.dotfiles/pull/10/),
# which is inspired by this Ruby on Rails trick from 2006:
# http://weblog.rubyonrails.org/2006/3/9/fast-rake-task-completion-for-zsh/
_rake_refresh () {
if [ -f .rake_tasks ]; then
rm .rake_tasks
fi
echo "Generating .rake_tasks..." > /dev/stderr
_rake_generate
cat .rake_tasks
}
_rake_does_task_list_need_generating () {
if [ ! -f .rake_tasks ]; then return 0;
else
accurate=$(stat -f%m .rake_tasks)
changed=$(stat -f%m Rakefile)
return $(expr $accurate '>=' $changed)
fi
}
_rake_generate () {
rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
}
_rake () {
if [ -f Rakefile ]; then
if _rake_does_task_list_need_generating; then
echo "\nGenerating .rake_tasks..." > /dev/stderr
_rake_generate
fi
compadd `cat .rake_tasks`
fi
}
compdef _rake rake
alias rake_refresh='_rake_refresh'

View file

@ -10,9 +10,6 @@ FOUND_RBENV=0
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv") rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv")
if _homebrew-installed && _rbenv-from-homebrew-installed ; then if _homebrew-installed && _rbenv-from-homebrew-installed ; then
rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}") rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}")
if [[ $RBENV_ROOT = '' ]]; then
RBENV_ROOT="$HOME/.rbenv"
fi
fi fi
for rbenvdir in "${rbenvdirs[@]}" ; do for rbenvdir in "${rbenvdirs[@]}" ; do

122
plugins/scd/README.md Normal file
View file

@ -0,0 +1,122 @@
# scd - smart change of directory
Define `scd` shell function for changing to any directory with
a few keystrokes.
`scd` keeps history of the visited directories, which serves as an index of
the known paths. The directory index is updated after every `cd` command in
the shell and can be also filled manually by running `scd -a`. To switch to
some directory, `scd` needs few fragments of the desired path to match with
the index. A selection menu is displayed in case of several matches, with a
preference given to recently visited paths. `scd` can create permanent
directory aliases, which appear as named directories in zsh session.
## INSTALLATION
For oh-my-zsh, add `scd` to the `plugins` array in the ~/.zshrc file as in the
[template file](../../templates/zshrc.zsh-template#L45).
Besides zsh, `scd` can be used with *bash*, *dash* or *tcsh*
shells and is also available as [Vim](http://www.vim.org/) plugin and
[IPython](http://ipython.org/) extension. For installation details, see
https://github.com/pavoljuhas/smart-change-directory.
## SYNOPSIS
```sh
scd [options] [pattern1 pattern2 ...]
```
## OPTIONS
<dl><dt>
-a, --add</dt><dd>
add specified directories to the directory index.</dd><dt>
--unindex</dt><dd>
remove specified directories from the index.</dd><dt>
-r, --recursive</dt><dd>
apply options <em>--add</em> or <em>--unindex</em> recursively.</dd><dt>
--alias=ALIAS</dt><dd>
create alias for the current or specified directory and save it to
<em>~/.scdalias.zsh</em>.</dd><dt>
--unalias</dt><dd>
remove ALIAS definition for the current or specified directory from
<em>~/.scdalias.zsh</em>.</dd><dt>
--list</dt><dd>
show matching directories and exit.</dd><dt>
-v, --verbose</dt><dd>
display directory rank in the selection menu.</dd><dt>
-h, --help</dt><dd>
display this options summary and exit.</dd>
</dl>
## Examples
```sh
# Index recursively some paths for the very first run
scd -ar ~/Documents/
# Change to a directory path matching "doc"
scd doc
# Change to a path matching all of "a", "b" and "c"
scd a b c
# Change to a directory path that ends with "ts"
scd "ts(#e)"
# Show selection menu and ranking of 20 most likely directories
scd -v
# Alias current directory as "xray"
scd --alias=xray
# Jump to a previously defined aliased directory
scd xray
```
# FILES
<dl><dt>
~/.scdhistory</dt><dd>
time-stamped index of visited directories.</dd><dt>
~/.scdalias.zsh</dt><dd>
scd-generated definitions of directory aliases.</dd>
</dl>
# ENVIRONMENT
<dl><dt>
SCD_HISTFILE</dt><dd>
path to the scd index file (by default ~/.scdhistory).</dd><dt>
SCD_HISTSIZE</dt><dd>
maximum number of entries in the index (5000). Index is trimmed when it
exceeds <em>SCD_HISTSIZE</em> by more than 20%.</dd><dt>
SCD_MENUSIZE</dt><dd>
maximum number of items for directory selection menu (20).</dd><dt>
SCD_MEANLIFE</dt><dd>
mean lifetime in seconds for exponential decay of directory
likelihood (86400).</dd><dt>
SCD_THRESHOLD</dt><dd>
threshold for cumulative directory likelihood. Directories with
a lower likelihood compared to the best match are excluded (0.005).
</dd><dt>
SCD_SCRIPT</dt><dd>
command script file where scd writes the final <code>cd</code>
command. This variable must be defined when scd runs in its own
process rather than as a shell function. It is up to the
scd caller to use the output in <em>SCD_SCRIPT</em>.</dd>
</dl>

353
plugins/scd/scd Executable file
View file

@ -0,0 +1,353 @@
#!/bin/zsh -f
emulate -L zsh
local EXIT=return
if [[ $(whence -w $0) == *:' 'command ]]; then
emulate -R zsh
local RUNNING_AS_COMMAND=1
EXIT=exit
fi
local DOC='scd -- smart change to a recently used directory
usage: scd [options] [pattern1 pattern2 ...]
Go to a directory path that contains all fixed string patterns. Prefer
recently visited directories and directories with patterns in their tail
component. Display a selection menu in case of multiple matches.
Options:
-a, --add add specified directories to the directory index
--unindex remove specified directories from the index
-r, --recursive apply options --add or --unindex recursively
--alias=ALIAS create alias for the current or specified directory and
store it in ~/.scdalias.zsh
--unalias remove ALIAS definition for the current or specified
directory from ~/.scdalias.zsh
--list show matching directories and exit
-v, --verbose display directory rank in the selection menu
-h, --help display this message and exit
'
local SCD_HISTFILE=${SCD_HISTFILE:-${HOME}/.scdhistory}
local SCD_HISTSIZE=${SCD_HISTSIZE:-5000}
local SCD_MENUSIZE=${SCD_MENUSIZE:-20}
local SCD_MEANLIFE=${SCD_MEANLIFE:-86400}
local SCD_THRESHOLD=${SCD_THRESHOLD:-0.005}
local SCD_SCRIPT=${RUNNING_AS_COMMAND:+$SCD_SCRIPT}
local SCD_ALIAS=~/.scdalias.zsh
local ICASE a d m p i tdir maxrank threshold
local opt_help opt_add opt_unindex opt_recursive opt_verbose
local opt_alias opt_unalias opt_list
local -A drank dalias
local dmatching
local last_directory
setopt extendedhistory extendedglob noautonamedirs brace_ccl
# If SCD_SCRIPT is defined make sure the file exists and is empty.
# This removes any previous old commands.
[[ -n "$SCD_SCRIPT" ]] && [[ -s $SCD_SCRIPT || ! -f $SCD_SCRIPT ]] && (
umask 077
: >| $SCD_SCRIPT
)
# process command line options
zmodload -i zsh/zutil
zmodload -i zsh/datetime
zparseopts -D -- a=opt_add -add=opt_add -unindex=opt_unindex \
r=opt_recursive -recursive=opt_recursive \
-alias:=opt_alias -unalias=opt_unalias -list=opt_list \
v=opt_verbose -verbose=opt_verbose h=opt_help -help=opt_help \
|| $EXIT $?
if [[ -n $opt_help ]]; then
print $DOC
$EXIT
fi
# load directory aliases if they exist
[[ -r $SCD_ALIAS ]] && source $SCD_ALIAS
# works faster than the (:a) modifier and is compatible with zsh 4.2.6
_scd_Y19oug_abspath() {
set -A $1 ${(ps:\0:)"$(
unfunction -m "*"; shift
for d; do
cd $d && print -Nr -- $PWD && cd $OLDPWD
done
)"}
}
# define directory alias
if [[ -n $opt_alias ]]; then
if [[ -n $1 && ! -d $1 ]]; then
print -u2 "'$1' is not a directory."
$EXIT 1
fi
a=${opt_alias[-1]#=}
_scd_Y19oug_abspath d ${1:-$PWD}
# alias in the current shell, update alias file if successful
hash -d -- $a=$d &&
(
umask 077
hash -dr
[[ -r $SCD_ALIAS ]] && source $SCD_ALIAS
hash -d -- $a=$d
hash -dL >| $SCD_ALIAS
)
$EXIT $?
fi
# undefine directory alias
if [[ -n $opt_unalias ]]; then
if [[ -n $1 && ! -d $1 ]]; then
print -u2 "'$1' is not a directory."
$EXIT 1
fi
_scd_Y19oug_abspath a ${1:-$PWD}
a=$(print -rD ${a})
if [[ $a != [~][^/]## ]]; then
$EXIT
fi
a=${a#[~]}
# unalias in the current shell, update alias file if successful
if unhash -d -- $a 2>/dev/null && [[ -r $SCD_ALIAS ]]; then
(
umask 077
hash -dr
source $SCD_ALIAS
unhash -d -- $a 2>/dev/null &&
hash -dL >| $SCD_ALIAS
)
fi
$EXIT $?
fi
# Rewrite directory index if it is at least 20% oversized
if [[ -s $SCD_HISTFILE ]] && \
(( $(wc -l <$SCD_HISTFILE) > 1.2 * $SCD_HISTSIZE )); then
m=( ${(f)"$(<$SCD_HISTFILE)"} )
print -lr -- ${m[-$SCD_HISTSIZE,-1]} >| ${SCD_HISTFILE}
fi
# Determine the last recorded directory
if [[ -s ${SCD_HISTFILE} ]]; then
last_directory=${"$(tail -1 ${SCD_HISTFILE})"#*;}
fi
# Internal functions are prefixed with "_scd_Y19oug_".
# The "record" function adds its arguments to the directory index.
_scd_Y19oug_record() {
while [[ -n $last_directory && $1 == $last_directory ]]; do
shift
done
if [[ $# -gt 0 ]]; then
( umask 077
p=": ${EPOCHSECONDS}:0;"
print -lr -- ${p}${^*} >>| $SCD_HISTFILE )
fi
}
if [[ -n $opt_add ]]; then
for d; do
if [[ ! -d $d ]]; then
print -u2 "Directory '$d' does not exist."
$EXIT 2
fi
done
_scd_Y19oug_abspath m ${*:-$PWD}
_scd_Y19oug_record $m
if [[ -n $opt_recursive ]]; then
for d in $m; do
print -n "scanning ${d} ... "
_scd_Y19oug_record ${d}/**/*(-/N)
print "[done]"
done
fi
$EXIT
fi
# take care of removing entries from the directory index
if [[ -n $opt_unindex ]]; then
if [[ ! -s $SCD_HISTFILE ]]; then
$EXIT
fi
# expand existing directories in the argument list
for i in {1..$#}; do
if [[ -d ${argv[i]} ]]; then
_scd_Y19oug_abspath d ${argv[i]}
argv[i]=${d}
fi
done
m="$(awk -v recursive=${opt_recursive} '
BEGIN {
for (i = 2; i < ARGC; ++i) {
argset[ARGV[i]] = 1;
delete ARGV[i];
}
}
1 {
d = $0; sub(/^[^;]*;/, "", d);
if (d in argset) next;
}
recursive {
for (a in argset) {
if (substr(d, 1, length(a) + 1) == a"/") next;
}
}
{ print $0 }
' $SCD_HISTFILE ${*:-$PWD} )" || $EXIT $?
: >| ${SCD_HISTFILE}
[[ ${#m} == 0 ]] || print -r -- $m >> ${SCD_HISTFILE}
$EXIT
fi
# The "action" function is called when there is just one target directory.
_scd_Y19oug_action() {
cd $1 || return $?
if [[ -z $SCD_SCRIPT && -n $RUNNING_AS_COMMAND ]]; then
print -u2 "Warning: running as command with SCD_SCRIPT undefined."
fi
if [[ -n $SCD_SCRIPT ]]; then
print -r "cd ${(q)1}" >| $SCD_SCRIPT
fi
}
# Match and rank patterns to the index file
# set global arrays dmatching and drank
_scd_Y19oug_match() {
## single argument that is an existing directory or directory alias
if [[ $# == 1 ]] && \
[[ -d ${d::=$1} || -d ${d::=${nameddirs[$1]}} ]] && [[ -x $d ]];
then
_scd_Y19oug_abspath dmatching $d
drank[${dmatching[1]}]=1
return
fi
# ignore case unless there is an argument with an uppercase letter
[[ "$*" == *[[:upper:]]* ]] || ICASE='(#i)'
# calculate rank of all directories in the SCD_HISTFILE and keep it as drank
# include a dummy entry for splitting of an empty string is buggy
[[ -s $SCD_HISTFILE ]] && drank=( ${(f)"$(
print -l /dev/null -10
<$SCD_HISTFILE \
awk -v epochseconds=$EPOCHSECONDS -v meanlife=$SCD_MEANLIFE '
BEGIN { FS = "[:;]"; }
length($0) < 4096 && $2 > 0 {
tau = 1.0 * ($2 - epochseconds) / meanlife;
if (tau < -4.61) tau = -4.61;
prec = exp(tau);
sub(/^[^;]*;/, "");
if (NF) ptot[$0] += prec;
}
END { for (di in ptot) { print di; print ptot[di]; } }'
)"}
)
unset "drank[/dev/null]"
# filter drank to the entries that match all arguments
for a; do
p=${ICASE}"*${a}*"
drank=( ${(kv)drank[(I)${~p}]} )
done
# build a list of matching directories reverse-sorted by their probabilities
dmatching=( ${(f)"$(
for d p in ${(kv)drank}; do
print -r -- "$p $d";
done | sort -grk1 | cut -d ' ' -f 2-
)"}
)
# if some directory paths match all patterns in order, discard all others
p=${ICASE}"*${(j:*:)argv}*"
m=( ${(M)dmatching:#${~p}} )
[[ -d ${m[1]} ]] && dmatching=( $m )
# if some directory names match last pattern, discard all others
p=${ICASE}"*${(j:*:)argv}[^/]#"
m=( ${(M)dmatching:#${~p}} )
[[ -d ${m[1]} ]] && dmatching=( $m )
# if some directory names match all patterns, discard all others
m=( $dmatching )
for a; do
p=${ICASE}"*/[^/]#${a}[^/]#"
m=( ${(M)m:#${~p}} )
done
[[ -d ${m[1]} ]] && dmatching=( $m )
# if some directory names match all patterns in order, discard all others
p=${ICASE}"/*${(j:[^/]#:)argv}[^/]#"
m=( ${(M)dmatching:#${~p}} )
[[ -d ${m[1]} ]] && dmatching=( $m )
# do not match $HOME or $PWD when run without arguments
if [[ $# == 0 ]]; then
dmatching=( ${dmatching:#(${HOME}|${PWD})} )
fi
# keep at most SCD_MENUSIZE of matching and valid directories
m=( )
for d in $dmatching; do
[[ ${#m} == $SCD_MENUSIZE ]] && break
[[ -d $d && -x $d ]] && m+=$d
done
dmatching=( $m )
# find the maximum rank
maxrank=0.0
for d in $dmatching; do
[[ ${drank[$d]} -lt maxrank ]] || maxrank=${drank[$d]}
done
# discard all directories below the rank threshold
threshold=$(( maxrank * SCD_THRESHOLD ))
dmatching=( ${^dmatching}(Ne:'(( ${drank[$REPLY]} >= threshold ))':) )
}
_scd_Y19oug_match $*
## process whatever directories that remained
if [[ ${#dmatching} == 0 ]]; then
print -u2 "No matching directory."
$EXIT 1
fi
## build formatted directory aliases for selection menu or list display
for d in $dmatching; do
if [[ -n ${opt_verbose} ]]; then
dalias[$d]=$(printf "%.3g %s" ${drank[$d]} $d)
else
dalias[$d]=$(print -Dr -- $d)
fi
done
## process the --list option
if [[ -n $opt_list ]]; then
for d in $dmatching; do
print -r -- "# ${dalias[$d]}"
print -r -- $d
done
$EXIT
fi
## process single directory match
if [[ ${#dmatching} == 1 ]]; then
_scd_Y19oug_action $dmatching
$EXIT $?
fi
## here we have multiple matches - display selection menu
a=( {a-z} {A-Z} )
p=( )
for i in {1..${#dmatching}}; do
[[ -n ${a[i]} ]] || break
p+="${a[i]}) ${dalias[${dmatching[i]}]}"
done
print -c -r -- $p
if read -s -k 1 d && [[ ${i::=${a[(I)$d]}} -gt 0 ]]; then
_scd_Y19oug_action ${dmatching[i]}
$EXIT $?
fi

View file

@ -0,0 +1,19 @@
## The scd script should autoload as a shell function.
autoload scd
## If the scd function exists, define a change-directory-hook function
## to record visited directories in the scd index.
if [[ ${+functions[scd]} == 1 ]]; then
scd_chpwd_hook() { scd --add $PWD }
autoload add-zsh-hook
add-zsh-hook chpwd scd_chpwd_hook
fi
## Allow scd usage with unquoted wildcard characters such as "*" or "?".
alias scd='noglob scd'
## Load the directory aliases created by scd if any.
if [[ -s ~/.scdalias.zsh ]]; then source ~/.scdalias.zsh; fi

View file

@ -44,7 +44,7 @@ __task_list ()
__box_list () __box_list ()
{ {
_wanted application expl 'command' compadd $(command ls -1 $HOME/.vagrant/boxes 2>/dev/null| sed -e 's/ /\\ /g') _wanted application expl 'command' compadd $(command vagrant box list | sed -e 's/ /\\ /g')
} }
__vm_list () __vm_list ()

View file

@ -17,9 +17,15 @@ function zle-keymap-select zle-line-init zle-line-finish {
zle -N zle-line-init zle -N zle-line-init
zle -N zle-line-finish zle -N zle-line-finish
zle -N zle-keymap-select zle -N zle-keymap-select
zle -N edit-command-line
bindkey -v bindkey -v
# allow v to edit the command line (standard behaviour)
autoload -Uz edit-command-line
bindkey -M vicmd 'v' edit-command-line
# if mode indicator wasn't setup by theme, define default # if mode indicator wasn't setup by theme, define default
if [[ "$MODE_INDICATOR" == "" ]]; then if [[ "$MODE_INDICATOR" == "" ]]; then
MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}" MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"

View file

@ -0,0 +1,82 @@
# Vim Interaction #
The plugin presents a function called `callvim` whose usage is:
usage: callvim [-b cmd] [-a cmd] [file ... fileN]
-b cmd Run this command in GVIM before editing the first file
-a cmd Run this command in GVIM after editing the first file
file The file to edit
... fileN The other files to add to the argslist
## Rationale ##
The idea for this script is to give you some decent interaction with a running
GVim session. Normally you'll be running around your filesystem doing any
number of amazing things and you'll need to load some files into GVim for
editing, inspecting, destruction, or other bits of mayhem. This script lets you
do that.
## Aliases ##
There are a few aliases presented as well:
* `v` A shorthand for `callvim`
* `vvsp` Edits the passed in file but first makes a vertical split
* `vhsp` Edits the passed in file but first makes a horizontal split
## Post Callout ##
At the end of the `callvim` function we invoke the `postCallVim` function if it
exists. If you're using MacVim, for example, you could define a function that
brings window focus to it after the file is loaded:
function postCallVim
{
osascript -e 'tell application "MacVim" to activate'
}
This'll be different depending on your OS / Window Manager.
## Examples ##
This will load `/tmp/myfile.scala` into the running GVim session:
> v /tmp/myfile.scala
This will load it after first doing a vertical split:
> vvsp /tmp/myfile.scala
or
> v -b':vsp' /tmp/myfile.scala
This will load it after doing a horizontal split, then moving to the bottom of
the file:
> vhsp -aG /tmp/myfile.scala
or
> v -b':sp' -aG /tmp/myfile.scala
This will load the file and then copy the first line to the end (Why you would
ever want to do this... I dunno):
> v -a':1t$' /tmp/myfile.scala
And this will load all of the `*.txt` files into the args list:
> v *.txt
If you want to load files into areas that are already split, use one of the
aliases for that:
# Do a ':wincmd h' first
> vh /tmp/myfile.scala
# Do a ':wincmd j' first
> vj /tmp/myfile.scala
# Do a ':wincmd k' first
> vk /tmp/myfile.scala
# Do a ':wincmd l' first
> vl /tmp/myfile.scala

View file

@ -0,0 +1,72 @@
#
# See README.md
#
# Derek Wyatt (derek@{myfirstnamemylastname}.org
#
function resolveFile
{
if [ -f "$1" ]; then
echo $(readlink -f "$1")
elif [[ "${1#/}" == "$1" ]]; then
echo "$(pwd)/$1"
else
echo $1
fi
}
function callvim
{
if [[ $# == 0 ]]; then
cat <<EOH
usage: callvim [-b cmd] [-a cmd] [file ... fileN]
-b cmd Run this command in GVIM before editing the first file
-a cmd Run this command in GVIM after editing the first file
file The file to edit
... fileN The other files to add to the argslist
EOH
return 0
fi
local cmd=""
local before="<esc>"
local after=""
while getopts ":b:a:" option
do
case $option in
a) after="$OPTARG"
;;
b) before="$OPTARG"
;;
esac
done
shift $((OPTIND-1))
if [[ ${after#:} != $after && ${after%<cr>} == $after ]]; then
after="$after<cr>"
fi
if [[ ${before#:} != $before && ${before%<cr>} == $before ]]; then
before="$before<cr>"
fi
local files=""
for f in $@
do
files="$files $(resolveFile $f)"
done
if [[ -n $files ]]; then
files=':args! '"$files<cr>"
fi
cmd="$before$files$after"
gvim --remote-send "$cmd"
if typeset -f postCallVim > /dev/null; then
postCallVim
fi
}
alias v=callvim
alias vvsp="callvim -b':vsp'"
alias vhsp="callvim -b':sp'"
alias vk="callvim -b':wincmd k'"
alias vj="callvim -b':wincmd j'"
alias vl="callvim -b':wincmd l'"
alias vh="callvim -b':wincmd h'"

View file

@ -1,4 +1,4 @@
virtualenvwrapper='virtualenvwrapper_lazy.sh' virtualenvwrapper='virtualenvwrapper.sh'
if (( $+commands[$virtualenvwrapper] )); then if (( $+commands[$virtualenvwrapper] )); then
source ${${virtualenvwrapper}:c} source ${${virtualenvwrapper}:c}

View file

@ -0,0 +1,13 @@
zsh_cache=$HOME/.zsh_cache
mkdir -p $zsh_cache
# reload zshrc
function src()
{
autoload -U compinit zrecompile
compinit -d $zsh_cache/zcomp-$HOST
for f in $HOME/.zshrc $zsh_cache/zcomp-$HOST; do
zrecompile -p $f && rm -f $f.zwc.old
done
source ~/.zshrc
}

View file

@ -1,5 +1,5 @@
# Path to your oh-my-zsh configuration. # Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load. # Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/ # Look in ~/.oh-my-zsh/themes/

View file

@ -18,7 +18,7 @@ else
if which rbenv &> /dev/null; then if which rbenv &> /dev/null; then
RPS1='$(git_custom_status)%{$fg[red]%}[`rbenv version | sed -e "s/ (set.*$//"`]%{$reset_color%} $EPS1' RPS1='$(git_custom_status)%{$fg[red]%}[`rbenv version | sed -e "s/ (set.*$//"`]%{$reset_color%} $EPS1'
else else
if which chruby_prompt_info &> /dev/null; then if [[ -n `which chruby_prompt_info` && -n `chruby_prompt_info` ]]; then
RPS1='$(git_custom_status)%{$fg[red]%}[`chruby_prompt_info`]%{$reset_color%} $EPS1' RPS1='$(git_custom_status)%{$fg[red]%}[`chruby_prompt_info`]%{$reset_color%} $EPS1'
else else
RPS1='$(git_custom_status) $EPS1' RPS1='$(git_custom_status) $EPS1'

View file

@ -6,7 +6,7 @@ autoload -U colors zsh/terminfo # Used in the colour alias below
colors colors
setopt prompt_subst setopt prompt_subst
# make some aliases for the colours: (coud use normal escap.seq's too) # make some aliases for the colours: (could use normal escape sequences too)
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$fg[${(L)color}]%}' eval PR_$color='%{$fg[${(L)color}]%}'
done done
@ -36,13 +36,13 @@ local return_code="%(?..%{$PR_RED%}%? ↵%{$PR_NO_COLOR%})"
local user_host='${PR_USER}${PR_CYAN}@${PR_HOST}' local user_host='${PR_USER}${PR_CYAN}@${PR_HOST}'
local current_dir='%{$PR_BOLD$PR_BLUE%}%~%{$PR_NO_COLOR%}' local current_dir='%{$PR_BOLD$PR_BLUE%}%~%{$PR_NO_COLOR%}'
local rvm_ruby='' local rvm_ruby=''
if which rvm-prompt &> /dev/null; then if ${HOME}/.rvm/bin/rvm-prompt &> /dev/null; then # detect local user rvm installation
rvm_ruby='%{$PR_RED%}$(${HOME}/.rvm/bin/rvm-prompt i v g s)%{$PR_NO_COLOR%}'
elif which rvm-prompt &> /dev/null; then # detect sysem-wide rvm installation
rvm_ruby='%{$PR_RED%}$(rvm-prompt i v g s)%{$PR_NO_COLOR%}' rvm_ruby='%{$PR_RED%}$(rvm-prompt i v g s)%{$PR_NO_COLOR%}'
else elif which rbenv &> /dev/null; then # detect Simple Ruby Version management
if which rbenv &> /dev/null; then
rvm_ruby='%{$PR_RED%}$(rbenv version | sed -e "s/ (set.*$//")%{$PR_NO_COLOR%}' rvm_ruby='%{$PR_RED%}$(rbenv version | sed -e "s/ (set.*$//")%{$PR_NO_COLOR%}'
fi fi
fi
local git_branch='$(git_prompt_info)%{$PR_NO_COLOR%}' local git_branch='$(git_prompt_info)%{$PR_NO_COLOR%}'
#PROMPT="${user_host} ${current_dir} ${rvm_ruby} ${git_branch}$PR_PROMPT " #PROMPT="${user_host} ${current_dir} ${rvm_ruby} ${git_branch}$PR_PROMPT "