-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreck
executable file
·59 lines (44 loc) · 1.99 KB
/
freck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Force Bash, so we have 'let' for addition
# Freck - "To move swiftly or nimbly."
# http://matadornetwork.com/abroad/20-obsolete-english-words-that-should-make-a-comeback/
VERSION="0.02"
# 0.01 Works!
# 0.02 Uses find + moves [[:upper:]] files to subdir.
echo "If you knew Time as well as I do, said the Hatter, you wouldn't talk about wasting IT. It's HIM."
# Following lines keep a running count in a hidden file .count in the present directory...
count=` cat .count `
let count=count+1
echo $count > .count
# Format this as 0002 etc. ; pad to 4 digits with awk/printf
prefix=` echo $count | awk '{printf("%04d",$1)}' `
# Request name for this set of calcs / data
echo "OK; going to bundle & rename to (please enter...):"
echo -n "${prefix}-"
read suffix
# Glob together for use from this point on
newdir="${prefix}-${suffix}"
# Should look like "0004-MY_wicked_calculations"
echo -n "Making directory ${newdir} ..."
mkdir "${newdir}"
echo "Moving files to ${newdir}..."
#mv *.* "${newdir}" # Standard files
find ./ -maxdepth 1 -name "*.*" -not -name ".*" -type f -print0 | xargs -0 -I {} mv {} "${newdir}"
find ./ -maxdepth 1 -name "[[:upper:]]*" -type f -print0 | xargs -0 -I {} mv {} "${newdir}"
# find ./ -maxdepth 1 -name "[[:upper:]]*" -type f # something like this + then mv
#mv [A-Z] "${newdir}" # VASP and other Fortran programmes ALLCAPS output files (no extension)
# Automatic logging - would like to add a lot more...
echo "Leaving breadcrumbs..."
crumb="${newdir}/`date +%Y-%m-%d_%H%S`_${USER}_at_${HOSTNAME}"
touch "${crumb}"
cat > ${crumb} << EOF
#Archived with Freck Version ${VERSION}...
# Still not able to extract history
pwd: ` pwd `
date: ` date `
hostname: `hostname `
EOF
# Doesn't work currently - we're in a sub shell (~:
# Nice things to do with permanently changing .bashrc to adjust history defaults, which might be an idea anyway...
# HISTFILE="${newdir}"/`date +%Y-%m-%d`_${USER}_at_${HOSTNAME}.dat
# history -a # Dump history saved in memory (i.e. this shell)