From cbdf8122a67564e4e64f69fc1762813aba2b5134 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Sun, 10 Jun 2012 19:35:15 -0400 Subject: [PATCH] [Fix #149] Restructure utility --- modules/utility/README.md | 88 ++++++++++++++++-------------- modules/utility/init.zsh | 111 +++++++++++++++++++++----------------- 2 files changed, 111 insertions(+), 88 deletions(-) diff --git a/modules/utility/README.md b/modules/utility/README.md index 48642b20..8c67671a 100644 --- a/modules/utility/README.md +++ b/modules/utility/README.md @@ -11,8 +11,8 @@ Settings If you have enabled color globally in *zshrc*, you may disable it for certain commands. -To disable `ls` color, add the following line to *zshrc*. If coloring is -disabled, type indicators (*, /, =>, @, |) will be appended to entries. +To disable `ls` color, add the following line to *zshrc*; when coloring is +disabled, type indicators (\*, /, =>, @, =, |, %) will be appended to entries. zstyle ':omz:module:utility:ls' color 'no' @@ -31,32 +31,7 @@ To disable `make` highlighting, add the following line to *zshrc*: Aliases ------- -### The ls Family - - - `ls` lists with directories grouped first (GNU only). - - `l` lists in one column, hidden files. - - `ll` lists human readable sizes. - - `lr` lists recursively. - - `la` lists hidden files. - - `lp` lists through pager. - - `lx` lists sorted by extension (GNU only). - - `lk` lists sorted by size, largest last. - - `lt` lists sorted by date, most recent last. - - `lc` lists sorted by date, most recent last, shows change time. - - `lu` lists sorted by date, most recent last, shows access time. - - `sl` is aliased to ls. - -### General - - - `_` is aliased to sudo. - - `b` opens the default web browser. - - `e` opens the default editor. - - `p` opens the default pager. - - `po` removes a directory from the stack and changes to it. - - `pu` adds the current directory to the stack and changes to a directory. - - `type` displays all attribute values of a shell parameter. - -### Spelling Correction Disabled +### Disabled Spelling Correction - `ack` - `cd` @@ -64,6 +39,7 @@ Aliases - `ebuild` - `gcc` - `gist` + - `grep` - `heroku` - `ln` - `man` @@ -73,7 +49,7 @@ Aliases - `rm` - `scp` -### File Globbing Disabled +### Disabled File Globbing - `fc` - `find` @@ -81,14 +57,45 @@ Aliases - `locate` - `rake` -### Mac OS X +### General - - `o` is alised to `open` on Mac OS X and `xdg-open` on non Mac OS X. - - `get` downloads a file using `curl` or `wget`. - - `pbcopy` uses xclip or xsel on non Mac OS X. - - `pbpaste` uses xclip or xsel on non Mac OS X. - - `pbc` is alised to `pbcopy`. - - `pbp` is alised to `pbpaste`. + - `_` executes a command as another user (`sudo`). + - `b` opens the default web browser. + - `cp` copies files and directories interactively. + - `e` opens the default editor. + - `ln` links files and directories interactively. + - `mkdir` creates directories, including itermediery directories. + - `mv` moves files and directories interactively. + - `p` opens the default pager. + - `po` removes a directory from the stack and changes to it (`popd`). + - `pu` changes the directory and pushes the old directory onto the stack + (`pushd`). + - `rm` removes files and directories interactively. + - `type` displays all the attribute values of a shell parameter. + +### Files and Directories + + - `ls` lists with directories grouped first (GNU only). + - `l` lists in one column, hidden files. + - `ll` lists human readable sizes. + - `lr` lists human readable sizes, recursively. + - `la` lists human readable sizes, hidden files. + - `lp` lists human readable sizes, hidden files through pager. + - `lx` lists sorted by extension (GNU only). + - `lk` lists sorted by size, largest last. + - `lt` lists sorted by date, most recent last. + - `lc` lists sorted by date, most recent last, shows change time. + - `lu` lists sorted by date, most recent last, shows access time. + - `sl` lists directory contents (`ls`). + +### Mac OS X Everywhere + + - `o` opens files and directories (`open` or `xdg-open`). + - `get` downloads files (`curl` or `wget`). + - `pbcopy` copies to the pasteboard (`pbcopy`, `xclip` or `xsel`). + - `pbpaste` pastes from the pasteboard (`pbcopy`, `xclip` or `xsel`). + - `pbc` copies to the pasteboard (`pbcopy`). + - `pbp` pastes from the pasteboard (`pbpaste`). ### Resource Usage @@ -103,19 +110,18 @@ Aliases ### Misecellaneous - `http-serve` serves a directory via HTTP. - - `pmine` displays user owned processes status. Functions --------- ### General - - `slit` prints columns 1 2 3 ... n. + - `slit` prints columns *1, 2, 3 ... n*. ### Files and Directories - `cdls` changes to a directory and lists its contents. - - `duh` displays human readable disk usage. + - `dut` displays the grand total disk usage using human readable units. - `find-exec` finds files and executes a command on them. - `mkdcd` makes a directory and changes to it. - `popdls` pops an entry off the directory stack and lists its contents. @@ -127,6 +133,10 @@ Functions - `make` highlights make output (requires `colormake`). - `wdiff` highlights wdiff output (requires `wdiff `or `Git`). +### Resource usage + + - `psu` displays user owned processes status. + Authors ------- diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index bcd9a581..53b618d4 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -15,9 +15,47 @@ setopt CORRECT # Aliases -# The 'ls' Family +# Disable correction. +alias ack='nocorrect ack' +alias cd='nocorrect cd' +alias cp='nocorrect cp' +alias ebuild='nocorrect ebuild' +alias gcc='nocorrect gcc' +alias gist='nocorrect gist' +alias grep='nocorrect grep' +alias heroku='nocorrect heroku' +alias ln='nocorrect ln' +alias man='nocorrect man' +alias mkdir='nocorrect mkdir' +alias mv='nocorrect mv' +alias mysql='nocorrect mysql' +alias rm='nocorrect rm' +alias scp='nocorrect scp' + +# Disable globbing. +alias fc='noglob fc' +alias find='noglob find' +alias history='noglob history' +alias locate='noglob locate' +alias rake='noglob rake' + +# Define general aliases. +alias _='sudo' +alias b='${(z)BROWSER}' +alias cp="${aliases[cp]:-cp} -i" +alias e='${(z)EDITOR}' +alias ln="${aliases[ln]:-ln} -i" +alias mkdir="${aliases[mkdir]:-mkdir} -p" +alias mv="${aliases[mv]:-mv} -i" +alias p='${(z)PAGER}' +alias po='popd' +alias pu='pushd' +alias rm="${aliases[rm]:-rm} -i" +alias type='type -a' + +# ls if is-callable 'dircolors'; then - # GNU core utilities. + # GNU Core Utilities alias ls='ls --group-directories-first' if zstyle -t ':omz:module:utility:ls' color; then @@ -31,7 +69,7 @@ if is-callable 'dircolors'; then alias ls="$aliases[ls] -F" fi else - # BSD core utilities. + # BSD Core Utilities if zstyle -t ':omz:module:utility:ls' color; then export LSCOLORS="exfxcxdxbxegedabagacad" alias ls="ls -G" @@ -40,44 +78,19 @@ else fi fi -alias l='ls -1A' # List in one column. -alias ll='ls -lh' # List human readable sizes. -alias lr='ll -R' # List recursively. -alias la='ll -A' # List hidden files. -alias lp='la | "$PAGER"' # List through pager. -alias lx='ll -XB' # List sorted by extension. -alias lk='ll -Sr' # List sorted by size, largest last. -alias lt='ll -tr' # List sorted by date, most recent last. -alias lc='lt -c' # List sorted by date, most recent last, show change time. -alias lu='lt -u' # List sorted by date, most recent last, show access time. +alias l='ls -1A' # Lists in one column, hidden files. +alias ll='ls -lh' # Lists human readable sizes. +alias lr='ll -R' # Lists human readable sizes, recursively. +alias la='ll -A' # Lists human readable sizes, hidden files. +alias lp='la | "$PAGER"' # Lists human readable sizes, hidden files through pager. +alias lx='ll -XB' # Lists sorted by extension (GNU only). +alias lk='ll -Sr' # Lists sorted by size, largest last. +alias lt='ll -tr' # Lists sorted by date, most recent last. +alias lc='lt -c' # Lists sorted by date, most recent last, shows change time. +alias lu='lt -u' # Lists sorted by date, most recent last, shows access time. alias sl='ls' # I often screw this up. -# General -alias _='sudo' -alias b='${(z)BROWSER}' -alias cd='nocorrect cd' -alias cp='nocorrect cp -i' -alias df='df -kh' -alias du='du -kh' -alias e='${(z)EDITOR}' -alias find='noglob find' -alias fc='noglob fc' -alias gcc='nocorrect gcc' -alias history='noglob history' -alias ln='nocorrect ln -i' -alias locate='noglob locate' -alias man='nocorrect man' -alias mkdir='nocorrect mkdir -p' -alias mv='nocorrect mv -i' -alias p='${(z)PAGER}' -alias po='popd' -alias pu='pushd' -alias rake='noglob rake' -alias rm='nocorrect rm -i' -alias scp='nocorrect scp' -alias type='type -a' - -# Mac OS X +# Mac OS X Everywhere if [[ "$OSTYPE" == darwin* ]]; then alias o='open' alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time' @@ -99,27 +112,22 @@ fi alias pbc='pbcopy' alias pbp='pbpaste' -# Top +# Resource Usage +alias df='df -kh' +alias du='du -kh' + if (( $+commands[htop] )); then alias top=htop else - alias topm='top -o vsize' alias topc='top -o cpu' + alias topm='top -o vsize' fi # Miscellaneous -alias afind='nocorrect ack' -alias ebuild='nocorrect ebuild' -alias gist='nocorrect gist' -alias heroku='nocorrect heroku' -alias mysql='nocorrect mysql' # Serves a directory via HTTP. alias http-serve='python -m SimpleHTTPServer' -# Displays user owned processes status. -alias pmine='ps -U "$USER" -o pid,%cpu,%mem,command' - # Functions # Makes a directory and changes to it. @@ -152,3 +160,8 @@ function find-exec { find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \; } +# Displays user owned processes status. +function psu { + ps -{U,u}" ${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}" +} +