Added slit, duh functions and comments.

This commit is contained in:
Sorin Ionescu 2011-07-14 17:19:05 -04:00
parent 571aa8c8e1
commit 3c273c4ce7

View file

@ -1,39 +1,42 @@
# Lists the ten most used commands.
function history-stat() { function history-stat() {
history | awk '{print $2}' | sort | uniq -c | sort -rn | head history | awk '{print $2}' | sort | uniq -c | sort -n -r | head
} }
# Makes a directory and changes to it.
function mkdcd() { function mkdcd() {
mkdir -p "$1" mkdir -p "$@"
cd "$1" cd "$argv[-1]"
} }
compdef _mkdir mkdcd
# Changes to a directory and lists its contents.
function cdll() { function cdll() {
if [[ -n "$1" ]]; then builtin cd "$@"
builtin cd "$1" ll
ls -lFhA
else
ls -lFhA
fi
} }
compdef _cd cdll
# Pushes an entry onto the directory stack and lists its contents.
function pushdll() { function pushdll() {
if [[ -n "$1" ]]; then builtin pushd "$@"
builtin pushd "$1" ll
ls -lFhA
else
ls -lFhA
fi
} }
compdef _cd pushdll
# Pops an entry off the directory stack and lists its contents.
function popdll() { function popdll() {
builtin popd builtin popd "$@"
ls -lFhA ll
} }
compdef _cd popdll
# Gets ownership.
function gown() { function gown() {
sudo chown -R "${USER}" "${1:-.}" sudo chown -R "${USER}" "${1:-.}"
} }
# Reloads ~/.zshrc.
function reload() { function reload() {
local zshrc="$HOME/.zshrc" local zshrc="$HOME/.zshrc"
if [[ -n "$1" ]]; then if [[ -n "$1" ]]; then
@ -42,18 +45,39 @@ function reload() {
source "$zshrc" source "$zshrc"
} }
# Provides a simple calculator.
function calc() { function calc() {
echo "scale=4; $@" | bc -l 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/,$//') }"
}
# Displays user owned process status.
function pmine() { 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 findexec() {
find . -type f -iname "*${1:-}*" -exec "${2:-file}" {} \; find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
} }
# Serves a directory via HTTP.
function httpserve() { function httpserve() {
python -m SimpleHTTPServer "$@" python -m SimpleHTTPServer "$@"
} }