From 60f39d8d91ced59ad631485784bbde4a9c2e102a Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Tue, 11 Oct 2011 23:13:58 -0400 Subject: [PATCH] Moved hub into the git plugin. --- README.md | 14 +- functions/duh | 13 ++ functions/reload | 7 + helper.zsh | 6 +- init.zsh | 36 ++++- keyboard.zsh | 6 +- plugins/archive/{ => completions}/_extract | 0 plugins/archive/{ => completions}/_ls-archive | 0 plugins/archive/functions/extract | 68 +++++++++ plugins/archive/functions/ls-archive | 45 ++++++ plugins/archive/init.zsh | 125 ---------------- plugins/bundler/init.zsh | 2 +- plugins/command-not-found/init.zsh | 2 +- plugins/dpkg/functions/apt-copy | 9 ++ plugins/dpkg/functions/dbb-build | 10 ++ plugins/dpkg/init.zsh | 27 ---- plugins/git/completion.zsh | 17 ++- plugins/git/{ => completions}/_git-info | 0 plugins/git/functions/git-branch | 9 ++ plugins/git/functions/git-hub | 22 +++ plugins/git/{info.zsh => functions/git-info} | 35 ++--- plugins/git/functions/git-root | 9 ++ plugins/{github/init.zsh => git/hub.zsh} | 2 - plugins/git/init.zsh | 4 +- plugins/git/style.zsh | 18 +++ plugins/git/utility.zsh | 46 ------ plugins/history-substring-search/README | 2 +- .../history-substring-search.zsh | 10 +- plugins/kate/init.zsh | 3 +- plugins/node/functions/node-docs | 4 + plugins/node/init.zsh | 6 - plugins/osx/README.md | 10 ++ plugins/osx/_man-preview | 5 - plugins/osx/functions/pfd | 6 + plugins/osx/functions/pfs | 11 ++ plugins/osx/functions/tab | 34 +++++ plugins/osx/functions/trash | 13 ++ plugins/osx/init.zsh | 108 ++------------ plugins/pacman/functions/pacdisowned | 16 ++ plugins/pacman/functions/paclist | 4 + plugins/pacman/init.zsh | 138 ++++++++++-------- plugins/perl/functions/pgs | 12 ++ plugins/perl/functions/prep | 11 ++ plugins/perl/init.zsh | 27 ---- plugins/ruby/init.zsh | 2 +- plugins/ssh-agent/init.zsh | 4 +- plugins/textmate/init.zsh | 3 +- plugins/wakeonlan/{ => completions}/_wake | 0 plugins/wakeonlan/functions/wake | 13 ++ plugins/wakeonlan/init.zsh | 15 -- spectrum.zsh | 2 +- templates/zshrc.zsh | 4 +- themes/nicoulaj/prompt_nicoulaj_setup | 2 +- themes/steeef/prompt_steeef_setup | 4 +- utility.zsh | 60 ++------ 55 files changed, 532 insertions(+), 529 deletions(-) create mode 100644 functions/duh create mode 100644 functions/reload rename plugins/archive/{ => completions}/_extract (100%) rename plugins/archive/{ => completions}/_ls-archive (100%) create mode 100644 plugins/archive/functions/extract create mode 100644 plugins/archive/functions/ls-archive delete mode 100644 plugins/archive/init.zsh create mode 100644 plugins/dpkg/functions/apt-copy create mode 100644 plugins/dpkg/functions/dbb-build rename plugins/git/{ => completions}/_git-info (100%) create mode 100644 plugins/git/functions/git-branch create mode 100644 plugins/git/functions/git-hub rename plugins/git/{info.zsh => functions/git-info} (84%) create mode 100644 plugins/git/functions/git-root rename plugins/{github/init.zsh => git/hub.zsh} (91%) create mode 100644 plugins/git/style.zsh delete mode 100644 plugins/git/utility.zsh create mode 100644 plugins/node/functions/node-docs create mode 100644 plugins/osx/README.md delete mode 100644 plugins/osx/_man-preview create mode 100644 plugins/osx/functions/pfd create mode 100644 plugins/osx/functions/pfs create mode 100644 plugins/osx/functions/tab create mode 100644 plugins/osx/functions/trash create mode 100644 plugins/pacman/functions/pacdisowned create mode 100644 plugins/pacman/functions/paclist create mode 100644 plugins/perl/functions/pgs create mode 100644 plugins/perl/functions/prep rename plugins/wakeonlan/{ => completions}/_wake (100%) create mode 100644 plugins/wakeonlan/functions/wake delete mode 100644 plugins/wakeonlan/init.zsh diff --git a/README.md b/README.md index 38d65e9..1bab17d 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/functions/duh b/functions/duh new file mode 100644 index 0000000..b01f142 --- /dev/null +++ b/functions/duh @@ -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 "$@" + diff --git a/functions/reload b/functions/reload new file mode 100644 index 0000000..9b75639 --- /dev/null +++ b/functions/reload @@ -0,0 +1,7 @@ +# Reloads ~/.zshrc. +local zshrc="$HOME/.zshrc" +if [[ -n "$1" ]]; then + zshrc="$1" +fi +source "$zshrc" + diff --git a/helper.zsh b/helper.zsh index 89e7514..f4153ce 100644 --- a/helper.zsh +++ b/helper.zsh @@ -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 diff --git a/init.zsh b/init.zsh index 6eb4977..7af5d88 100644 --- a/init.zsh +++ b/init.zsh @@ -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 diff --git a/keyboard.zsh b/keyboard.zsh index 6cb7c50..e481cba 100644 --- a/keyboard.zsh +++ b/keyboard.zsh @@ -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 diff --git a/plugins/archive/_extract b/plugins/archive/completions/_extract similarity index 100% rename from plugins/archive/_extract rename to plugins/archive/completions/_extract diff --git a/plugins/archive/_ls-archive b/plugins/archive/completions/_ls-archive similarity index 100% rename from plugins/archive/_ls-archive rename to plugins/archive/completions/_ls-archive diff --git a/plugins/archive/functions/extract b/plugins/archive/functions/extract new file mode 100644 index 0000000..2271fab --- /dev/null +++ b/plugins/archive/functions/extract @@ -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 ." +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 + diff --git a/plugins/archive/functions/ls-archive b/plugins/archive/functions/ls-archive new file mode 100644 index 0000000..589b245 --- /dev/null +++ b/plugins/archive/functions/ls-archive @@ -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 ." +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 + diff --git a/plugins/archive/init.zsh b/plugins/archive/init.zsh deleted file mode 100644 index 006afad..0000000 --- a/plugins/archive/init.zsh +++ /dev/null @@ -1,125 +0,0 @@ -# ------------------------------------------------------------------------------ -# FILE: extract.plugin.zsh -# DESCRIPTION: oh-my-zsh plugin file. -# AUTHOR: Sorin Ionescu -# 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 ." - 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 ." - 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 -} - diff --git a/plugins/bundler/init.zsh b/plugins/bundler/init.zsh index cb38415..c3377d4 100644 --- a/plugins/bundler/init.zsh +++ b/plugins/bundler/init.zsh @@ -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" diff --git a/plugins/command-not-found/init.zsh b/plugins/command-not-found/init.zsh index b8f3fe9..e94b8f2 100644 --- a/plugins/command-not-found/init.zsh +++ b/plugins/command-not-found/init.zsh @@ -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. diff --git a/plugins/dpkg/functions/apt-copy b/plugins/dpkg/functions/apt-copy new file mode 100644 index 0000000..2f2e283 --- /dev/null +++ b/plugins/dpkg/functions/apt-copy @@ -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 + diff --git a/plugins/dpkg/functions/dbb-build b/plugins/dpkg/functions/dbb-build new file mode 100644 index 0000000..7576e2e --- /dev/null +++ b/plugins/dpkg/functions/dbb-build @@ -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 + diff --git a/plugins/dpkg/init.zsh b/plugins/dpkg/init.zsh index 0b6f440..a653768 100644 --- a/plugins/dpkg/init.zsh +++ b/plugins/dpkg/init.zsh @@ -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 -} - diff --git a/plugins/git/completion.zsh b/plugins/git/completion.zsh index 4bcf7e9..b986745 100644 --- a/plugins/git/completion.zsh +++ b/plugins/git/completion.zsh @@ -1,13 +1,20 @@ # 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 - if (( $+commands[curl] )); then - curl -L "$completion_file_url" -o "$completion_file" &> /dev/null &! + # Remove empty completions directory. + if [[ -d "${completion_file:h}"(/^F) ]]; then + rmdir "${completion_file:h}" 2> /dev/null fi - if (( $+commmands[wget] )); then - wget -C "$completion_file_url" -O "$completion_file" &> /dev/null &! + if mkdir -p "${completion_file:h}" > /dev/null; then + if (( $+commands[curl] )); then + curl -L "$completion_file_url" -o "$completion_file" &> /dev/null &! + fi + + if (( $+commmands[wget] )); then + wget -C "$completion_file_url" -O "$completion_file" &> /dev/null &! + fi fi fi unset completion_file diff --git a/plugins/git/_git-info b/plugins/git/completions/_git-info similarity index 100% rename from plugins/git/_git-info rename to plugins/git/completions/_git-info diff --git a/plugins/git/functions/git-branch b/plugins/git/functions/git-branch new file mode 100644 index 0000000..b38618a --- /dev/null +++ b/plugins/git/functions/git-branch @@ -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 + diff --git a/plugins/git/functions/git-hub b/plugins/git/functions/git-hub new file mode 100644 index 0000000..6bfbb9a --- /dev/null +++ b/plugins/git/functions/git-hub @@ -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 + diff --git a/plugins/git/info.zsh b/plugins/git/functions/git-info similarity index 84% rename from plugins/git/info.zsh rename to plugins/git/functions/git-info index bd2d6cd..84e2391 100644 --- a/plugins/git/info.zsh +++ b/plugins/git/functions/git-info @@ -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 "$@" + diff --git a/plugins/git/functions/git-root b/plugins/git/functions/git-root new file mode 100644 index 0000000..e86ce70 --- /dev/null +++ b/plugins/git/functions/git-root @@ -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 + diff --git a/plugins/github/init.zsh b/plugins/git/hub.zsh similarity index 91% rename from plugins/github/init.zsh rename to plugins/git/hub.zsh index 3f327c3..8586e0a 100644 --- a/plugins/github/init.zsh +++ b/plugins/git/hub.zsh @@ -1,5 +1,3 @@ -# Aliases - # Hub by defunkt # https://github.com/defunkt/hub if (( $+commands[hub] )); then diff --git a/plugins/git/init.zsh b/plugins/git/init.zsh index 74cf943..1a30349 100644 --- a/plugins/git/init.zsh +++ b/plugins/git/init.zsh @@ -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" diff --git a/plugins/git/style.zsh b/plugins/git/style.zsh new file mode 100644 index 0000000..c0ad053 --- /dev/null +++ b/plugins/git/style.zsh @@ -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. diff --git a/plugins/git/utility.zsh b/plugins/git/utility.zsh deleted file mode 100644 index c50fc55..0000000 --- a/plugins/git/utility.zsh +++ /dev/null @@ -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 -} - diff --git a/plugins/history-substring-search/README b/plugins/history-substring-search/README index 2156774..0726ccf 100644 --- a/plugins/history-substring-search/README +++ b/plugins/history-substring-search/README @@ -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 diff --git a/plugins/history-substring-search/history-substring-search.zsh b/plugins/history-substring-search/history-substring-search.zsh index 336d359..8577130 100644 --- a/plugins/history-substring-search/history-substring-search.zsh +++ b/plugins/history-substring-search/history-substring-search.zsh @@ -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 diff --git a/plugins/kate/init.zsh b/plugins/kate/init.zsh index bacfcdc..b3b0642 100644 --- a/plugins/kate/init.zsh +++ b/plugins/kate/init.zsh @@ -3,7 +3,6 @@ alias kate='kate >/dev/null 2>&1' # Silent start. # Functions function kt() { - cd "$1" - kate "$1" + cd "$1" && kate . } diff --git a/plugins/node/functions/node-docs b/plugins/node/functions/node-docs new file mode 100644 index 0000000..8dfd49c --- /dev/null +++ b/plugins/node/functions/node-docs @@ -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}" + diff --git a/plugins/node/init.zsh b/plugins/node/init.zsh index f7abed0..69333e3 100644 --- a/plugins/node/init.zsh +++ b/plugins/node/init.zsh @@ -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" -} - diff --git a/plugins/osx/README.md b/plugins/osx/README.md new file mode 100644 index 0000000..750b5f1 --- /dev/null +++ b/plugins/osx/README.md @@ -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_. diff --git a/plugins/osx/_man-preview b/plugins/osx/_man-preview deleted file mode 100644 index 6cc344a..0000000 --- a/plugins/osx/_man-preview +++ /dev/null @@ -1,5 +0,0 @@ -#compdef man-preview -#autoload - -_man - diff --git a/plugins/osx/functions/pfd b/plugins/osx/functions/pfd new file mode 100644 index 0000000..5df7d27 --- /dev/null +++ b/plugins/osx/functions/pfd @@ -0,0 +1,6 @@ +osascript 2>/dev/null </dev/null < 0 )) && command="${command}; $*" + +the_app=$( + osascript 2>/dev/null </dev/null </dev/null < -# VERSION: 1.0.2 -# ------------------------------------------------------------------------------ +# Sorin Ionescu +# 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 </dev/null </dev/null </dev/null </dev/null < 0 )) && qlmanage -p "$@" &> /dev/null } -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 } - diff --git a/plugins/pacman/functions/pacdisowned b/plugins/pacman/functions/pacdisowned new file mode 100644 index 0000000..d46c0ee --- /dev/null +++ b/plugins/pacman/functions/pacdisowned @@ -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" + diff --git a/plugins/pacman/functions/paclist b/plugins/pacman/functions/paclist new file mode 100644 index 0000000..648fbbf --- /dev/null +++ b/plugins/pacman/functions/paclist @@ -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}' + diff --git a/plugins/pacman/init.zsh b/plugins/pacman/init.zsh index 7dd0e84..8f22176 100644 --- a/plugins/pacman/init.zsh +++ b/plugins/pacman/init.zsh @@ -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 - } - - 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 + # Upgrade Arch Linux. + alias arch-upgrade='yaourt -Syu' + + # 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,54 +51,54 @@ 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' -# Update and refresh the local package and ABS databases against repositories. -if (( $+commands[abs] )); then - alias pacupd='sudo pacman -Sy && sudo abs' -else - alias pacupd='sudo pacman -Sy' -fi +# 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' -# 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}' -} +# Display information about a given package in the local database. +alias pacloc='pacman -Qi' -# List disowned files. -function pacdisowned() { - tmp="${TMPDIR-/tmp}/pacman-disowned-$UID-$$" - db="$tmp/db" - fs="$tmp/fs" +# Search for package(s) in the local database. +alias paclocs='pacman -Qs' - mkdir "$tmp" - trap 'rm -rf "$tmp"' EXIT +# Install given package(s) as dependencies of another package. +alias pacinsd='sudo pacman -S --asdeps' - pacman -Qlq | sort -u > "$db" +# Force refresh of all package lists after updating /etc/pacman.d/mirrorlist. +alias pacmir='sudo pacman -Syy' - find /bin /etc /lib /sbin /usr \ - ! -name lost+found \ - \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" +# List orphan packages(s). +alias paclsorphans='sudo pacman -Qdt' - comm -23 "$fs" "$db" -} +# 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 + alias pacupd='sudo pacman -Sy && sudo abs' +else + alias pacupd='sudo pacman -Sy' +fi diff --git a/plugins/perl/functions/pgs b/plugins/perl/functions/pgs new file mode 100644 index 0000000..99a375c --- /dev/null +++ b/plugins/perl/functions/pgs @@ -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' "$@" + diff --git a/plugins/perl/functions/prep b/plugins/perl/functions/prep new file mode 100644 index 0000000..ef9118e --- /dev/null +++ b/plugins/perl/functions/prep @@ -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"'/;' "$@" + diff --git a/plugins/perl/init.zsh b/plugins/perl/init.zsh index 7adad86..450a8e0 100644 --- a/plugins/perl/init.zsh +++ b/plugins/perl/init.zsh @@ -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"'/;' "$@" -} - diff --git a/plugins/ruby/init.zsh b/plugins/ruby/init.zsh index 2776b5b..bca092c 100644 --- a/plugins/ruby/init.zsh +++ b/plugins/ruby/init.zsh @@ -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" diff --git a/plugins/ssh-agent/init.zsh b/plugins/ssh-agent/init.zsh index 6f309ce..89ad7f5 100644 --- a/plugins/ssh-agent/init.zsh +++ b/plugins/ssh-agent/init.zsh @@ -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}" } diff --git a/plugins/textmate/init.zsh b/plugins/textmate/init.zsh index 5370f63..80564b1 100644 --- a/plugins/textmate/init.zsh +++ b/plugins/textmate/init.zsh @@ -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 . } diff --git a/plugins/wakeonlan/_wake b/plugins/wakeonlan/completions/_wake similarity index 100% rename from plugins/wakeonlan/_wake rename to plugins/wakeonlan/completions/_wake diff --git a/plugins/wakeonlan/functions/wake b/plugins/wakeonlan/functions/wake new file mode 100644 index 0000000..83410c7 --- /dev/null +++ b/plugins/wakeonlan/functions/wake @@ -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" + diff --git a/plugins/wakeonlan/init.zsh b/plugins/wakeonlan/init.zsh deleted file mode 100644 index d91ba59..0000000 --- a/plugins/wakeonlan/init.zsh +++ /dev/null @@ -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" -} - diff --git a/spectrum.zsh b/spectrum.zsh index 67beeac..629e041 100644 --- a/spectrum.zsh +++ b/spectrum.zsh @@ -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 # Sorin Ionescu diff --git a/templates/zshrc.zsh b/templates/zshrc.zsh index 93b67fe..903e27b 100644 --- a/templates/zshrc.zsh +++ b/templates/zshrc.zsh @@ -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). diff --git a/themes/nicoulaj/prompt_nicoulaj_setup b/themes/nicoulaj/prompt_nicoulaj_setup index 26a0783..84061fd 100644 --- a/themes/nicoulaj/prompt_nicoulaj_setup +++ b/themes/nicoulaj/prompt_nicoulaj_setup @@ -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. diff --git a/themes/steeef/prompt_steeef_setup b/themes/steeef/prompt_steeef_setup index 28b2a91..6584125 100644 --- a/themes/steeef/prompt_steeef_setup +++ b/themes/steeef/prompt_steeef_setup @@ -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 } diff --git a/utility.zsh b/utility.zsh index 1af3902..20178cc 100644 --- a/utility.zsh +++ b/utility.zsh @@ -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 "$@" -} -