2 ###APPNAME: zim-add-entry
4 ###APPDATE: 2008-05-11 14:27:04
6 ###APPDESC: add a link entry to a zim txt file
7 ###APPUSAGE: [--read] [--test] (entry Name) [entry Location] [entry Description] [destination]
8 ###APPEXAMPLE: zim-add-entry Test .test abc.txt
9 ###APPOPTION: --read:Append text to entry from STDIN|--test:No writing will be made
13 #ENV variable MUST be defined somewhere,
14 #FOR perl to search modules from,
16 use lib
$ENV{XR_PERL_MODULE_DIR
};
18 use MyPlace
::Script
::Usage qw
/help_required help_even_empty/;
19 exit 0 if(help_even_empty
($0,@ARGV));
24 if($ARGV[0] eq "--read") {
28 elsif($ARGV[0] eq "--test") {
33 if($ARGV[0] eq "--read") {
37 elsif($ARGV[0] eq "--test") {
42 my ($ename,$eloc,$edesc,$dist) = @ARGV;
46 print STDERR
"\t$str";
52 $eloc =~ s/[ ,\+ ~×]/_/g;
59 print STDERR
"Creating directory $edir ...";
61 mkdir $edir or die("\n$!");
69 $dist =~ s/\/?$/.txt
/;
74 print STDERR
"Writing $edir.txt...\n";
76 open FO
,">>","/dev/null";
79 unless(-f
"$edir.txt") {
80 open FO
,">","$edir.txt";
81 print FO tee
("=" x
6 . " " . $ename . " " . "=" x
6 . "\n");
82 print FO tee
(scalar(localtime()) . "\n\n");
85 open FO
,">>","$edir.txt";
89 print STDERR
("Prepairing text to $edir.txt from STDIN(CTRL-D to END)...\n");
97 my $entry = "* [[$eloc|$ename]]";
112 print STDERR
"Entry $entry exists\n";
115 print STDERR
"Add entry to $dist:\n";
117 open FO
,">","/dev/null";
122 print FO tee
("$entry\n");
123 print FO tee
(" $edesc\n") if($edesc);