#!/bin/sh # Set modification date of the current (or specified) directory # to the earliest file in that directory. # # License: LGPLv2 # # I use this when I don't want to record when I (re)filed something, # and would like the directories to be ordered by date of the contents. # Digital camera pictures is usually what I use this for. test -z $1 && set "." global file := $[find $1 -maxdepth 1 -type f -printf "%p\t%T@\n" | sort -k2,2n | head -1 | cut -f1] test -z $file && exit global filedate := $[date --reference="$file" +%y%m%d%H%M] touch -c -t $filedate $1 (CommandList children: [ (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "]")}) (C {(set)} {(DQ (.))}) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(find)} {($ VSub_Number "$1")} {(-maxdepth)} {(1)} {(-type)} {(f)} {(-printf)} { (DQ ("%p") (EscapedLiteralPart token:) ("%T@") (EscapedLiteralPart token: ) ) } ) (C {(sort)} {(-k2) (Lit_Comma ",") (2n)}) (C {(head)} {(-1)}) (C {(cut)} {(-f1)}) ] negated: False ) ] ) left_token: spids: [48 89] ) } spids: [47] ) ] spids: [47] ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$file"))} {(Lit_Other "]")}) (C {(exit)}) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:filedate) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(date)} {(--reference) (Lit_Other "=") (DQ ($ VSub_Name "$file"))} {(Lit_Other "+") (Lit_Other "%") (y) (Lit_Other "%") (m) (Lit_Other "%") (d) (Lit_Other "%") (H) (Lit_Other "%") (M) } ) ] ) left_token: spids: [106 126] ) } spids: [105] ) ] spids: [105] ) (C {(touch)} {(-c)} {(-t)} {($ VSub_Name "$filedate")} {($ VSub_Number "$1")}) ] )