Zsh Utilities Modules

This is part of the Zsh Utilities.

Zsh Utilities - Modules

This file adds some configuration to external resources. Each program configuration is done item per item. The preamble is just here to ensure the binary is present. Thus each item is embedded between a preamble and postamble block code which is a basic if command.

dotfiles

dotfiles is a tool to make managing your dotfile symlinks in $HOME easy, allowing you to keep all your dotfiles in a single directory.

Preamble

if (( $+commands[dotfiles] )); then

Aliases

alias dotfiles='dotfiles -R ~/Development/dotfiles'

Postamble

fi

fasd

fasd is a command-line productivity booster, offers quick access to files and directories, inspired by autojump, z and v. Most of the following code is stolen from prezto.

Preamble

if (( $+commands[fasd] )); then

Initialization

  cache_file="${HOME}/.config/zsh/tmp/fasd_cache.zsh"
  if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then
    # Set the base init arguments.
    init_args=(zsh-hook)

    # Set fasd completion init arguments, if applicable.
#    if zstyle -t ':prezto:module:completion' loaded; then
      init_args+=(zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install)
#    fi

    # Cache init code.
    fasd --init "$init_args[@]" >! "$cache_file" 2> /dev/null
  fi
  source "$cache_file"
  unset cache_file init_args

Additional function for fast cd

function fasd_cd {
  local fasd_ret="$(fasd -d "$@")"
  if [[ -d "$fasd_ret" ]]; then
    cd "$fasd_ret"
  else
    print "$fasd_ret"
  fi
}

Aliases

  • Change the current working directory interactively
    alias j='fasd_cd -i'
    

Postamble

fi

rsync

rsync is an open source utility that provides fast incremental file transfer

Preamble

if (( $+commands[rsync] )); then

Aliases

alias rsync='noglob rsync'
_rsync_cmd='rsync --verbose --progress --human-readable --compress --archive --hard-links --one-file-system'

alias rsync-copy="${_rsync_cmd}"
alias rsync-move="${_rsync_cmd} --remove-source-files"
alias rsync-update="${_rsync_cmd} --update"
alias rsync-synchronize="${_rsync_cmd} --update --delete"

unset _rsync_cmd

Postamble

fi

colout

colout read lines of text stream on the standard input and output characters matching a given regular expression pattern in given and style: style may be colored bold strings, for instance.

Preamble

if (( $+commands[colout] )); then

Function

function cm ()
{
    $@ 2>&1 | colout "\[(?i)notice.*$|\[information.*$|\[INFO.*$" 4 \ |
    colout "\[(?i)error.*$|\[fatal.*$|erreur.*$|FAILED.*$" 1 \ |
    colout "\[(?i)warning.*$|attention.*$" 5 \ |
    colout "\[(?i)debug.*$" 2 normal |
    colout "\[(?i)trace.*$|DEVEL:.*$" 28 normal |
    colout ".*\|.*|\|\-\-.*|\`.*" 3 normal
}

Postamble

fi

mr

Preamble

if (( $+commands[mr] )); then

Function

function mr ()
{
    last=~/${@[-1]}
    if [ -d $last ]; then
        (
            cd $last
            $(pkgtools__get_binary_path $0) ${@:1:-1}
        )
    else
        $(pkgtools__get_binary_path $0) $@
    fi
}

Postamble

fi

plan

plan is a python package for writing and deploying cron jobs. plan will convert python code to cron syntax.

Cron syntax

from plan import Plan

cron = Plan()

cron.command('DISPLAY=:0 /home/garrido/.config/openbox/scripts/change-wallpaper', every='15.minute')
if __name__ == '__main__':
    cron.run('update')
File under version control - commit b7f7874 - 2014-11-07