Mercurial > hg > cc > cirrus_home
diff .bash_extras @ 157:cac9586291ad
no more gentoo,
split out functions into .bash_extras
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 04 Jul 2022 18:14:41 +0100 |
parents | |
children | acae526510e2 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.bash_extras Mon Jul 04 18:14:41 2022 +0100 @@ -0,0 +1,82 @@ +# Sourced by .bashrc + +cu () +{ + cvs update "$@" | egrep -v '^\?' +} + +lss () +{ + /bin/ls -l "$@" | sort -nr -k 5 +} + +ff () +{ + pat=$1; + shift; + find . -iname "*$pat*" $@ +} + +typecat () +{ + tt=$(type $1); + case $tt in + *\ is\ hashed\ *) + cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') + ;; + *\ is\ /*) + cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') + ;; + *) + type $1 + ;; + esac +} + +sus () +{ + sort "$@" | uniq -c | sort -k1nr,1 +} + +uz () +{ + igzip -dc "$@" +} + + +function typecat () +{ + tt=$(type $1) + case $tt in + *\ is\ hashed\ *) cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') ;; + *\ is\ /*) cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') ;; + *) type $1 ;; + esac +} + +function tot () +{ + awk '{sum+=$1} END {printf "%u\n",sum}' +} + +btot () +{ + python3 -c 'import sys +commas = False +if len(sys.argv)>1: + if sys.argv[1]=="-c": + commas = True +n=0 +for l in sys.stdin: + try: + n+=int(l) + except ValueError as e: + print(e,file=sys.stderr) +if commas: + print(f"{n:,}") +else: + print(n) +' "$@" +} + +export -f cu lss ff typecat sus uz tot btot