]>
code.delx.au - gnu-emacs-elpa/blob - packages/notes-mode/notesinit
5 # Copyright (C) 1996-2002,2012 Free Software Foundation, Inc.
6 # $Id: notesinit,v 1.12 2006/01/14 22:52:56 johnh Exp $
13 This program sets up notes mode for the first time.
14 It typically runs interactively.
17 -D use all defaults (also turns off prompting)
27 &GetOptions
(\
%opts, qw(D));
28 &usage
if ($#ARGV >= 0 && $ARGV[0] eq '-?');
29 my($use_defaults) = defined($opts{'D'});
31 my($PERL) = $^X
; # location of perl executable
35 BEGIN { unshift(@INC, $ENV{'NOTES_BIN_DIR'}); };
42 if ($_[0] eq '-nolc') {
46 my($expl, $query, $valid_regexp, $default) = @_;
47 return $default if ($use_defaults);
55 return $default if ($a eq '');
56 return $a if ($a =~ /$valid_regexp/);
57 print "I didn't understand your answer `$a'.\n";
63 notesinit will set up notes-mode for the first time.
65 What is notes mode? Texinfo documentation should be installed on your
66 system. Documentation is also available on the web at
67 <http://www.isi.edu/~johnh/SOFTWARE/NOTES_MODE/>. Everything you will
68 be asked here is discussed in greater detail in the documentation.
72 my($home_dir) = ((getpwuid($<))[7]);
73 my($def_choices, $def) = ('(Y/n)', 'y');
74 if (-f
"$home_dir/.notesrc") {
75 die "$0: will not override existing .notesrc with -D option.\n"
77 ($def_choices, $def) = ('(y/N)', 'n');
78 print "WARNING: you already appear to have notes configured.\n\n"
81 my($a) = query
($expl, "Do you want to set up notes mode now $def_choices? ", '(y|n)', $def);
83 print "\nnotesinit exited.\n\n";
89 Notes are stored in two-level hierarchy of directories.
92 ^^^^^^-- a notes file (the date, in YYMMDD)
93 ^^^^^^--------- one subdirectory per month (form: YYYYMM)
94 ^^^^^---------------- the parent directory of everything
97 $::notes
{dir
} = query
("-nolc", $expl, "What should the parent directory be (default: ~/NOTES)? ", '.', '~/NOTES');
98 # fix ~ (in honor of Cliffette's "yes, I have no tilde")
99 $::notes
{dir_notilde
} = $::notes
{dir
};
100 $::notes
{dir_notilde
} =~ s@
^~/@$home_dir/@
;
101 $::notes
{dir
} =~ s@
^$home_dir/@~/@
;
105 my($today_pathname) = epoch_to_pathname
($now);
109 notesinit can now set-up your environment for notes.
110 It will take the following steps:
112 0. set up your .notesrc
113 1. create $::notes{dir}
114 2. create a sample note for today ($today_pathname)
115 3. index the default note
116 4. set up a crontab entry to re-index notes at 4am every morning
120 ($def_choices, $def) = ('(M/d/s)', 'm');
121 ($def_choices, $def) = ('(m/D/s)', 'd') if (-f
"$home_dir/.notesrc");
122 my($go) = query
($expl, "Make these changes, describe the changes, or stop $def_choices? ", '[mds]', $def);
123 exit 1 if ($go eq 's');
126 my($expl, $cmd) = @_;
127 print $expl if (!$use_defaults);
136 # Ok, the code below is less-than-ideal.
137 # It's somewhat silly to have Perl output the shell commands
138 # rather than just "do it".
139 # The reason is that we to allow the user to look at what's being done.
142 $expl = "\n### changes begin here\n" .
143 "\n### 0. set up your .notesrc\n";
144 commands
($expl, "cat >$home_dir/.notesrc <<END
149 $expl = "\n### 1. creating $::notes{dir}\n";
150 commands
($expl, "mkdir -p $::notes{dir_notilde};\nchmod 0700 $::notes{dir_notilde}\n");
152 my($heading) = strftime_epoch
("%d-%b-%y %A", $now);
153 my($underline) = "-" x
length($heading);
154 $expl = "\n### 2. create a sample note for today ($today_pathname)\n";
155 commands
($expl, "mkdir -p `dirname $today_pathname`;\n cat >$today_pathname <<END
163 to do list goes here?
169 Set up notes with notesinit.
171 (To read the manual, run info notes-mode .)
176 my($mkall) = $PERL . " " . $::notes{bin_dir} . "/mkall
";
177 my($crontab_entry) = "0 4 * * * $mkall";
179 $expl = "\n### 3. index the default note\n";
180 commands
($expl, $mkall);
182 $expl = "\n### 4. set up a crontab entry to re-index notes at 4am every morning\n";
183 my($tmpfile) = "$home_dir/notesinit.$$~";
184 # this whole touch thing is to avoid leaving a globally writable crontab
185 commands
($expl, "touch $tmpfile;
187 echo 'If you do not have a crontab, errors about not being able to open a cron table can be ignored.';
188 crontab -l | sed 's/^\\(.*\\/mkall\\)\$/# \\1/' >>$tmpfile;
189 echo '$crontab_entry' >>$tmpfile;
190 " . $::notes
{bin_dir
} . "/setcrontab $tmpfile
193 print "\n### changes end here\n" if (!$use_defaults);
195 print "\nYou have elected to have the changes DESCRIBED but not made.\n" .
196 "To make the changes yourself, run the commands between\n" .
197 "\"changes begin here\" and \"changes end here\".\n"