Moved hub into the git plugin.

This commit is contained in:
Sorin Ionescu 2011-10-11 23:13:58 -04:00
parent 62fc8d802e
commit 60f39d8d91
55 changed files with 531 additions and 528 deletions

View file

@ -4,29 +4,29 @@ A handful of functions, auto-complete helpers, and stuff that makes you shout...
## Setup
`oh-my-zsh` should work with any recent release of [ZSH](http://www.zsh.org), but the
`oh-my-zsh` should work with any recent release of [Zsh](http://www.zsh.org), but the
minimum recommended version is 4.3.9.
1. Clone the repository.
`git clone git://github.com/sorin-ionescu/oh-my-zsh.git ~/.oh-my-zsh`
2. Create a new ZSH configuration by copying the ZSH template provided.
2. Create a new Zsh configuration by copying the Zsh template provided.
**NOTE**: If you already have a `~/.zshrc` file, you should back it up with `cp
~/.zshrc{,.orig}` in case you want to go back to your original settings.
cp ~/.oh-my-zsh/templates/zshrc.template.zsh ~/.zshrc
3. Set ZSH as your default shell:
3. Set Zsh as your default shell:
`chsh -s /bin/zsh`
4. Start / restart ZSH by opening a new terminal window or tab.
4. Start / restart Zsh by opening a new terminal window or tab.
### Problems?
If you are not able to find certain commands after switching to *Oh My ZSH*, you need
If you are not able to find certain commands after switching to *Oh My Zsh*, you need
to modify `PATH` in `~/.zshrc`, or better yet, in `~/functions/02.environment.zsh`
(may be subject to merge conflicts).
@ -42,7 +42,7 @@ to modify `PATH` in `~/.zshrc`, or better yet, in `~/functions/02.environment.zs
## Useful
The [ZSH Reference Card](http://www.bash2zsh.com/zsh_refcard/refcard.pdf) is tasty.
The [Zsh Reference Card](http://www.bash2zsh.com/zsh_refcard/refcard.pdf) is tasty.
### Customization
@ -51,7 +51,7 @@ If you have many related functions, you can organise them in a file in the
## Help out!
I am not a ZSH expert and suspect that there are improvements to be made. If you have
I am not a Zsh expert and suspect that there are improvements to be made. If you have
ideas on how to make the configuration easier to maintain or improve the performance,
do not hesitate to fork and send pull requests!

13
functions/duh Normal file
View file

@ -0,0 +1,13 @@
# Displays human readable disk usage statistics.
function duh() {
(( $# == 0 )) && set -- *
if [[ "$OSTYPE" == linux* ]]; then
du -khsc "$@" | sort -h -r
else
du -kcs "$@" | awk '{ printf "%9.1fM %s\n", $1 / 1024, $2 } ' | sort -n -r
fi
}
compdef _du duh
duh "$@"

7
functions/reload Normal file
View file

@ -0,0 +1,7 @@
# Reloads ~/.zshrc.
local zshrc="$HOME/.zshrc"
if [[ -n "$1" ]]; then
zshrc="$1"
fi
source "$zshrc"

View file

@ -9,7 +9,7 @@ function check-bool {
}
# Trap signals were generated with 'kill -l'.
# DEBUG, EXIT, and ZERR are ZSH signals.
# DEBUG, EXIT, and ZERR are Zsh signals.
TRAP_SIGNALS=(
ABRT ALRM BUS CHLD CONT EMT FPE HUP ILL INFO INT IO KILL PIPE PROF QUIT
SEGV STOP SYS TERM TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ
@ -19,12 +19,12 @@ TRAP_SIGNALS=(
# Adds a function to a list to be called when a trap is triggered.
function add-zsh-trap {
if (( $# < 2 )); then
echo "Usage: $0 type function"
print "Usage: $0 type function"
return 1
fi
if [[ -z "$TRAP_SIGNALS[(r)$1]" ]]; then
echo "$0: unknown signal: $1"
print "$0: unknown signal: $1"
return 1
fi

View file

@ -1,4 +1,11 @@
# Initializes OH MY ZSH.
# Initializes Oh My Zsh.
# Check for the minimum supported version.
min_zsh_version=4.3.9
if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then
print "oh-my-zsh: The minimum supported Zsh version is $min_zsh_version."
fi
unset min_zsh_version
# Disable color in dumb terminals.
if [[ "$TERM" == 'dumb' ]]; then
@ -7,10 +14,9 @@ fi
# Add functions to fpath.
fpath=(
${0:h}/themes/*(/N)
${plugins:+${0:h}/plugins/${^plugins}}
${0:h}/functions
${0:h}/completions
${0:h}/themes/*(/FN)
${plugins:+${0:h}/plugins/${^plugins}/{functions,completions}(/FN)}
${0:h}/{functions,completions}(/FN)
$fpath
)
@ -29,14 +35,28 @@ source "${0:h}/alias.zsh"
source "${0:h}/spectrum.zsh"
source "${0:h}/utility.zsh"
# Autoload Zsh function builtins.
autoload -Uz age
autoload -Uz zargs
autoload -Uz zcalc
autoload -Uz zmv
# Source plugins defined in ~/.zshrc.
for plugin in $plugins; do
for plugin in "$plugins[@]"; do
if [[ -f "${0:h}/plugins/$plugin/init.zsh" ]]; then
source "${0:h}/plugins/$plugin/init.zsh"
fi
done
unset plugin
unset plugins
unset plugin plugins
# Autoload Oh My Zsh functions.
for fdir in "$fpath[@]"; do
if [[ "$fdir" == ${0:h}/(|*/)functions ]]; then
for afunction in $fdir/[^_.]*(N.:t); do
autoload -Uz $afunction
done
fi
done
# Set environment variables for launchd processes.
if [[ "$OSTYPE" == darwin* ]]; then

View file

@ -82,7 +82,7 @@ if [[ "$KEYMAP" == (emacs|) ]]; then
fi
# Bind to history substring search plugin if enabled;
# otherwise, bind to built-in ZSH history search.
# otherwise, bind to built-in Zsh history search.
if (( $+widgets[history-incremental-pattern-search-backward] )); then
bindkey "$keyinfo[Control]r" history-incremental-pattern-search-backward
bindkey "$keyinfo[Control]s" history-incremental-pattern-search-forward
@ -169,7 +169,7 @@ elif [[ "$KEYMAP" == 'vi' ]]; then
bindkey -M vicmd "G" end-of-history
# Bind to history substring search plugin if enabled;
# otherwise, bind to built-in ZSH history search.
# otherwise, bind to built-in Zsh history search.
if (( $+plugins[(er)history-substring-search] )); then
bindkey -M vicmd "k" history-substring-search-up
bindkey -M vicmd "j" history-substring-search-down
@ -194,7 +194,7 @@ elif [[ "$KEYMAP" == 'vi' ]]; then
bindkey -M viins "$keyinfo[Control]s" history-incremental-search-forward
fi
else
echo "oh-my-zsh: KEYMAP must be set 'emacs' or 'vi' but is set to '$KEYMAP'" >&2
print "oh-my-zsh: KEYMAP must be set 'emacs' or 'vi' but is set to '$KEYMAP'" >&2
return 1
fi

View file

@ -0,0 +1,68 @@
local remove_archive
local success
local file_name
local extract_dir
if (( $# == 0 )); then
print "Usage: extract [-option] [file ...]"
print
print "Options:"
print " -r, --remove Remove archive."
print
print "Report bugs to <sorin.ionescu@gmail.com>."
fi
remove_archive=1
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
remove_archive=0
shift
fi
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
print "extract: '$1' is not a valid file" 1>&2
shift
continue
fi
success=0
file_name="${1:t}"
extract_dir="${file_name:r}"
case "$1" in
(*.tar.gz|*.tgz) tar xvzf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
(*.tar.xz|*.txz) tar --xz --help &> /dev/null \
&& tar --xz -xvf "$1" \
|| xzcat "$1" | tar xvf - ;;
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
&& tar --lzma -xvf "$1" \
|| lzcat "$1" | tar xvf - ;;
(*.tar) tar xvf "$1" ;;
(*.gz) gunzip "$1" ;;
(*.bz2) bunzip2 "$1" ;;
(*.xz) unxz "$1" ;;
(*.lzma) unlzma "$1" ;;
(*.Z) uncompress "$1" ;;
(*.zip) unzip "$1" -d $extract_dir ;;
(*.rar) unrar e -ad "$1" ;;
(*.7z) 7za x "$1" ;;
(*.deb)
mkdir -p "$extract_dir/control"
mkdir -p "$extract_dir/data"
cd "$extract_dir"; ar vx "../${1}" > /dev/null
cd control; tar xzvf ../control.tar.gz
cd ../data; tar xzvf ../data.tar.gz
cd ..; rm *.tar.gz debian-binary
cd ..
;;
(*)
print "extract: '$1' cannot be extracted" 1>&2
success=1
;;
esac
(( success = $success > 0 ? $success : $? ))
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
shift
done

View file

@ -0,0 +1,45 @@
local verbose
if (( $# == 0 )); then
print "Usage: extract [-option] [file ...]"
print
print "Options:"
print " -v, --verbose Verbose archive listing."
print
print "Report bugs to <sorin.ionescu@gmail.com>."
fi
if [[ "$1" == "-v" ]] || [[ "$1" == "--verbose" ]]; then
verbose=0
shift
fi
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
print "extract: '$1' is not a valid file" 1>&2
shift
continue
fi
case "$1" in
(*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;;
(*.tar.xz|*.txz) tar --xz --help &> /dev/null \
&& tar --xz -t${verbose:+v}f "$1" \
|| xzcat "$1" | tar t${verbose:+v}f - ;;
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
&& tar --lzma -t${verbose:+v}f "$1" \
|| lzcat "$1" | tar x${verbose:+v}f - ;;
(*.tar) tar t${verbose:+v}f "$1" ;;
(*.zip) unzip -l${verbose:+v} "$1" ;;
(*.rar) unrar ${${verbose:+v}:-l} "$1" ;;
(*.7z) 7za l "$1" ;;
(*)
print "ls-archive: '$1' cannot be listed" 1>&2
success=1
;;
esac
shift
done

View file

@ -1,125 +0,0 @@
# ------------------------------------------------------------------------------
# FILE: extract.plugin.zsh
# DESCRIPTION: oh-my-zsh plugin file.
# AUTHOR: Sorin Ionescu <sorin.ionescu@gmail.com>
# VERSION: 1.0.2
# ------------------------------------------------------------------------------
function extract() {
local remove_archive
local success
local file_name
local extract_dir
if (( $# == 0 )); then
echo "Usage: extract [-option] [file ...]"
echo
echo "Options:"
echo " -r, --remove Remove archive."
echo
echo "Report bugs to <sorin.ionescu@gmail.com>."
fi
remove_archive=1
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
remove_archive=0
shift
fi
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
echo "extract: '$1' is not a valid file" 1>&2
shift
continue
fi
success=0
file_name="$( basename "$1" )"
extract_dir="$( echo "$file_name" | sed "s/\.${1##*.}//g" )"
case "$1" in
(*.tar.gz|*.tgz) tar xvzf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
(*.tar.xz|*.txz) tar --xz --help &> /dev/null \
&& tar --xz -xvf "$1" \
|| xzcat "$1" | tar xvf - ;;
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
&& tar --lzma -xvf "$1" \
|| lzcat "$1" | tar xvf - ;;
(*.tar) tar xvf "$1" ;;
(*.gz) gunzip "$1" ;;
(*.bz2) bunzip2 "$1" ;;
(*.xz) unxz "$1" ;;
(*.lzma) unlzma "$1" ;;
(*.Z) uncompress "$1" ;;
(*.zip) unzip "$1" -d $extract_dir ;;
(*.rar) unrar e -ad "$1" ;;
(*.7z) 7za x "$1" ;;
(*.deb)
mkdir -p "$extract_dir/control"
mkdir -p "$extract_dir/data"
cd "$extract_dir"; ar vx "../${1}" > /dev/null
cd control; tar xzvf ../control.tar.gz
cd ../data; tar xzvf ../data.tar.gz
cd ..; rm *.tar.gz debian-binary
cd ..
;;
(*)
echo "extract: '$1' cannot be extracted" 1>&2
success=1
;;
esac
(( success = $success > 0 ? $success : $? ))
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
shift
done
}
function ls-archive() {
local verbose
if (( $# == 0 )); then
echo "Usage: extract [-option] [file ...]"
echo
echo "Options:"
echo " -v, --verbose Verbose archive listing."
echo
echo "Report bugs to <sorin.ionescu@gmail.com>."
fi
if [[ "$1" == "-v" ]] || [[ "$1" == "--verbose" ]]; then
verbose=0
shift
fi
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
echo "extract: '$1' is not a valid file" 1>&2
shift
continue
fi
case "$1" in
(*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;;
(*.tar.xz|*.txz) tar --xz --help &> /dev/null \
&& tar --xz -t${verbose:+v}f "$1" \
|| xzcat "$1" | tar t${verbose:+v}f - ;;
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
&& tar --lzma -t${verbose:+v}f "$1" \
|| lzcat "$1" | tar x${verbose:+v}f - ;;
(*.tar) tar t${verbose:+v}f "$1" ;;
(*.zip) unzip -l${verbose:+v} "$1" ;;
(*.rar) unrar ${${verbose:+v}:-l} "$1" ;;
(*.7z) 7za l "$1" ;;
(*)
echo "ls-archive: '$1' cannot be listed" 1>&2
success=1
;;
esac
shift
done
}

View file

@ -6,5 +6,5 @@ alias bl='b list'
alias bo='b open'
alias bp='b package'
alias bu='b update'
alias binit="bi && b package && echo '\nvendor/ruby' >>! .gitignore"
alias binit="bi && b package && print '\nvendor/ruby' >>! .gitignore"

View file

@ -1,4 +1,4 @@
# Uses the command-not-found package ZSH support as seen in
# Uses the command-not-found package Zsh support as seen in
# http://www.porcheron.info/command-not-found-for-zsh/ and
# installed in Ubuntu.

View file

@ -0,0 +1,9 @@
# Create a simple script that can be used to 'duplicate' a system.
print '#!/bin/sh'"\n" > apt-copy.sh
list=$(perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;')
print 'aptitude install '"$list\n" >> apt-copy.sh
chmod +x apt-copy.sh

View file

@ -0,0 +1,10 @@
# Kernel-package building shortcut.
MAKEFLAGS='' # Temporarily unset MAKEFLAGS ( '-j3' will fail ).
appendage='-custom' # This shows up in $ (uname -r ).
revision=$(date +"%Y%m%d") # This shows up in the .deb file name.
make-kpkg clean
time fakeroot make-kpkg --append-to-version "$appendage" --revision \
"$revision" kernel_image kernel_headers

View file

@ -1,5 +1,3 @@
# Debian ZSH Aliases and Functions
# Aliases
alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" --no-gui --disable-columns search" # Search package.
alias ad="sudo apt-get update" # Update packages lists.
@ -22,28 +20,3 @@ alias debc='time dpkg-buildpackage -rfakeroot -us -uc'
# Remove ALL kernel images and headers EXCEPT the one in use.
alias kclean='su -c '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'\'' root'
# Functions
# Create a simple script that can be used to 'duplicate' a system.
function apt-copy() {
print '#!/bin/sh'"\n" > apt-copy.sh
list=$(perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;')
print 'aptitude install '"$list\n" >> apt-copy.sh
chmod +x apt-copy.sh
}
# Kernel-package building shortcut.
function dbb-build() {
MAKEFLAGS='' # Temporarily unset MAKEFLAGS ( '-j3' will fail ).
appendage='-custom' # This shows up in $ (uname -r ).
revision=$(date +"%Y%m%d") # This shows up in the .deb file name.
make-kpkg clean
time fakeroot make-kpkg --append-to-version "$appendage" --revision \
"$revision" kernel_image kernel_headers
}

View file

@ -1,7 +1,13 @@
# Get the latest Git completion.
completion_file="${0:h}/_git"
completion_file="${0:h}/completions/_git"
completion_file_url='http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=blob_plain;f=Completion/Unix/Command/_git;hb=HEAD'
if [[ ! -e "$completion_file" ]] && (( $+commands[git] )); then
# Remove empty completions directory.
if [[ -d "${completion_file:h}"(/^F) ]]; then
rmdir "${completion_file:h}" 2> /dev/null
fi
if mkdir -p "${completion_file:h}" > /dev/null; then
if (( $+commands[curl] )); then
curl -L "$completion_file_url" -o "$completion_file" &> /dev/null &!
fi
@ -10,6 +16,7 @@ if [[ ! -e "$completion_file" ]] && (( $+commands[git] )); then
wget -C "$completion_file_url" -O "$completion_file" &> /dev/null &!
fi
fi
fi
unset completion_file
unset completion_file_url

View file

@ -0,0 +1,9 @@
# Gets the current branch.
local ref="$(git symbolic-ref HEAD 2> /dev/null)"
if [[ -n "$ref" ]]; then
print "${ref#refs/heads/}"
return 0
else
return 1
fi

View file

@ -0,0 +1,22 @@
# Open the GitHub repository in the browser.
local url=$(
git config -l \
| grep "remote.origin.url" \
| sed -En "s/remote.origin.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
)
if [[ -n "$url" ]]; then
url="${url}/tree/${$(git-branch):-master}"
if (( $+commands[$BROWSER] )); then
"$BROWSER" "$url"
return 0
else
print "fatal: Browser not set or set to a non-existent browser." >&2
return 1
fi
else
print "fatal: Not a Git repository or origin remote not set." >&2
return 1
fi

View file

@ -1,22 +1,3 @@
# The default styles.
zstyle ':git-info:' action 'action:%s' # %s - Special action name (am, merge, rebase).
zstyle ':git-info:' added 'added:%a' # %a - Indicator to notify of added files.
zstyle ':git-info:' ahead 'ahead:%A' # %A - Indicator to notify of ahead branch.
zstyle ':git-info:' behind 'behind:%B' # %B - Indicator to notify of behind branch.
zstyle ':git-info:' branch '%b' # %b - Branch name.
zstyle ':git-info:' clean 'clean' # %C - Indicator to notify of clean branch.
zstyle ':git-info:' commit 'commit:%c' # %c - SHA-1 hash.
zstyle ':git-info:' deleted 'deleted:%d' # %d - Indicator to notify of deleted files.
zstyle ':git-info:' dirty 'dirty' # %D - Indicator to notify of dirty branch.
zstyle ':git-info:' modified 'modified:%m' # %m - Indicator to notify of modified files.
zstyle ':git-info:' remote '%R' # %R - Remote name.
zstyle ':git-info:' renamed 'renamed:%r' # %r - Indicator to notify of renamed files.
zstyle ':git-info:' stashed 'stashed:%S' # %S - Indicator to notify of stashed files.
zstyle ':git-info:' unmerged 'unmerged:%U' # %U - Indicator to notify of unmerged files.
zstyle ':git-info:' untracked 'untracked:%u' # %u - Indicator to notify of untracked files.
zstyle ':git-info:' prompt ' git:(%b %D%C)' # Left prompt.
zstyle ':git-info:' rprompt '' # Right prompt.
# Gets the Git special action (am, merge, rebase, etc.).
# Borrowed from vcs_info and edited.
function _git-action() {
@ -36,7 +17,7 @@ function _git-action() {
else
action='am/rebase'
fi
echo "$action"
print "$action"
return 0
fi
done
@ -45,7 +26,7 @@ function _git-action() {
"${git_dir}/rebase-merge/interactive" \
"${git_dir}/.dotest-merge/interactive"; do
if [[ -f "$action_dir" ]]; then
echo 'rebase-i'
print 'rebase-i'
return 0
fi
done
@ -54,23 +35,23 @@ function _git-action() {
"${git_dir}/rebase-merge" \
"${git_dir}/.dotest-merge"; do
if [[ -d "$action_dir" ]]; then
echo 'rebase-m'
print 'rebase-m'
return 0
fi
done
if [[ -f "${git_dir}/MERGE_HEAD" ]]; then
echo 'merge'
print 'merge'
return 0
fi
if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then
echo 'cherry-pick'
print 'cherry-pick'
return 0
fi
if [[ -f "${git_dir}/BISECT_LOG" ]]; then
echo 'bisect'
print 'bisect'
return 0
fi
@ -175,7 +156,7 @@ function git-info() {
elif [[ "$1" == [Oo][Ff][Ff] ]]; then
git config --bool prompt.showinfo false
else
echo "Usage: $0 [ on | off ]"
print "Usage: $0 [ on | off ]"
fi
return 0
fi
@ -355,3 +336,5 @@ function git-info() {
return 0
}
git-info "$@"

View file

@ -0,0 +1,9 @@
# Gets the repository root.
local root="$(git rev-parse --show-toplevel 2> /dev/null)"
if [[ -n "$root" ]]; then
print "$root"
return 0
else
return 1
fi

View file

@ -1,5 +1,3 @@
# Aliases
# Hub by defunkt
# https://github.com/defunkt/hub
if (( $+commands[hub] )); then

View file

@ -6,8 +6,8 @@
# ------------------------------------------------------------------------------
# Source plugin files.
source "${0:h}/utility.zsh"
source "${0:h}/alias.zsh"
source "${0:h}/info.zsh"
source "${0:h}/hub.zsh"
source "${0:h}/style.zsh"
source "${0:h}/completion.zsh"

18
plugins/git/style.zsh Normal file
View file

@ -0,0 +1,18 @@
# The default styles.
zstyle ':git-info:' action 'action:%s' # %s - Special action name (am, merge, rebase).
zstyle ':git-info:' added 'added:%a' # %a - Indicator to notify of added files.
zstyle ':git-info:' ahead 'ahead:%A' # %A - Indicator to notify of ahead branch.
zstyle ':git-info:' behind 'behind:%B' # %B - Indicator to notify of behind branch.
zstyle ':git-info:' branch '%b' # %b - Branch name.
zstyle ':git-info:' clean 'clean' # %C - Indicator to notify of clean branch.
zstyle ':git-info:' commit 'commit:%c' # %c - SHA-1 hash.
zstyle ':git-info:' deleted 'deleted:%d' # %d - Indicator to notify of deleted files.
zstyle ':git-info:' dirty 'dirty' # %D - Indicator to notify of dirty branch.
zstyle ':git-info:' modified 'modified:%m' # %m - Indicator to notify of modified files.
zstyle ':git-info:' remote '%R' # %R - Remote name.
zstyle ':git-info:' renamed 'renamed:%r' # %r - Indicator to notify of renamed files.
zstyle ':git-info:' stashed 'stashed:%S' # %S - Indicator to notify of stashed files.
zstyle ':git-info:' unmerged 'unmerged:%U' # %U - Indicator to notify of unmerged files.
zstyle ':git-info:' untracked 'untracked:%u' # %u - Indicator to notify of untracked files.
zstyle ':git-info:' prompt ' git:(%b %D%C)' # Left prompt.
zstyle ':git-info:' rprompt '' # Right prompt.

View file

@ -1,46 +0,0 @@
# Gets the current branch.
function git-branch() {
local ref="$(git symbolic-ref HEAD 2> /dev/null)"
if [[ -n "$ref" ]]; then
echo "${ref#refs/heads/}"
return 0
else
return 1
fi
}
# Gets the repository root.
function git-root() {
local root="$(git rev-parse --show-toplevel 2> /dev/null)"
if [[ -n "$root" ]]; then
echo "$root"
return 0
else
return 1
fi
}
# Open the GitHub repository in the browser.
function git-hub() {
local url=$(
git config -l \
| grep "remote.origin.url" \
| sed -En "s/remote.origin.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
)
if [[ -n "$url" ]]; then
url="${url}/tree/${$(git-branch):-master}"
if (( $+commands[$BROWSER] )); then
"$BROWSER" "$url"
return 0
else
echo "fatal: Browser not set or set to a non-existent browser." >&2
return 1
fi
else
echo "fatal: Not a Git repository or origin remote not set." >&2
return 1
fi
}

View file

@ -1,4 +1,4 @@
To activate this script, load it into an interactive ZSH session:
To activate this script, load it into an interactive Zsh session:
% source history-substring-search.zsh

View file

@ -147,9 +147,9 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
_zsh_highlight_bind_widgets()
{
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
# Load Zsh module zsh/zleparameter, needed to override user defined widgets.
zmodload zsh/zleparameter 2>/dev/null || {
echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
print 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
return 1
}
@ -176,7 +176,7 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Default: unhandled case.
*) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
*) print "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
esac
done
}
@ -347,7 +347,7 @@ function _history-substring-search-down-buffer() {
function _history-substring-search-up-history() {
#
# Behave like up in ZSH, except clear the $BUFFER
# Behave like up in Zsh, except clear the $BUFFER
# when beginning of history is reached like in Fish.
#
if [[ -z $_history_substring_search_query ]]; then
@ -369,7 +369,7 @@ function _history-substring-search-up-history() {
function _history-substring-search-down-history() {
#
# Behave like down-history in ZSH, except clear the
# Behave like down-history in Zsh, except clear the
# $BUFFER when end of history is reached like in Fish.
#
if [[ -z $_history_substring_search_query ]]; then

View file

@ -3,7 +3,6 @@ alias kate='kate >/dev/null 2>&1' # Silent start.
# Functions
function kt() {
cd "$1"
kate "$1"
cd "$1" && kate .
}

View file

@ -0,0 +1,4 @@
# Open the node api for your current version to the optional section.
# TODO: Make the sections easier to use.
open "http://nodejs.org/docs/$(node --version)/api/all.html#${1}"

View file

@ -9,9 +9,3 @@ else
fi
unset cache_file
# Open the node api for your current version to the optional section.
# TODO: Make the sections easier to use.
function node-docs() {
open "http://nodejs.org/docs/$(node --version)/api/all.html#$1"
}

10
plugins/osx/README.md Normal file
View file

@ -0,0 +1,10 @@
Provides the following commands.
- `tab` create a new tab (works in both _Terminal_ and _iTerm_).
- `pfd` print current _Finder_ directory.
- `pfs` print current _Finder_ selection.
- `cdf` cd to current _Finder_ directory.
- `pushdf` pushd to current _Finder_ directory.
- `ql` quick look at files.
- `manp` Open MAN pages in _Preview.app_.
- `trash` Move files and folders to _Trash_.

View file

@ -1,5 +0,0 @@
#compdef man-preview
#autoload
_man

View file

@ -0,0 +1,6 @@
osascript 2>/dev/null <<EOF
tell application "Finder"
return POSIX path of (target of window 1 as alias)
end tell
EOF

11
plugins/osx/functions/pfs Normal file
View file

@ -0,0 +1,11 @@
osascript 2>/dev/null <<EOF
set output to ""
tell application "Finder" to set the_selection to selection
set item_count to count the_selection
repeat with item_index from 1 to count the_selection
if item_index is less than item_count then set the_delimiter to "\n"
if item_index is item_count then set the_delimiter to ""
set output to output & ((item item_index of the_selection as alias)'s POSIX path) & the_delimiter
end repeat
EOF

34
plugins/osx/functions/tab Normal file
View file

@ -0,0 +1,34 @@
local command="cd \\\"$PWD\\\""
(( $# > 0 )) && command="${command}; $*"
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[ "$the_app" == 'Terminal' ]] && {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
tell application "Terminal" to do script "${command}" in front window
end tell
EOF
}
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
launch session "Default Session"
set current_session to current session
tell current_session
write text "${command}"
end tell
end tell
end tell
EOF
}

View file

@ -0,0 +1,13 @@
local trash_dir="${HOME}/.Trash"
local trash_item
local item
for item in "${@}"; do
if [[ -e "${item}" ]] || [[ -L "${item}" ]]; then
trash_item="${trash_dir}/${item:t}"
if [[ -e "${trash_item}" ]] || [[ -L "${trash_item}" ]]; then
trash_item="${trash_item} $(date "+%H-%M-%S")"
fi
mv -f "${item}" "${trash_item}"
fi
done

View file

@ -1,103 +1,23 @@
# ------------------------------------------------------------------------------
# FILE: osx.plugin.zsh
# DESCRIPTION: oh-my-zsh plugin file.
# AUTHOR: Sorin Ionescu <sorin.ionescu@gmail.com>
# VERSION: 1.0.2
# ------------------------------------------------------------------------------
# Sorin Ionescu <sorin.ionescu@gmail.com>
# Change directory to the current Finder directory.
alias cdf='cd "$(pfd)"'
function tab() {
local command="cd \\\"$PWD\\\""
(( $# > 0 )) && command="${command}; $*"
# Push directory to the current Finder directory.
alias pushdf='pushd "$(pfd)"'
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[ "$the_app" == 'Terminal' ]] && {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
tell application "Terminal" to do script "${command}" in front window
end tell
EOF
# Open files in Quick Look.
function ql() {
(( $# > 0 )) && qlmanage -p "$@" &> /dev/null
}
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
launch session "Default Session"
set current_session to current session
tell current_session
write text "${command}"
end tell
end tell
end tell
EOF
}
}
function pfd() {
osascript 2>/dev/null <<EOF
tell application "Finder"
return POSIX path of (target of window 1 as alias)
end tell
EOF
}
function pfs() {
osascript 2>/dev/null <<EOF
set output to ""
tell application "Finder" to set the_selection to selection
set item_count to count the_selection
repeat with item_index from 1 to count the_selection
if item_index is less than item_count then set the_delimiter to "\n"
if item_index is item_count then set the_delimiter to ""
set output to output & ((item item_index of the_selection as alias)'s POSIX path) & the_delimiter
end repeat
EOF
}
function cdf() {
cd "$(pfd)"
}
function pushdf() {
pushd "$(pfd)"
}
function quick-look() {
(( $# > 0 )) && qlmanage -p $* &>/dev/null &
}
function man-preview() {
man -t "$@" | open -f -a Preview
}
function trash() {
local trash_dir="${HOME}/.Trash"
local temp_ifs=$IFS
IFS=$'\n'
for item in "$@"; do
if [[ -e "$item" ]]; then
item_name="$(basename $item)"
if [[ -e "${trash_dir}/${item_name}" ]]; then
mv -f "$item" "${trash_dir}/${item_name} $(date "+%H-%M-%S")"
else
mv -f "$item" "${trash_dir}/"
fi
fi
done
IFS=$temp_ifs
# Open man pages in Preview.
function manp() {
(( $# > 0 )) && man -t "$@" | open -f -a Preview
}
compdef _man manp
# Delete .DS_Store and __MACOSX directories.
function rm-osx-cruft() {
find ${@:-$PWD} \( -type f -name ".DS_Store" \) -o \( -type d -name '__MACOSX' \) -delete
find "${@:-$PWD}" \( -type f -name '.DS_Store' \) -o \( -type d -name '__MACOSX' \) -print0 | xargs rm -rf
}

View file

@ -0,0 +1,16 @@
# List disowned files.
tmp="${TMPDIR-/tmp}/pacman-disowned-$UID-$$"
db="$tmp/db"
fs="$tmp/fs"
mkdir "$tmp"
trap 'rm -rf "$tmp"' EXIT
pacman -Qlq | sort -u > "$db"
find /bin /etc /lib /sbin /usr \
! -name lost+found \
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
comm -23 "$fs" "$db"

View file

@ -0,0 +1,4 @@
# List explicitly installed packages.
sudo pacman -Qei $(pacman -Qu|cut -d" " -f 1) \
| awk ' BEGIN {FS=":"}/^Name/{printf("\033[1;36m%s\033[1;37m", $2)}/^Description/{print $2}'

View file

@ -1,26 +1,48 @@
# Archlinux ZSH Aliases and Functions
# Arch Linux Zsh Aliases and Functions
#
# Pacman Tips:
# https://wiki.archlinux.org/index.php/Pacman_Tips
# Yaourt Aliases
if (( $+commands[yaourt] )); then
function arch-upgrade() {
yaourt -Syu
}
# Upgrade Arch Linux.
alias arch-upgrade='yaourt -Syu'
alias yaconf='yaourt -C' # Fix all configuration files with vimdiff.
alias yaupg='yaourt -Syu' # Synchronize with repositories before upgrading packages that are out of date on the local system.
alias yain='yaourt -S' # Install specific package(s) from the repositories.
alias yains='yaourt -U' # Install specific package(s) not from the repositories but from a file .
alias yare='yaourt -R' # Remove the specified package(s), retaining its configuration(s) and required dependencies.
alias yarem='yaourt -Rns' # Remove the specified package(s), its configuration(s) and unneeded dependencies.
alias yarep='yaourt -Si' # Display information about a given package in the repositories.
alias yareps='yaourt -Ss' # Search for package(s) in the repositories.
alias yaloc='yaourt -Qi' # Display information about a given package in the local database.
alias yalocs='yaourt -Qs' # Search for package(s) in the local database.
alias yamir='yaourt -Syy' # Force refresh of all package lists after updating /etc/pacman.d/mirrorlist
alias yainsd='yaourt -S --asdeps' # Install given package(s) as dependencies of another package
# Fix all configuration files with vimdiff.
alias yaconf='yaourt -C'
# Synchronize with repositories before upgrading packages that are out of date on the local system.
alias yaupg='yaourt -Syu'
# Install specific package(s) from the repositories.
alias yain='yaourt -S'
# Install specific package(s) not from the repositories but from a file .
alias yains='yaourt -U'
# Remove the specified package(s), retaining its configuration(s) and required dependencies.
alias yare='yaourt -R'
# Remove the specified package(s), its configuration(s) and unneeded dependencies.
alias yarem='yaourt -Rns'
# Display information about a given package in the repositories.
alias yarep='yaourt -Si'
# Search for package(s) in the repositories.
alias yareps='yaourt -Ss'
# Display information about a given package in the local database.
alias yaloc='yaourt -Qi'
# Search for package(s) in the local database.
alias yalocs='yaourt -Qs'
# Force refresh of all package lists after updating /etc/pacman.d/mirrorlist
alias yamir='yaourt -Syy'
# Install given package(s) as dependencies of another package
alias yainsd='yaourt -S --asdeps'
# Update and refresh the local package and ABS databases against repositories.
if (( $+commands[abs] )); then
@ -29,25 +51,49 @@ if (( $+commands[yaourt] )); then
alias yaupd='yaourt -Sy'
fi
else
function arch-upgrade() {
sudo pacman -Syu
}
# Upgrade Arch Linux.
alias arch-upgrade='sudo pacman -Syu'
fi
# Pacman Aliaases
alias pacupg='sudo pacman -Syu' # Synchronize with repositories before upgrading packages that are out of date on the local system.
alias pacin='sudo pacman -S' # Install specific package(s) from the repositories.
alias pacins='sudo pacman -U' # Install specific package not from the repositories but from a file.
alias pacre='sudo pacman -R' # Remove the specified package(s), retaining its configuration(s) and required dependencies.
alias pacrem='sudo pacman -Rns' # Remove the specified package(s), its configuration(s) and unneeded dependencies.
alias pacrep='pacman -Si' # Display information about a given package in the repositories.
alias pacreps='pacman -Ss' # Search for package(s) in the repositories.
alias pacloc='pacman -Qi' # Display information about a given package in the local database.
alias paclocs='pacman -Qs' # Search for package(s) in the local database.
alias pacinsd='sudo pacman -S --asdeps' # Install given package(s) as dependencies of another package.
alias pacmir='sudo pacman -Syy' # Force refresh of all package lists after updating /etc/pacman.d/mirrorlist.
alias paclsorphans='sudo pacman -Qdt' # List orphan packages(s).
alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)' # Remove orphan package(s).
# Pacman Aliases
# Synchronize with repositories before upgrading packages that are out of date on the local system.
alias pacupg='sudo pacman -Syu'
# Install specific package(s) from the repositories.
alias pacin='sudo pacman -S'
# Install specific package not from the repositories but from a file.
alias pacins='sudo pacman -U'
# Remove the specified package(s), retaining its configuration(s) and required dependencies.
alias pacre='sudo pacman -R'
# Remove the specified package(s), its configuration(s) and unneeded dependencies.
alias pacrem='sudo pacman -Rns'
# Display information about a given package in the repositories.
alias pacrep='pacman -Si'
# Search for package(s) in the repositories.
alias pacreps='pacman -Ss'
# Display information about a given package in the local database.
alias pacloc='pacman -Qi'
# Search for package(s) in the local database.
alias paclocs='pacman -Qs'
# Install given package(s) as dependencies of another package.
alias pacinsd='sudo pacman -S --asdeps'
# Force refresh of all package lists after updating /etc/pacman.d/mirrorlist.
alias pacmir='sudo pacman -Syy'
# List orphan packages(s).
alias paclsorphans='sudo pacman -Qdt'
# Remove orphan package(s).
alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)'
# Update and refresh the local package and ABS databases against repositories.
if (( $+commands[abs] )); then
@ -56,27 +102,3 @@ else
alias pacupd='sudo pacman -Sy'
fi
# List explicitly installed packages.
function paclist() {
sudo pacman -Qei $(pacman -Qu|cut -d" " -f 1) \
| awk ' BEGIN {FS=":"}/^Name/{printf("\033[1;36m%s\033[1;37m", $2)}/^Description/{print $2}'
}
# List disowned files.
function pacdisowned() {
tmp="${TMPDIR-/tmp}/pacman-disowned-$UID-$$"
db="$tmp/db"
fs="$tmp/fs"
mkdir "$tmp"
trap 'rm -rf "$tmp"' EXIT
pacman -Qlq | sort -u > "$db"
find /bin /etc /lib /sbin /usr \
! -name lost+found \
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
comm -23 "$fs" "$db"
}

View file

@ -0,0 +1,12 @@
# Perl Global Substitution
if (( $# < 2 )); then
print "Usage: $0 find replace [file ...]" >&2
return 1
fi
local find="$1"
local replace="$2"
repeat 2 shift
perl -i.orig -pe 's/'"$find"'/'"$replace"'/g' "$@"

View file

@ -0,0 +1,11 @@
# Perl grep since 'grep -P' is terrible.
if (( $# < 1 )) ; then
print "Usage: $0 pattern [file ...]" >&2
return 1
fi
local pattern="$1"
shift
perl -nle 'print if /'"$pattern"'/;' "$@"

View file

@ -42,30 +42,3 @@ alias pbu='perlbrew use'
alias ple='perl -wlne'
alias pd='perldoc'
# Perl Global Substitution
function pgs() {
if (( $# < 2 )) ; then
echo "Usage: $0 find replace [file ...]" >&2
return 1
fi
local find="$1"
local replace="$2"
repeat 2 shift
perl -i.orig -pe 's/'"$find"'/'"$replace"'/g' "$@"
}
# Perl grep since 'grep -P' is terrible.
function prep() {
if (( $# < 1 )) ; then
echo "Usage: $0 pattern [file ...]" >&2
return 1
fi
local pattern="$1"
shift
perl -nle 'print if /'"$pattern"'/;' "$@"
}

View file

@ -6,7 +6,7 @@ if [[ "$OSTYPE" == darwin* ]]; then
# gem is slow; cache its output.
cache_file="${0:h}/cache.zsh"
if [[ ! -f "$cache_file" ]]; then
echo export GEM_PATH=$GEM_HOME:$(gem env gempath) >! "$cache_file"
print export GEM_PATH=$GEM_HOME:$(gem env gempath) >! "$cache_file"
source "$cache_file"
else
source "$cache_file"

View file

@ -28,13 +28,13 @@ function _ssh-agent-start() {
local -a identities
# Start ssh-agent and setup environment.
/usr/bin/env ssh-agent | sed 's/^echo/#echo/' > "${_ssh_agent_env}"
/usr/bin/env ssh-agent | sed 's/^print/#print/' > "${_ssh_agent_env}"
chmod 600 "${_ssh_agent_env}"
source "${_ssh_agent_env}" > /dev/null
# Load identies.
zstyle -a :omz:plugins:ssh-agent identities identities
echo starting...
print starting...
/usr/bin/ssh-add "$HOME/.ssh/${^identities}"
}

View file

@ -9,7 +9,6 @@ alias mr='mate CHANGELOG app config db lib public script spec test'
# Functions
function tm() {
cd $1
mate $1
cd "$1" && mate .
}

View file

@ -0,0 +1,13 @@
local config_file="$HOME/.wakeonlan/$1"
if [[ ! -f "$config_file" ]]; then
print "$0: $1: There is no such device file." >&2
return 1
fi
if (( ! $+commands[wakeonlan] )); then
print "$0: Can't find wakeonlan. Is it installed?" >&2
return 1
fi
wakeonlan -f "$config_file"

View file

@ -1,15 +0,0 @@
function wake() {
local config_file="$HOME/.wakeonlan/$1"
if [[ ! -f "$config_file" ]]; then
echo "$0: $1: There is no such device file." >&2
return 1
fi
if (( ! $+commands[wakeonlan] )); then
echo "$0: Can't find wakeonlan. Is it installed?" >&2
return 1
fi
wakeonlan -f "$config_file"
}

View file

@ -1,4 +1,4 @@
# A script to make using 256 colors in ZSH less painful.
# A script to make using 256 colors in Zsh less painful.
# P.C. Shyamshankar <sykora@lucentbeing.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>

View file

@ -1,4 +1,4 @@
# Path to oh-my-zsh.
# Set the path to Oh My Zsh.
OMZ="$HOME/.oh-my-zsh"
# Set the key mapping style to 'emacs' or 'vi'.
@ -23,7 +23,7 @@ COMPLETION_INDICATOR='false'
# Example: plugins=(git lighthouse rails ruby textmate)
plugins=(git)
# This will make you scream: OH MY ZSH!
# This will make you shout: OH MY ZSHELL!
source "$OMZ/init.zsh"
# Load the prompt theme (type prompt -l to list all themes).

View file

@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------
# Prompt for ZSH:
# Prompt for Zsh:
# * One line.
# * VCS info on the right prompt.
# * Only shows the path on the left prompt by default.

View file

@ -1,7 +1,7 @@
# Prompt style and colors based on Steve Losh's Prose theme:
# http://github.com/sjl/oh-my-zsh/blob/master/themes/prose.zsh-theme
#
# vcs_info modifications from Bart Trojanowski's zsh prompt:
# vcs_info modifications from Bart Trojanowski's Zsh prompt:
# http://www.jukie.net/bart/blog/pimping-out-zsh-prompt
#
# Git untracked files modification from Brian Carper:
@ -9,7 +9,7 @@
function virtualenv_info() {
if [[ -n "$VIRTUAL_ENV" ]]; then
echo '('`basename $VIRTUAL_ENV`') '
print "(${VIRTUAL_ENV:t}) "
fi
}

View file

@ -1,84 +1,46 @@
# Lists the ten most used commands.
function history-stat() {
history | awk '{print $2}' | sort | uniq -c | sort -n -r | head
}
alias history-stat="history | awk '{print \$2}' | sort | uniq -c | sort -n -r | head"
# Serves a directory via HTTP.
alias http-serve='python -m SimpleHTTPServer'
# Makes a directory and changes to it.
function mkdcd() {
mkdir -p "$@"
cd "$argv[-1]"
[[ -n "$1" ]] && mkdir -p "$1" && cd "$1"
}
compdef _mkdir mkdcd
# Changes to a directory and lists its contents.
function cdll() {
builtin cd "$@"
ll
builtin cd "$1" && ll
}
compdef _cd cdll
# Pushes an entry onto the directory stack and lists its contents.
function pushdll() {
builtin pushd "$@"
ll
builtin pushd "$1" && ll
}
compdef _cd pushdll
# Pops an entry off the directory stack and lists its contents.
function popdll() {
builtin popd "$@"
ll
builtin popd "$1" && ll
}
compdef _cd popdll
# Gets ownership.
function gown() {
sudo chown -R "${USER}" "${1:-.}"
}
# Reloads ~/.zshrc.
function reload() {
local zshrc="$HOME/.zshrc"
if [[ -n "$1" ]]; then
zshrc="$1"
fi
source "$zshrc"
}
# Provides a simple calculator.
function calc() {
echo "scale=4; $@" | bc -l
}
# Displays human readable disk usage statistics.
function duh() {
(( $# == 0 )) && set -- *
if [[ "$OSTYPE" == linux* ]]; then
du -khsc "$@" | sort -h -r
else
du -kcs "$@" | awk '{ printf "%9.1fM %s\n", $1 / 1024, $2 } ' | sort -n -r
fi
}
compdef _du duh
# Prints columns 1 2 3 ... n.
function slit() {
awk "{ print $(for n; do echo -n "\$$n,"; done | sed 's/,$//') }"
awk "{ print $(for n; do print -n "\$$n,"; done | sed 's/,$//') }"
}
# Displays user owned process status.
function pmine() {
ps "$@" -u "$USER" -o pid,%cpu,%mem,command
ps "$@" -U "$USER" -o pid,%cpu,%mem,command
}
compdef _ps pmine
# Finds files and executes a command on them.
function findexec() {
function find-exec() {
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
}
# Serves a directory via HTTP.
function httpserve() {
python -m SimpleHTTPServer "$@"
}