#!/bin/zsh ################################################################################# # daily use aliases ##############################################################################{{{ alias ls="ls -N --color=auto" alias ll="ls -hl --group-directories-first" alias lll="ls -hla" alias ds="du -sh" alias :q="exit" alias rget="rsync -rvP --append-verify --inplace" alias 7zu="7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on" if command -v fd >/dev/null; then alias f="fd" else f() { noglob find . -iname "*${*}*" } fi alias sudo="sudo " alias S='sudo $(history -n -1)' alias rm="rm -I" alias v="xdg-open" fork() { ( $* &>/dev/null & ) } alias en="dict.cc.py de en" alias de="dict.cc.py en de" #}}} ################################################################################# # zsh stuff ##############################################################################{{{ alias histoff="HISTFILE=/dev/null" alias histon="HISTFILE=$HOME/.histfile" alias E="exec zsh" # edit and refresh aliases aliases() { sudoedit /etc/zsh/aliases/${1:-functions} . /etc/zsh/aliases/* } # per directory configuration cd(){ if [ -e ".zout" ]; then . "./.zout" fi builtin cd $* if [ -e ".zin" ]; then . "./.zin" fi } #}}} ################################################################################# # filesystem stuff ##############################################################################{{{ t=${TAGSISTANT_ROOT:-$HOME/tagged}/store tagmount() { tagsistant ${TAGSISTANT_ROOT:-$HOME/tagged} &>/tmp/tagsistant.$USER } tag() { if [[ -z $2 ]]; then printf "%s\n" \ "Usage: tag FILE... [-n name] [-v] [-p] TAG..." \ "" \ "Each TAG must end with the @ delimiter component." \ "Each File must have a name different from a single @" return 1 fi local name preview zparseopts -D -E n:=name -name:=name p=preview -preview=preview \ v=verbose -verbose=verbose local sources=() local tags=() for i in "${@}"; do if [[ ${i:t} == "@" ]]; then tags+=${i} else sources+=${i:A} fi done for source in "${sources[@]}"; do for tag in "${tags[@]}"; do target=~t/$tag if [[ ! -d $target ]]; then mkdir -p $target; fi if [[ -n $verbose ]]; then echo "Tagging $source with $tag"; fi ${=preview:+echo} ln -s $source $target/${name[2]} done done } papertag() { if [[ -z $2 ]]; then echo "Usage: papertag FILE [-v] [-y YEAR] [AUTHOR...] [:: OTHER TAGS]" return 1 fi local year zparseopts -D -E y:=year -year:=year \ v=verbose -verbose=verbose local paper=$1; shift tag $verbose $paper paper/@ if [[ -n "$year" ]]; then tag $verbose $paper meta:/year/eq/${year[2]}/@/ fi while [[ -n $1 ]]; do local author=$1; shift if [[ "$author" == "::" ]]; then break; fi tag $verbose $paper meta:/author/eq/$author/@ done for tag in "$@"; do tag $verbose $paper $tag done } tcd() { rpath=$(realpath ~t/$1) if [[ -d $rpath ]]; then cd $rpath; else cd ${rpath:h} fi } # count files in current or given directory count() { find $1 \( ! -path '*/.*' \) | wc -l } pumount() { params=() while [[ "${1[1]}" == "-" ]]; do params+="$1" shift done if [[ "${1[1]}" == "/" ]]; then command pumount "${params[@]}" "$1" else command pumount "${params[@]}" "/media/$1" fi } #}}} ################################################################################# # filename manipulation ##############################################################################{{{ alias cleanspaces="renamexm -s/\ /_/g -R" # prefix all given files with first argument to this function prefix() { pre=$1;shift for i in $*; do mv $i $pre$i;done } # prefix all given files with consecutive numbers, starting with 1 # or with number given by -s switch (must be first argument) prenumbering() { if [[ "$1" == "-s" ]]; then n=${2}; shift 2 else n=1 fi for i in "$@"; do mv $i ${(l:2::0:)n}_$i; ((n++)); done } # appends given suffix (first argument) suffix() { suf=$1;shift for i in $*; do mv $i $i$suf;done } #}}} ################################################################################# # audio video photo ##############################################################################{{{ alias exifcopy="exiftool -tagsFromFile" photobydate() { for i in ${*:-(#i)*.(JPG|CR2)}; do if [[ -e $i ]]; then dir=$(exiftool -p '$DateTimeOriginal' $i | tr ':' '-' | cut -d' ' -f1;) mkdir -p $dir mv ${i:r}.* $dir fi done } alias mkvidentify="mkvmerge --identify" cropdetect() { ffmpeg -ss ${2:-00:05:00} -t 1 -i "${1}" -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1 } #}}} ################################################################################# # programming ##############################################################################{{{ # watch latex file for changes and rebuild latexwatch() { maindoc=$1 while : ; do inotifywait -e modify $*; pdflatex -halt-on-error $maindoc done } svn() { case $1 in log|diff) command svn "$@" | $PAGER ;; *) command svn "$@" ;; esac } alias gitv='vim "$(git rev-parse --git-dir)/index" -c "Gitv --all" -c tabonly' #}}} ################################################################################# # noglobs ##############################################################################{{{ alias ri=noglob\ ri alias wcalc="noglob wcalc" #}}} ################################################################################# # tmux ##############################################################################{{{ tdetachprep() { env -i tmux new-session -d -s detached &>/dev/null } alias :u="tmux select-pane -U" alias :d="tmux select-pane -D" alias :l="tmux select-pane -L" alias :r="tmux select-pane -R" alias :split="tmux splitw -v" alias :vsplit="tmux splitw -h" alias :detachw="tdetachprep; tmux movew -t detached: -s" alias :attachw="tdetachprep; tmux movew -t : -s" #}}} ################################################################################# # btrfs ##############################################################################{{{ btrfs-subvolume-force-delete() { btrfs property set "$1" ro false btrfs subvolume delete "$1" } #}}} # ################################################################################# # global and suffix aliases ##############################################################################{{{ # lazy shortcuts alias -g G="| grep" alias -g L="| less" alias -g T="| tail" # xclipboard alias -g XS='$(xclip -o -selection primary)' alias -g XC='$(xclip -o -selection clipboard)' alias -s log=vimpager #}}} ################################################################################# # various small scripts ##############################################################################{{{ urlencode() { local input setopt extendedglob if [ -n "$1" ]; then input="$*" else input=$( [remote_port]" return fi local host="$1"; local port="$2"; local remote_port="${3:-$2}" ssh -L $port:$host:$remote_port fasel -N & } tmpssh() { dir=/tmp/${${1#*:}:t} mkdir -p ${dir} sshfs $1 ${dir} cd ${dir} } # vim: foldmethod=marker