Manuel Amago: ProfileFunctions

Making life taste better…


Page actions: RecentChanges | PrintableView | PageHistory | EditPage



 
#
# Navigation
#
export MARKPATH=$HOME/.marks
function go {
    if [[ ! -e "$MARKPATH/$1" ]]; then
        echo "No such mark: $1"
    elif [[ -h "$MARKPATH/$1" ]]; then
        pushd $(readlink -f "$MARKPATH/$1") 2>/dev/null
    elif [[ -x "$MARKPATH/$1" ]]; then
        local cmd="$MARKPATH/$1"
        shift
        . $cmd $@
    fi
}
function mark {
    mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
}
function unmark {
    rm "$MARKPATH/$1"
}
function marks {
    for f in "$MARKPATH"/*; do
        local name="$(basename "$f")"
        if [[ -h "$f" ]]; then
            local target="$(readlink -f "$f")"
            echo "${name} -> ${target}"
        elif [[ -x "$f" ]]; then
            echo "${name}*"
        fi
    done
}
# Tab completion
_completemarks() {
  local curw=${COMP_WORDS[COMP_CWORD]}
  local wordlist=$(ls -p $MARKPATH)
  local IFS=$'\n'
  COMPREPLY=($(compgen -W "${wordlist[@]}" -- "$curw"))
  return 0
}

complete -o filenames -F _completemarks go unmark

#
# Fun
#
alias rmatrix='echo -ne "\e[31m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done'
alias gmatrix='echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done'


Page actions: RecentChanges | PrintableView | PageHistory | EditPage