view .bash_extras @ 175:d123ef7fdb82

working on implementing types and parts: 1, 2, 4 working, 3 not
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 03 Jul 2023 18:16:14 +0100
parents cac9586291ad
children acae526510e2
line wrap: on
line source

# 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