diff --git a/Changelog b/Changelog index fbed4c3..426f610 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,31 @@ +1.3.5: +FIXED: Applied patch by Elmar Loos which fixes misbehavior for + -t and -T (identical output) +FIXED: Fixed import bug which omitted the timestamp of the last + entry, supmitted by Bill Barnard. +FIXED: Fixed another import "bug" (or design flaw) which caused + imported notes to get new numbering after importing them. + Submitted by Bill Barnard. +CHANGED: Until 1.3.4 missing Crypt:: modules lead to unencrypted + fallback by note. From 1.3.5 on this will no more happen, + it croaks now until you install the desired modules + or modify your configuration to use no encryption. +CHANGED: default config and default settings without config have + been changed. They are now simpler, no colours or anything + so that it works better out of the box in any terminal + window or shell (e.g. on dark ones or the like). +ADDED: New interactive mode command: "c". It is now possible to + change note's behavior at runtime. No database related + parameters can be modified. +================================================================================ +1.3.4: +ADDED: Each note now contains a "ticket number" which identifies + it against other notes. Those tickets are not changing when + notes will be reorganized. + +ADDED: added support for less to view note entries instead of + just printing it to STDOUT. (interactive mode). +================================================================================ 1.3.3: ADDED: new configfile parameter PrintLines (default: YES), which controls wether listings are separated by horizontal lines. diff --git a/NOTEDB/binary.pm b/NOTEDB/binary.pm index 8ddabb9..8e19dbd 100644 --- a/NOTEDB/binary.pm +++ b/NOTEDB/binary.pm @@ -125,7 +125,7 @@ sub get_all sub import_data { my ($this, $data) = @_; - foreach my $num (keys %{$data}) { + foreach my $num (sort keys %{$data}) { my $pos = $this->get_nextnum(); $this->set_edit($pos, $data->{$num}->{note}, $data->{$num}->{date}); } diff --git a/README b/README index b2375f9..5ef2c87 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -note 1.3.3 by Thomas Linden, 02/12/2005 +note 1.3.5 by Thomas Linden, 07/19/2009 ======================================= Introduction @@ -166,7 +166,7 @@ Refer to the note(1) manpage for usage instructions. Comments ======== -You can send any comments to Thomas Linden . +You can send any comments to Thomas Linden . If you find a bug or if you have a suggestion for improvement of the script feel free to send me a patch ;-) @@ -214,4 +214,4 @@ and I'll add you. Last changed ============ -02/12/2005 +07/19/2009 diff --git a/VERSION b/VERSION index 31e5c84..80e78df 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.3 +1.3.5 diff --git a/bin/note b/bin/note index 79dcf4a..a8052e4 100755 --- a/bin/note +++ b/bin/note @@ -1,7 +1,7 @@ #!/usr/bin/perl # # note - console notes management with database and encryption support. -# Copyright (C) 1999-2004 Thomas Linden (see README for details!) +# Copyright (C) 1999-2009 Thomas Linden (see README for details!) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# - Thomas Linden +# - Thomas Linden # # latest version on: # http://www.daemon.de/note/ @@ -56,8 +56,8 @@ sub help; # interactive help screen sub import; # import from notedb-dump sub display_tree; # show nice tree-view sub tree; # build the tree -sub print_tree; # print the tree, contributed by Jens Heunemann . THX! - +sub print_tree; # print the tree, contributed by Jens Heunemann . THX! +sub ticket; # return a random string which is used as ticket number for new note entries # # globals @@ -97,6 +97,7 @@ my ( $version, $CurTopic, $CurDepth, $WantTopic, $db, $sizeof, %TP, $TreeType, $ListType, $SetTitle, $clearstring, @ArgTopics, $key, $typedef, @NumBlock, $has_nothing, @completion_topics, @completion_notes, + @randomlist, $hardparams ); @@ -105,29 +106,46 @@ my ( # don't change them, instead use the config file! # -$conf{dbdriver} = "binary"; -$conf{usecolors} = 1; -$conf{bordercolor} = "bold"; -$conf{numbercolor} = "blue"; -$conf{notecolor} = "green"; -$conf{timecolor} = "blue"; -$conf{topiccolor} = "bold"; -$conf{topicseparator} = '/'; -$conf{useencryption} = 0; -$conf{tempdirectory} = File::Spec->tmpdir(); -$conf{alwaysinteractive} = 1; -$conf{alwayseditor} = 1; -$conf{autoclear} = 1; +%conf = ( + 'numbercolor' => 'blue', + 'bordercolor' => 'black', + 'timecolor' => 'black', + 'topiccolor' => 'black', + 'notecolor' => 'green', + 'alwaysinteractive' => 1, + 'keeptimestamp' => 0, + 'readonly' => 0, + 'shortcd' => 1, + 'autoclear' => 0, + 'maxlen' => 'auto', + 'defaultlong' => 0, + 'dbdriver' => 'binary', + 'timeformat' => 'DD.MM.YYYY hh:mm:ss', + 'usecolors' => 0, + 'addticket' => 0, + 'formattext' => 0, + 'alwayseditor' => 1, + 'useencryption' => 0, + 'tempdirectory' => File::Spec->tmpdir(), + 'topicseparator' => '/', + 'printlines' => 0, + 'cache' => 0, + 'preferrededitor' => '' +); + +# these are not customizable at runtime! +$hardparams = "(readonly|maxlen|dbdriver|useencryption|cryptmethod)"; $CONF = File::Spec->catfile($ENV{HOME}, ".noterc"); $USER = getlogin || getpwuid($<); chomp $USER; $TOPIC = 1; -$version = "1.3.3"; +$version = "1.3.5"; $CurDepth = 1; # the current depth inside the topic "directory" structure... $maxlen = "auto"; $timelen = 22; +@randomlist = ('a'..'z', 0..9, 'A'..'Z'); # colors available # \033[1m%30s\033[0m @@ -224,6 +242,7 @@ else { } elsif ($opt_t || $opt_T) { $mode = "tree"; + $mode = "display_tree"; $TreeType = "LONG" if($opt_T); } elsif (defined $opt_s) { @@ -273,7 +292,7 @@ else { } } elsif ($opt_v) { - print "This is note $version by Thomas Linden .\n"; + print "This is note $version by Thomas Linden .\n"; exit(0); } elsif ($opt_h) { @@ -414,7 +433,7 @@ if ($conf{useencryption} && $NOTEDB::crypt_supported == 1) { $cipher->decrypt(unpack("u", $driver{mysql}->{dbpasswd})) if($driver{mysql}->{encrypt_passwd}); &load_driver(); }; - die "Could not connect do db: $@!\n" if($@); + die "Could not connect to db: $@!\n" if($@); } else { &load_driver(); @@ -430,7 +449,16 @@ if ($conf{useencryption} && $NOTEDB::crypt_supported == 1) { } } #else empty database! } +elsif ($conf{useencryption} && $NOTEDB::crypt_supported == 0) { + print STDERR "WARNING: You enabled database encryption but neither Crypt::CBC\n"; + print STDERR "WARNING: or Crypt::$conf{cryptmethod} are installed! Please turn\n"; + print STDERR "WARNING: off encryption or install the desired modules! Thanks!\n"; + exit 1; +} else { + # as of 1.3.5 we do not fall back to cleartext anymore + # I consider this as unsecure, if you don't, fix your installation! + &load_driver(); $db->no_crypt; @@ -743,12 +771,38 @@ sub new { $note = $PATH . "\n$note"; } } + $note = &add_ticket($note); + $db->set_new($number,$note,$date); # everything ok until here! print "note stored. it has been assigned the number $number.\n\n"; $db->unlock(); } +sub add_ticket { + my $note = shift; + if ($conf{addticket}) { + my ($topic, $title, $rest) = split /\n/, $note, 3; + my $note = ""; + if ($topic =~ /^\//) { + # topic path, keep it + $note .= "$topic\n"; + } + else { + # no topic + $rest = "$title\n$rest"; + $title = $topic; + } + if ($title !~ /^\[[a-z0-9A-Z]+\]/) { + # no ticket number, so create one + my $ticket = &ticket(); + $title = "[" . ticket() . "] " . $title; + } + $note .= "$title\n$rest"; + } + return $note; +} + ############################### DELETE ################################## sub del { @@ -901,7 +955,7 @@ sub import { # we got a complete record, save it! $data{$number} = { date => $date, - note => $note + note => &add_ticket($note) }; print "fetched note number $number from $dump_file from $date.\n" if(!$stdin); $complete = 0; @@ -923,8 +977,8 @@ sub import { if ($note ne "" && $date ne "") { # the last record, if existent $data{$number} = { - data => $date, - note => $note + date => $date, + note => &add_ticket($note) }; print "fetched note number $number from $dump_file from $date.\n" if(!$stdin); } @@ -1119,6 +1173,26 @@ sub interactive { &display_tree; $TreeType = ""; } + elsif ($char =~ /^c\s*$/) { + print "Missing parameter (parameter=value), available ones:\n"; + foreach my $var (sort keys %conf) { + if ($var !~ /^$hardparams/ && $var !~ /::/) { + printf "%20s = %s\n", $var, $conf{$var}; + } + } + } + elsif ($char =~ /^c\s*(.+?)\s*=\s*(.+?)/) { + # configure + my $param = $1; + my $value = $2; + if ($param !~ /^$hardparams/ && $param !~ /::/ && exists $conf{$param}) { + print "Changing $param from $conf{$param} to $value\n"; + $conf{$param} = $value; + } + else { + print "Unknown config parameter $param!\n"; + } + } elsif ($char =~ /^\.\.$/ || $char =~ /^cd\s*\.\.$/) { $CurDepth-- if ($CurDepth > 1); $CurTopic = $LastTopic[$CurDepth]; @@ -1210,7 +1284,7 @@ sub interactive { sub usage { - print qq~This is the program note $version by Thomas Linden (c) 1999-2003. + print qq~This is the program note $version by Thomas Linden (c) 1999-2009. It comes with absolutely NO WARRANTY. It is distributed under the terms of the GNU General Public License. Use it at your own risk :-) @@ -1355,11 +1429,33 @@ sub output { # we will not reach this in raw-mode, therefore no decision here! chomp $note; $Space = " " x (($maxlen + $timelen) - $nlen - 16); - print C $LINE if ($conf{printlines}); - print C "$L $NUMC$num$_NUMC $R$L$TIMEC$time$_TIMEC $Space$R\n"; - print "\n"; - print C $NOTEC . $note . $_NOTEC . "\n"; - print C $LINE if ($count == 1 && $conf{printlines}); + + *CHANNEL = *STDOUT; + my $usecol = $conf{usecolors}; + + if ($conf{less}) { + my $less = "less"; + if ($conf{less} ne 1) { + # use given less command line + $less = $conf{less}; + } + if (open LESS, "|$less") { + *CHANNEL = *LESS; + $conf{usecolors} = 0; + } + } + + print CHANNEL C $LINE if ($conf{printlines}); + print CHANNEL C "$L $NUMC$num$_NUMC $R$L$TIMEC$time$_TIMEC $Space$R\n"; + print CHANNEL C "\n"; + print CHANNEL C $NOTEC . $note . $_NOTEC . "\n"; + print CHANNEL C $LINE if ($count == 1 && $conf{printlines}); + + if ($conf{less}) { + close LESS; + } + + $conf{usecolors} = $usecol; } } @@ -1469,7 +1565,7 @@ sub gettemp { sub help { my $B = ""; my $BB = ""; - my($S, $L, $T, $Q, $H, $N, $D, $E); + my($S, $L, $T, $Q, $H, $N, $D, $E, $C); $L = $B . "L" . $BB . $NOTEC; $T = $B . "T" . $BB . $NOTEC; $Q = $B . "Q" . $BB . $NOTEC; @@ -1478,6 +1574,7 @@ sub help { $D = $B . "D" . $BB . $NOTEC; $E = $B . "E" . $BB . $NOTEC; $S = $B . "S" . $BB . $NOTEC; + $C = $B . "C" . $BB . $NOTEC; print C qq~$BORDERC ----------------------------------------------------------------------$_BORDERC $TOPICC @@ -1495,6 +1592,7 @@ $S Search trough the notes database. Usage is similar to Delete, use a string instead of a number to search for. $E Edit a note. Usage is similar to Delete but you can only edit note a time. +$C Change note config online. Use with care! $H This help screen. $Q Exit the program.~; if ($TOPIC) { @@ -1528,6 +1626,7 @@ sub display_tree { @nodes = (); #("$conf{topicseparator}"); $text = $firstline; } + &determine_width; # ensure $maxlen values for &tree in non interactive modes &tree($num, $text, \%TREE, @nodes); } #return if ($num == 0); @@ -1664,5 +1763,7 @@ sub load_driver { } } - +sub ticket { + return join "", (map { $randomlist[int(rand($#randomlist))] } (0 .. 10) ); +} __END__ diff --git a/config/noterc b/config/noterc index e306ca0..5411cad 100644 --- a/config/noterc +++ b/config/noterc @@ -1,12 +1,12 @@ - # note 1.3.3 -*- sh -*- + # note 1.3.5 -*- sh -*- # # This is a sample config for the note script # There are useful defaults set in note itself. # # Copy it to your $HOME as .noterc # - # note is Copyright (c) 1999-2004 Thomas Linden. - # You can contact me per email: + # note is Copyright (c) 1999-2009 Thomas Linden. + # You can contact me per email: # # Comments start with #, empty lines will be ignored. # @@ -106,8 +106,8 @@ DefaultLong = NO # # You can use an external editor everytime from note instead - # of STDIN for creating new notes. The default is: NO -AlwaysEditor = NO + # of STDIN for creating new notes. The default is: YES +AlwaysEditor = YES @@ -148,8 +148,8 @@ MaxLen = auto # # Turn this off if you dont want note to automatically # clear the screen after displaying something and after - # exit. The default is: YES -AutoClear = YES + # exit. The default is: NO +AutoClear = NO @@ -157,7 +157,7 @@ AutoClear = YES # note can use colors for output, turn this of, if # you don't like it, or if your terminal does # not support it. The default is: YES -UseColors = YES +UseColors = NO @@ -182,7 +182,7 @@ TopicColor BLACK # # Additional to colors, you can also do a little bit of formatting your # notes (bold, underlined, italic) text. The default is: YES. -FormatText = YES +FormatText = NO @@ -198,7 +198,7 @@ TempDirectory = ~/tmp # # You can jump to a topic by typing "cd 13" in interactive mode. # The deault is: NO -ShortCd = NO +ShortCd = YES @@ -233,17 +233,25 @@ ReadOnly = NO # - # Note separates titles and topics using horizontal lines when - # listing them. You can turn off this behavior by setting - # PrintLines to NO. - # The default is: YES -PrintLines = YES + # Note may separate titles and topics using horizontal lines when + # listing them. You can turn on this behavior by setting + # PrintLines to YES. + # The default is: NO +PrintLines = NO + + + + # + # Add a hash to identify notes. Such a hash will persist several + # importy/export cycles and makes each single note unique. +AddTicket = NO + # # # That's all about it for now. # If you still have any questiosn, please feel free to contact - # me by email: Thomas Linden + # me by email: Thomas Linden # # diff --git a/note.pod b/note.pod index a16d2a3..c9cc90f 100644 --- a/note.pod +++ b/note.pod @@ -349,6 +349,12 @@ that note entry instead of displaying its number. This prints a tree-view of your topic-structure. B displays the tree with notes, B displays just the topics without notes. +=item B + +It is possible to change note's behavior at runtime. Specify the parameter +you'd like to modify followed by equalsign and the new value. Use with +care! However, database related parameters cannot be changed at runtime. +Entering just "c" without parameters displays the customizable variables. =item B @@ -367,6 +373,7 @@ If is possible to abbreviate a topic. This works only if the abbreviation matches on one single topic. If it matches more than one topic then the available ones will be suggested. + =item B Display a short help screen. @@ -518,11 +525,11 @@ at the supplied sample configuration file in B. =head1 AUTHOR -Thomas Linden +Thomas Linden =head1 VERSION -1.3.1 (12/01/2005) +1.3.5 (07/19/2009) =cut