Commit 6952105b authored by Pavol Juhas's avatar Pavol Juhas
Browse files
parents ed19ffee ca900216
The MIT License The MIT License
Copyright (c) 2009-2013 Robby Russell and contributors (see https://github.com/robbyrussell/oh-my-zsh/contributors) Copyright (c) 2009-2014 Robby Russell and contributors (see https://github.com/robbyrussell/oh-my-zsh/contributors)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
...@@ -14,15 +14,25 @@ You can install this via the command line with either `curl` or `wget`. ...@@ -14,15 +14,25 @@ You can install this via the command line with either `curl` or `wget`.
h4. via `curl` h4. via `curl`
@curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh@ @curl -L http://install.ohmyz.sh | sh@
h4. via `wget` h4. via `wget`
@wget --no-check-certificate https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh@ @wget --no-check-certificate http://install.ohmyz.sh -O - | sh@
h3. The manual way h4. Optional: change the install directory
The default location is `~/.oh-my-zsh` (hidden in your home directory).
You can change the install directory with the ZSH environment variable, either
by running `export ZSH=/your/path` before installing, or setting it before the
end of the install pipeline like this:
@curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | ZSH=~/.dotfiles/zsh sh@
h3. The manual way
1. Clone the repository 1. Clone the repository
@git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh@ @git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh@
...@@ -35,7 +45,6 @@ h3. The manual way ...@@ -35,7 +45,6 @@ h3. The manual way
@cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc@ @cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc@
4. Set zsh as your default shell: 4. Set zsh as your default shell:
@chsh -s /bin/zsh@ @chsh -s /bin/zsh@
...@@ -46,6 +55,8 @@ h3. Problems? ...@@ -46,6 +55,8 @@ h3. Problems?
You _might_ need to modify your PATH in ~/.zshrc if you're not able to find some commands after switching to _Oh My Zsh_. You _might_ need to modify your PATH in ~/.zshrc if you're not able to find some commands after switching to _Oh My Zsh_.
If you installed manually or changed the install location, check ZSH in ~/.zshrc
h2. Usage h2. Usage
* enable the plugins you want in your @~/.zshrc@ (take a look at @plugins/@ to see what's possible) * enable the plugins you want in your @~/.zshrc@ (take a look at @plugins/@ to see what's possible)
......
...@@ -27,9 +27,9 @@ else ...@@ -27,9 +27,9 @@ else
fi fi
# List direcory contents # List direcory contents
alias lsa='ls -lah' alias lsa='ls -lah'
alias l='ls -la' alias l='ls -lah'
alias ll='ls -l' alias ll='ls -lh'
alias la='ls -lA' alias la='ls -lAh'
alias sl=ls # often screw this up alias sl=ls # often screw this up
alias afind='ack-grep -il' alias afind='ack-grep -il'
......
...@@ -31,35 +31,20 @@ zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm ...@@ -31,35 +31,20 @@ zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
cdpath=(.) cdpath=(.)
# use /etc/hosts and known_hosts for hostname completion
[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _global_ssh_hosts=()
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r ~/.ssh/config ] && _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
hosts=(
"$_ssh_config[@]"
"$_global_ssh_hosts[@]"
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
"$HOST"
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
zstyle ':completion:*' users off
# Use caching so that commands like apt and dpkg complete are useable # Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1 zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path $ZSH/cache/ zstyle ':completion::complete:*' cache-path $ZSH/cache/
# Don't complete uninteresting users # Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \ zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \ adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \ clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \ gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \
mailman mailnull mldonkey mysql nagios \ ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \ named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \ operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \
usbmux uucp vcsa wwwrun xfs
# ... unless we really want to. # ... unless we really want to.
zstyle '*' single-ignored show zstyle '*' single-ignored show
......
# TODO: Explain what some of this does.. # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
bindkey -e # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
bindkey '\ew' kill-region
bindkey -s '\el' "ls\n" # Make sure that the terminal is in application mode when zle is active, since
bindkey '^r' history-incremental-search-backward # only then values from $terminfo are valid
bindkey "^[[5~" up-line-or-history if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
bindkey "^[[6~" down-line-or-history function zle-line-init() {
echoti smkx
# make search up and down work, so partially type and hit up/down to find relevant stuff }
bindkey '^[[A' up-line-or-search function zle-line-finish() {
bindkey '^[[B' down-line-or-search echoti rmkx
}
bindkey "^[[H" beginning-of-line zle -N zle-line-init
bindkey "^[[1~" beginning-of-line zle -N zle-line-finish
bindkey "^[OH" beginning-of-line fi
bindkey "^[[F" end-of-line
bindkey "^[[4~" end-of-line bindkey -e # Use emacs key bindings
bindkey "^[OF" end-of-line
bindkey ' ' magic-space # also do history expansion on space bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
bindkey "^[[1;5C" forward-word bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
bindkey "^[[1;5D" backward-word bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
bindkey '^[[Z' reverse-menu-complete
bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
bindkey '^?' backward-delete-char
bindkey "^[[3~" delete-char bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
bindkey "^[3;5~" delete-char bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
bindkey "\e[3~" delete-char
bindkey ' ' magic-space # [Space] - do history expansion
bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
bindkey '^?' backward-delete-char # [Backspace] - delete backward
bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
# Edit the current command line in $EDITOR # Edit the current command line in $EDITOR
autoload -U edit-command-line autoload -U edit-command-line
......
# *_prompt_info functions for usage in your prompt
#
# Plugin creators, please add your *_prompt_info function to the list
# of dummy implementations to help theme creators not receiving errors
# without the need of implementing conditional clauses.
#
# See also lib/bzr.zsh, lib/git.zsh and lib/nvm.zsh for
# git_prompt_info, bzr_prompt_info and nvm_prompt_info
# Dummy implementations that return false to prevent command_not_found
# errors with themes, that implement these functions
# Real implementations will be used when the respective plugins are loaded
function chruby_prompt_info hg_prompt_info pyenv_prompt_info \
rbenv_prompt_info svn_prompt_info vi_mode_prompt_info \
virtualenv_prompt_info {
return 1
}
# oh-my-zsh supports an rvm prompt by default
# get the name of the rvm ruby version
function rvm_prompt_info() {
[ -f $HOME/.rvm/bin/rvm-prompt ] || return 1
local rvm_prompt
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
[[ "${rvm_prompt}x" == "x" ]] && return 1
echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
}
# use this to enable users to see their ruby version, no matter which
# version management system they use
function ruby_prompt_info() {
echo $(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)
}
# using the rbenv plugin will override this with a real implementation
function rbenv_prompt_info() {}
# get the name of the ruby version
function rvm_prompt_info() {
[ -f $HOME/.rvm/bin/rvm-prompt ] || return
local rvm_prompt
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
[[ "${rvm_prompt}x" == "x" ]] && return
echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
}
...@@ -27,9 +27,8 @@ function omz_termsupport_preexec { ...@@ -27,9 +27,8 @@ function omz_termsupport_preexec {
emulate -L zsh emulate -L zsh
setopt extended_glob setopt extended_glob
local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
local LINE="${2:gs/$/\\$}" local LINE="${2:gs/%/%%}"
LINE="${LINE:gs/%/%%}" title '$CMD' '%100>...>$LINE%<<'
title "$CMD" "%100>...>$LINE%<<"
} }
autoload -U add-zsh-hook autoload -U add-zsh-hook
......
#
# Your guess is as good as mine. Let's just assume that we will need this...
# - For more info visit... http://atom.io/
#
\ No newline at end of file
export AWS_HOME=~/.aws
function agp {
echo $AWS_DEFAULT_PROFILE
}
function asp {
export AWS_DEFAULT_PROFILE=$1
export RPROMPT="<aws:$AWS_DEFAULT_PROFILE>"
}
function aws_profiles {
reply=($(grep profile $AWS_HOME/config|sed -e 's/.*profile \([a-zA-Z0-9_-]*\).*/\1/'))
}
compctl -K aws_profiles asp
source `which aws_zsh_completer.sh`
...@@ -18,11 +18,15 @@ if [[ $(uname) == "Darwin" ]] ; then ...@@ -18,11 +18,15 @@ if [[ $(uname) == "Darwin" ]] ; then
echo $i echo $i
} }
function plugged_in() {
[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ]
}
function battery_pct_remaining() { function battery_pct_remaining() {
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then if plugged_in ; then
battery_pct
else
echo "External Power" echo "External Power"
else
battery_pct
fi fi
} }
...@@ -30,7 +34,11 @@ if [[ $(uname) == "Darwin" ]] ; then ...@@ -30,7 +34,11 @@ if [[ $(uname) == "Darwin" ]] ; then
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //') timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
if [ $timeremaining -gt 720 ] ; then
echo "::"
else
echo "~$((timeremaining / 60)):$((timeremaining % 60))" echo "~$((timeremaining / 60)):$((timeremaining % 60))"
fi
else else
echo "∞" echo "∞"
fi fi
...@@ -58,9 +66,19 @@ if [[ $(uname) == "Darwin" ]] ; then ...@@ -58,9 +66,19 @@ if [[ $(uname) == "Darwin" ]] ; then
elif [[ $(uname) == "Linux" ]] ; then elif [[ $(uname) == "Linux" ]] ; then
function battery_pct_remaining() { function battery_is_charging() {
if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then ! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]]
}
function battery_pct() {
echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')"
}
function battery_pct_remaining() {
if [ ! $(battery_is_charging) ] ; then
battery_pct
else
echo "External Power"
fi fi
} }
...@@ -86,15 +104,6 @@ elif [[ $(uname) == "Linux" ]] ; then ...@@ -86,15 +104,6 @@ elif [[ $(uname) == "Linux" ]] ; then
fi fi
} }
function battery_pct() {
# todo for on linux
}
function battery_is_charging() {
# todo on linux
false
}
else else
# Empty functions so we don't cause errors in prompts # Empty functions so we don't cause errors in prompts
function battery_pct_remaining() { function battery_pct_remaining() {
......
...@@ -11,10 +11,25 @@ _brew_installed_formulae() { ...@@ -11,10 +11,25 @@ _brew_installed_formulae() {
installed_formulae=(`brew list`) installed_formulae=(`brew list`)
} }
_brew_installed_taps() {
installed_taps=(`brew tap`)
}
_brew_outdated_formulae() {
outdated_formulae=(`brew outdated`)
}
_brew_running_services() {
running_services=(`brew services list | awk '{print $1}'`)
}
local -a _1st_arguments local -a _1st_arguments
_1st_arguments=( _1st_arguments=(
'audit:check formulae for Homebrew coding style'
'bundle:look for a Brewfile and run each line as a brew command'
'cat:display formula file for a formula' 'cat:display formula file for a formula'
'cleanup:uninstall unused and old versions of packages' 'cleanup:uninstall unused and old versions of packages'
'commands:show a list of commands'
'create:create a new formula' 'create:create a new formula'
'deps:list dependencies and dependants of a formula' 'deps:list dependencies and dependants of a formula'
'doctor:audits your installation for common issues' 'doctor:audits your installation for common issues'
...@@ -22,26 +37,38 @@ _1st_arguments=( ...@@ -22,26 +37,38 @@ _1st_arguments=(
'home:visit the homepage of a formula or the brew project' 'home:visit the homepage of a formula or the brew project'
'info:information about a formula' 'info:information about a formula'
'install:install a formula' 'install:install a formula'
'reinstall:install a formula anew; re-using its current options'
'link:link a formula' 'link:link a formula'
'list:list files in a formula or not-installed formulae' 'list:list files in a formula or not-installed formulae'
'log:git commit log for a formula' 'log:git commit log for a formula'
'missing:check all installed formuale for missing dependencies.' 'missing:check all installed formuale for missing dependencies.'
'options:display install options specific to formula.' 'outdated:list formulae for which a newer version is available'
'outdated:list formulas for which a newer version is available' 'pin:pin specified formulae'
'prune:remove dead links' 'prune:remove dead links'
'reinstall:reinstall a formula'
'remove:remove a formula' 'remove:remove a formula'
'search:search for a formula (/regex/ or string)' 'search:search for a formula (/regex/ or string)'
'server:start a local web app that lets you browse formulae (requires Sinatra)' 'server:start a local web app that lets you browse formulae (requires Sinatra)'
'services:small wrapper around `launchctl` for supported formulae'
'tap:tap a new formula repository from GitHub, or list existing taps'
'unlink:unlink a formula' 'unlink:unlink a formula'
'unpin:unpin specified formulae'
'untap:remove a tapped repository'
'update:freshen up links' 'update:freshen up links'
'upgrade:upgrade outdated formulae' 'upgrade:upgrade outdated formulae'
'uses:show formulas which depend on a formula' 'uses:show formulae which depend on a formula'
'versions:show all available formula versions' )
local -a _service_arguments
_service_arguments=(
'cleanup:get rid of stale services and unused plists'
'list:list all services managed by `brew services`'
'restart:gracefully restart selected service'
'start:start selected service'
'stop:stop selected service'
) )
local expl local expl
local -a formulae installed_formulae local -a formulae installed_formulae installed_taps outdated_formulae running_services
_arguments \ _arguments \
'(-v)-v[verbose]' \ '(-v)-v[verbose]' \
...@@ -60,13 +87,13 @@ if (( CURRENT == 1 )); then ...@@ -60,13 +87,13 @@ if (( CURRENT == 1 )); then
fi fi
case "$words[1]" in case "$words[1]" in
search|-S) install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|edit|options)
_arguments \ _brew_all_formulae
'(--macports)--macports[search the macports repository]' \ _wanted formulae expl 'all formulae' compadd -a formulae ;;
'(--fink)--fink[search the fink repository]' ;;
list|ls) list|ls)
_arguments \ _arguments \
'(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \ '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
'(--pinned)--pinned[list all versions of pinned formulae]' \
'(--versions)--versions[list all installed versions of a formula]' \ '(--versions)--versions[list all installed versions of a formula]' \
'1: :->forms' && return 0 '1: :->forms' && return 0
...@@ -74,10 +101,27 @@ case "$words[1]" in ...@@ -74,10 +101,27 @@ case "$words[1]" in
_brew_installed_formulae _brew_installed_formulae
_wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
fi ;; fi ;;
install|home|homepage|log|info|abv|uses|cat|deps|edit|options|versions) remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin)
_brew_all_formulae
_wanted formulae expl 'all formulae' compadd -a formulae ;;
reinstall|remove|rm|uninstall|unlink|cleanup|link|ln)
_brew_installed_formulae _brew_installed_formulae
_wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;; _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
search|-S)
_arguments \
'(--macports)--macports[search the macports repository]' \
'(--fink)--fink[search the fink repository]' ;;
services)
if [[ -n "$words[2]" ]]; then
case "$words[2]" in
restart|start|stop)
_brew_running_services
_wanted running_services expl 'running services' compadd -a running_services ;;
esac
else
_describe -t commands "brew services subcommand" _service_arguments
fi ;;
untap)
_brew_installed_taps
_wanted installed_taps expl 'installed taps' compadd -a installed_taps ;;
upgrade)
_brew_outdated_formulae
_wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;;
esac esac
...@@ -6,7 +6,7 @@ alias bu="bundle update" ...@@ -6,7 +6,7 @@ alias bu="bundle update"
# The following is based on https://github.com/gma/bundler-exec # The following is based on https://github.com/gma/bundler-exec
bundled_commands=(annotate berks cap capify cucumber foodcritic foreman guard jekyll kitchen knife middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor taps thin thor unicorn unicorn_rails puma) bundled_commands=(annotate berks cap capify cucumber foodcritic foreman guard jekyll kitchen knife mailcatcher middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor taps thin thor unicorn unicorn_rails puma)
# Remove $UNBUNDLED_COMMANDS from the bundled_commands list # Remove $UNBUNDLED_COMMANDS from the bundled_commands list
for cmd in $UNBUNDLED_COMMANDS; do for cmd in $UNBUNDLED_COMMANDS; do
......
function cabal_sandbox_info() {
cabal_files=(*.cabal(N))
if [ $#cabal_files -gt 0 ]; then
if [ -f cabal.sandbox.config ]; then
echo "%{$fg[green]%}sandboxed%{$reset_color%}"
else
echo "%{$fg[red]%}not sandboxed%{$reset_color%}"
fi
fi
}
function _cabal_commands() { function _cabal_commands() {
local ret=1 state local ret=1 state
_arguments ':subcommand:->subcommand' && ret=0 _arguments ':subcommand:->subcommand' && ret=0
......
################################################################################
# catimg script by Eduardo San Martin Morote aka Posva #
# http://posva.net #
# #
# Ouput the content of an image to the stdout using the 256 colors of the #
# terminal. #
# Github: https://github.com/posva/catimg #
################################################################################
function catimg() {
if [[ -x `which convert` ]]; then
zsh $ZSH/plugins/catimg/catimg.sh $@
else
echo "catimg need convert (ImageMagick) to work)"
fi
}
################################################################################
# catimg script by Eduardo San Martin Morote aka Posva #
# http://posva.net #
# #
# Ouput the content of an image to the stdout using the 256 colors of the #
# terminal. #
# Github: https://github.com/posva/catimg #
################################################################################
function help() {
echo "Usage catimg [-h] [-w width] [-c char] img"
echo "By default char is \" \" and w is the terminal width"
}
# VARIABLES
COLOR_FILE=$(dirname $0)/colors.png
CHAR=" "
WIDTH=""
IMG=""
while getopts qw:c:h opt; do
case "$opt" in
w) WIDTH="$OPTARG" ;;
c) CHAR="$OPTARG" ;;
h) help; exit ;;
*) help ; exit 1;;
esac
done
while [ "$1" ]; do
IMG="$1"
shift
done
if [ "$IMG" = "" -o ! -f "$IMG" ]; then
help
exit 1
fi
if [ ! "$WIDTH" ]; then
COLS=$(expr $(tput cols) "/" $(echo -n "$CHAR" | wc -c))
else
COLS=$(expr $WIDTH "/" $(echo -n "$CHAR" | wc -c))
fi
WIDTH=$(convert "$IMG" -print "%w\n" /dev/null)
if [ "$WIDTH" -gt "$COLS" ]; then
WIDTH=$COLS
fi
REMAP=""
if convert "$IMG" -resize $COLS\> +dither -remap $COLOR_FILE /dev/null ; then
REMAP="-remap $COLOR_FILE"
else
echo "The version of convert is too old, don't expect good results :(" >&2
#convert "$IMG" -colors 256 PNG8:tmp.png
#IMG="tmp.png"
fi
# Display the image
I=0
convert "$IMG" -resize $COLS\> +dither `echo $REMAP` txt:- 2>/dev/null |
sed -e 's/.*none.*/NO NO NO/g' -e '1d;s/^.*(\(.*\)[,)].*$/\1/g;y/,/ /' |
while read R G B f; do
if [ ! "$R" = "NO" ]; then
if [ "$R" -eq "$G" -a "$G" -eq "$B" ]; then
((
I++,
IDX = 232 + R * 23 / 255
))
else
((
I++,
IDX = 16
+ R * 5 / 255 * 36
+ G * 5 / 255 * 6
+ B * 5 / 255
))
fi
#echo "$R,$G,$B: $IDX"
echo -ne "\e[48;5;${IDX}m${CHAR}"
else
(( I++ ))
echo -ne "\e[0m${CHAR}"
fi
# New lines
(( $I % $WIDTH )) || echo -e "\e[0m"
done
...@@ -217,3 +217,11 @@ kerndeb () { ...@@ -217,3 +217,11 @@ kerndeb () {
"$revision" kernel_image kernel_headers "$revision" kernel_image kernel_headers
} }
# List packages by size
function apt-list-packages {
dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | \
grep -v deinstall | \
sort -n | \
awk '{print $1" "$2}'
}
##
# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories
# that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT.
#
dirhistory_past=(`pwd`)
dirhistory_future=()
export dirhistory_past
export dirhistory_future
export DIRHISTORY_SIZE=30
# Pop the last element of dirhistory_past.
# Pass the name of the variable to return the result in.
# Returns the element if the array was not empty,
# otherwise returns empty string.
function pop_past() {
eval "$1='$dirhistory_past[$#dirhistory_past]'"
if [[ $#dirhistory_past -gt 0 ]]; then
dirhistory_past[$#dirhistory_past]=()
fi
}
function pop_future() {
eval "$1='$dirhistory_future[$#dirhistory_future]'"
if [[ $#dirhistory_future -gt 0 ]]; then
dirhistory_future[$#dirhistory_future]=()
fi
}
# Push a new element onto the end of dirhistory_past. If the size of the array
# is >= DIRHISTORY_SIZE, the array is shifted
function push_past() {
if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then
shift dirhistory_past
fi
if [[ $#dirhistory_past -eq 0 || $dirhistory_past[$#dirhistory_past] != "$1" ]]; then
dirhistory_past+=($1)
fi
}
function push_future() {
if [[ $#dirhistory_future -ge $DIRHISTORY_SIZE ]]; then
shift dirhistory_future
fi
if [[ $#dirhistory_future -eq 0 || $dirhistory_futuret[$#dirhistory_future] != "$1" ]]; then
dirhistory_future+=($1)
fi
}
# Called by zsh when directory changes
function chpwd() {
push_past `pwd`
# If DIRHISTORY_CD is not set...
if [[ -z "${DIRHISTORY_CD+x}" ]]; then
# ... clear future.
dirhistory_future=()
fi
}
function dirhistory_cd(){
DIRHISTORY_CD="1"
cd $1
unset DIRHISTORY_CD
}
# Move backward in directory history
function dirhistory_back() {
local cw=""
local d=""
# Last element in dirhistory_past is the cwd.
pop_past cw
if [[ "" == "$cw" ]]; then
# Someone overwrote our variable. Recover it.
dirhistory_past=(`pwd`)
return
fi
pop_past d
if [[ "" != "$d" ]]; then
dirhistory_cd $d
push_future $cw
else
push_past $cw
fi
}
# Move forward in directory history
function dirhistory_forward() {
local d=""
pop_future d
if [[ "" != "$d" ]]; then
dirhistory_cd $d
push_past $d
fi
}
# Bind keys to history navigation
function dirhistory_zle_dirhistory_back() {
# Erase current line in buffer
zle kill-buffer
dirhistory_back
zle accept-line
}
function dirhistory_zle_dirhistory_future() {
# Erase current line in buffer
zle kill-buffer
dirhistory_forward
zle accept-line
}
zle -N dirhistory_zle_dirhistory_back
# xterm in normal mode
bindkey "\e[3D" dirhistory_zle_dirhistory_back
bindkey "\e[1;3D" dirhistory_zle_dirhistory_back
# Putty:
bindkey "\e\e[D" dirhistory_zle_dirhistory_back
# GNU screen:
bindkey "\eO3D" dirhistory_zle_dirhistory_back
zle -N dirhistory_zle_dirhistory_future
bindkey "\e[3C" dirhistory_zle_dirhistory_future
bindkey "\e[1;3C" dirhistory_zle_dirhistory_future
bindkey "\e\e[C" dirhistory_zle_dirhistory_future
bindkey "\eO3C" dirhistory_zle_dirhistory_future
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment