-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailmonth
executable file
·82 lines (73 loc) · 2.31 KB
/
mailmonth
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
#
# mailmonth - outputs a mail folder name for X months ago
# Copyright (C) 2000,2001 Chris Gushue <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the license, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: mailmonth,v 1.8 2001/01/03 15:45:07 seymour Exp $
# I made this little shell script so I wouldn't have to keep changing
# the monthly mail folders for Mutt (used in conjunction with my procmail
# scripts, available from the place you obtained this script) manually.
#
# eg. "./mailmonth 2" will display the folder for two months ago
# "./mailmonth 1" will display the folder for last month
# "./mailmonth" will display the folder for the current month
#
# To be used in .muttrc as follows:
#
# mailboxes +`~/.mutt/mailmonth`/Inbox
# mailboxes +`~/.mutt/mailmonth 2`
# mailboxes +`~/.mutt/mailmonth 1`
#
# Visit http://mutt.lazygenes.net for more of my Mutt stuff
GNUDATE="yes" # Change to "no" if you aren't using the GNU date util
# pour mettre un mois/annee particuliere
#echo "2010/08"
#exit 0
if [ $# -eq 0 ]; then
echo `date +%Y/%m`
else
if [ $GNUDATE = "yes" ]; then
echo `date -d "$1 months ago" +%Y/%m`
else
echo `date -v -$1m +"%Y/%m"`
fi
fi
exit 0
## ** This method has problems still **
# Method which doesn't rely on GNU date, thanks to BinarySoul <[email protected]>
m=`date +%m`
y=`date +%Y`
if [ $# -eq 0 ] ; then
dt="$y/$m"
else
d=$1
m=$(($m - $d))
if [ $m -eq 0 ] ; then
m=12
y=$(($y - 1))
elif [ $m -lt 0 -a $m -gt -12 ] ; then
m=$((12 - $d + 1))
y=$(($y - 1))
elif [ $m -le -12 ] ; then
m=$(( $m * -1))
y2=$(( $m/12 - 1 ))
y=$(( $y - $y2 ))
m=$(( 12 - ($m%12) ))
fi
dt="$y/$m"
fi
echo $dt