parent
62fc8d802e
commit
60f39d8d91
@ -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 "$@"
|
||||
|
@ -0,0 +1,7 @@
|
||||
# Reloads ~/.zshrc.
|
||||
local zshrc="$HOME/.zshrc"
|
||||
if [[ -n "$1" ]]; then
|
||||
zshrc="$1"
|
||||
fi
|
||||
source "$zshrc"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,3 @@
|
||||
# Aliases
|
||||
|
||||
# Hub by defunkt
|
||||
# https://github.com/defunkt/hub
|
||||
if (( $+commands[hub] )); then
|
@ -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.
|
@ -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
|
||||
}
|
||||
|
@ -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}"
|
||||
|
@ -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_.
|
@ -1,5 +0,0 @@
|
||||
#compdef man-preview
|
||||
#autoload
|
||||
|
||||
_man
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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}'
|
||||
|
@ -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' "$@"
|
||||
|
@ -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"'/;' "$@"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in new issue