#!/bin/zsh ################################################################################# # daily use aliases ##############################################################################{{{ alias ls="ls --group-directories-first -N --color=auto" alias ll="ls -hl" alias lll="ls -hla" alias ds="du -sh" alias :q="exit" alias rget="rsync -rP --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 fd() { if [[ "$1" =~ "-*" ]]; then echo "fd not installed. shell alias supports only basic operation" return 1 fi noglob find . -iname "*${*}*" } fi alias sudo="sudo " alias S='sudo $(history -n -1)' alias rm="rm -I" function v() { xdg-open "$@" &| } alias vmemcache="vmtouch -l -m 12G -v" fork() { "$@" &>/dev/null &| } alias en="dict.cc.py de en" alias de="dict.cc.py en de" su() { if [[ -z "$@" ]]; then echo "Switching to sudo -s for enviromental reasons" sudo -s else command su "$@" fi } loadgroup() { if [[ -z $1 ]]; then echo "Usage: loadgroup " return 1 fi exec sg $1 newgrp $(id -gn) } #}}} ################################################################################# # zsh stuff ##############################################################################{{{ alias histoff="HISTFILE=/dev/null" alias histon="HISTFILE=$HOME/.histfile" E() { if [[ -n $(jobs) ]]; then echo "exec: You have suspended jobs." else builtin exec zsh fi } # edit and refresh aliases aliases() { $EDITOR $(zdotfile aliases/${1:-functions}) . $(zdotfile aliases)/* } # per directory configuration cd(){ if [ -e ".zout" ]; then . "./.zout" fi builtin cd $* if [ -e ".zin" ]; then . "./.zin" fi } #}}} ################################################################################# # filesystem stuff ##############################################################################{{{ # 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 } dl-source() { for file in "$@"; do getfattr --only-values -n user.xdg.origin.url "$file" 2>/dev/null && echo || echo "$file: no download source info" >&2 done } receive-subvolume() { nc -c -l -p $2 | btrfs receive -ve $1 } send-subvolume() { btrfs property set $1 ro true; btrfs send -v $1 | pv | nc -c nashorn.fritz.box $2 } #}}} ################################################################################# # 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() { revolver start for i in ${*:-(#i)*.(JPG|CR[23]|DNG)(N)}; do if [[ -e $i ]]; then revolver update $i dir=$(exiftool -p '$DateTimeOriginal' $i | tr ':' '-' | cut -d' ' -f1;) mkdir -p $dir mv ${i:r}.* $dir fi done revolver stop } 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 ##############################################################################{{{ 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} } alias jdl="docopen $HOME/.jails/*/Downloads" alias vcat="nvimpager -c" # vim: foldmethod=marker