#!/bin/sh # Shows the date for "fri week" or "mon last" for e.g. # License: LGPLv2 proc Usage { echo "Usage: $[basename $0] mon|tue|... [next]|week|last" > !2 exit 1 } test "$Argc" -eq "0" && Usage global day := $1 global which := $2 test -z $which && global which := 'next' matchstr $which { week { if test $[date +%D] = $[date --date="next $day" +%D] { global weeks := '+2' #assume we want the next week, not today } else { global weeks := '+1' } } last { global weeks := '-1'} next { if test $[date +%D] = $[date --date="next $day" +%D] { global weeks := '+1' #assume we want the next week, not today } else { global weeks := '+0' } } * { Usage} } date --date="$day $weeks weeks" +%x (CommandList children: [ (FuncDef name: Usage body: (BraceGroup children: [ (SimpleCommand words: [ {(echo)} { (DQ ("Usage: ") (CommandSubPart command_list: (CommandList children:[(C {(basename)} {($ VSub_Number "$0")})]) left_token: spids: [24 28] ) (" mon|tue|... [next]|week|last") ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[32])] ) (C {(exit)} {(1)}) ] spids: [17] ) spids: [12 16] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Pound "$#"))} {(-eq)} {(DQ (0))} {(Lit_Other "]")}) (C {(Usage)}) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:day) op:Equal rhs:{($ VSub_Number "$1")} spids:[62])] spids: [62] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:which) op:Equal rhs:{($ VSub_Number "$2")} spids:[65])] spids: [65] ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$which"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:which) op:Equal rhs:{(next)} spids:[80])] spids: [80] ) ] op_id: Op_DAmp ) (Case to_match: {($ VSub_Name "$which")} arms: [ (case_arm pat_list: [{(week)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} { (CommandSubPart command_list: (CommandList children: [(C {(date)} {(Lit_Other "+") (Lit_Other "%") (D)})] ) left_token: spids: [98 104] ) } {(Lit_Other "=")} { (CommandSubPart command_list: (CommandList children: [ (C {(date)} {(--date) (Lit_Other "=") (DQ ("next ") ($ VSub_Name "$day"))} {(Lit_Other "+") (Lit_Other "%") (D)} ) ] ) left_token: spids: [108 121] ) } {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:weeks) op: Equal rhs: {(Lit_Other "+") (2)} spids: [129] ) ] spids: [129] ) ] spids: [-1 126] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:weeks) op: Equal rhs: {(Lit_Other "+") (1)} spids: [140] ) ] spids: [140] ) ] spids: [137 145] ) ] spids: [90 91 147 -1] ) (case_arm pat_list: [{(last)}] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:weeks) op:Equal rhs:{(-1)} spids:[153])] spids: [153] ) ] spids: [149 150 155 -1] ) (case_arm pat_list: [{(next)}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} { (CommandSubPart command_list: (CommandList children: [(C {(date)} {(Lit_Other "+") (Lit_Other "%") (D)})] ) left_token: spids: [165 171] ) } {(Lit_Other "=")} { (CommandSubPart command_list: (CommandList children: [ (C {(date)} {(--date) (Lit_Other "=") (DQ ("next ") ($ VSub_Name "$day"))} {(Lit_Other "+") (Lit_Other "%") (D)} ) ] ) left_token: spids: [175 188] ) } {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:weeks) op: Equal rhs: {(Lit_Other "+") (1)} spids: [196] ) ] spids: [196] ) ] spids: [-1 193] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:weeks) op: Equal rhs: {(Lit_Other "+") (0)} spids: [207] ) ] spids: [207] ) ] spids: [204 212] ) ] spids: [157 158 214 -1] ) (case_arm pat_list:[{(Lit_Other "*")}] action:[(C {(Usage)})] spids:[216217221-1]) ] spids: [84 88 223] ) (C {(date)} {(--date) (Lit_Other "=") (DQ ($ VSub_Name "$day") (" ") ($ VSub_Name "$weeks") (" weeks"))} {(Lit_Other "+") (Lit_Other "%") (x)} ) ] )