#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/ide coders () { local log=$1 egrep '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}\s' $log | cut -d ' ' -f3- | sort -u } find-duplicate-lines () { local file=$1 cat $file | sort | uniq -d } alias dups=find-duplicate-lines bogus-file () { local file=${1:-100.data} rm $file dd if=/dev/urandom \ of=$file \ count=$(( 1024 * 100 )) \ bs=1024 | sha256sum | ( read rnd _; echo $rnd >> $file ) } create-bogus-file () { local file=$1 local lines=$2 rm -r $file for l in {0..$lines}; do dd if=/dev/urandom count=1 2> /dev/null | sha256sum | ( read rnd _; echo $rnd >> $file ) done } alias cbf=create-bogus-file last-cmd () { history | tail -n 1 | cut -d ' ' -f 5- } indent-files () { local files=() for f in $@; do files+=\"$f\" done emacs -Q --batch -l cl --eval " (dolist (filename (list $files)) (find-file filename) (indent-region (point-min) (point-max)) (save-buffer) (kill-buffer) )" } # make alias make='make -s -j -k' alias ma='make all' alias maa='make again' emake () { local emacs_path=~/.emacs.d/emacs-init make $@ -C ${emacs_path} } alias em='emake' alias ema='emake again' # scripts cats () { local file=~/scripts/$1 [[ -f $file ]] && cat $file } # 't' is an extention of zsh's 'whence' ("t" # for "type"). It outputs what file the # function or alias is defined, and it uses # 'whence' to output the definition or code. # If the argument command is a script, 't' uses # 'cats' ("catenate script") to output it. t () { if [[ $# == 0 ]]; then echo "syntax: $0 COMMAND" >&2 return fi local cmd=$1 find-zsh-command $cmd # use whence; if a path, do 'ls' local whence_hits whence_hits=("${(@f)${$(whence -ca $cmd)//$HOME/~}}") local h for h in $whence_hits; do echo $h ls -Ghl --color=auto $h 2> /dev/null if [ -h $h ]; then local dest=$(readlink -e $h) set-fg-color 3 echo -n " * links to: " reset-color echo -n $dest '\n ' ls -Ghl --color=auto $dest fi done # if a script, output it cats $cmd }