annotate .bash_extras @ 181:55169996c3bf

add support for multiple calls to srun with a counter
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Fri, 21 Jul 2023 11:38:20 +0100
parents cac9586291ad
children acae526510e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
157
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 # Sourced by .bashrc
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 cu ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 cvs update "$@" | egrep -v '^\?'
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 lss ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 /bin/ls -l "$@" | sort -nr -k 5
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13 ff ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 pat=$1;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 shift;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 find . -iname "*$pat*" $@
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 typecat ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 tt=$(type $1);
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23 case $tt in
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 *\ is\ hashed\ *)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()')
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 ;;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 *\ is\ /*)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
28 cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()')
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
29 ;;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
30 *)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
31 type $1
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 ;;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
33 esac
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
34 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
35
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
36 sus ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
37 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
38 sort "$@" | uniq -c | sort -k1nr,1
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
39 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
40
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
41 uz ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
42 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
43 igzip -dc "$@"
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
44 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
45
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
46
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 function typecat ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
49 tt=$(type $1)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50 case $tt in
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
51 *\ is\ hashed\ *) cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') ;;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
52 *\ is\ /*) cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') ;;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
53 *) type $1 ;;
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
54 esac
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
55 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
56
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
57 function tot ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
58 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
59 awk '{sum+=$1} END {printf "%u\n",sum}'
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
60 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
61
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
62 btot ()
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
63 {
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
64 python3 -c 'import sys
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
65 commas = False
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
66 if len(sys.argv)>1:
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
67 if sys.argv[1]=="-c":
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
68 commas = True
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
69 n=0
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
70 for l in sys.stdin:
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
71 try:
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
72 n+=int(l)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
73 except ValueError as e:
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
74 print(e,file=sys.stderr)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
75 if commas:
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
76 print(f"{n:,}")
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
77 else:
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
78 print(n)
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
79 ' "$@"
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
80 }
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
81
cac9586291ad no more gentoo,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
82 export -f cu lss ff typecat sus uz tot btot