mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 04:31:02 +01:00
first commit
This commit is contained in:
140
README
Normal file
140
README
Normal file
@@ -0,0 +1,140 @@
|
||||
note 0.1 by Thomas Linden, 1999
|
||||
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
This is a small console program written in
|
||||
perl, which allows you to manage notes similar
|
||||
to programs like "knotes" from commandline.
|
||||
|
||||
You can add, edit, list and delete as many notes
|
||||
as you want. The notes are stored in a mysql
|
||||
database. You might think, "what an overkill...",
|
||||
but doing it this way provides some important
|
||||
advantages:
|
||||
o data integrity
|
||||
o no need of another proprietary file format
|
||||
o no new engine to maintain this file format
|
||||
o speed
|
||||
o portability
|
||||
o availability
|
||||
...
|
||||
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
You need the following things:
|
||||
o perl installed (5.004x)
|
||||
o mysql database installed and running
|
||||
o Mysql perlmodule (you can find it on
|
||||
http://www.mysql.org) PLEASE NOTE:
|
||||
It needs the Module "Mysql". Newer versions
|
||||
are DBI, which you can also use to access
|
||||
mysql databases. If you want to use it, you
|
||||
have to rewrite the program. Please let me
|
||||
know, if you did it :-)
|
||||
o permissions to create a new database and
|
||||
to write data to this database.
|
||||
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
First, make sure all these things above are ok.
|
||||
You can use the script "install.sh" to create a new
|
||||
database and the table structure. You might edit
|
||||
the script before running it.
|
||||
|
||||
If you getting trouble, i.e. if you have not the
|
||||
required permissions to do that, please make sure,
|
||||
you can.
|
||||
As user root, you have to give your username the
|
||||
neccessary permissions. Please refer to the mysql
|
||||
documentation, how to do that.
|
||||
After that repeat the step above.
|
||||
|
||||
As root, copy the perl-script "note" to /usr/bin.
|
||||
|
||||
This should be all.
|
||||
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
If you created the database with install.sh, you
|
||||
do not need to do anything further. Simply run
|
||||
"note" without any commandline parameters. It will
|
||||
create a configfile ~/.noterc for you.
|
||||
You might take a look to this file and change something,
|
||||
if neccessary.
|
||||
|
||||
|
||||
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
If you don't know, how to run note, try "note -h" first.
|
||||
It will tell you all available commandline options.
|
||||
|
||||
To create a new note, simply run "note". You can enter
|
||||
the note (there is no limitation on length of the note).
|
||||
End by typing a . on a line itself. note will tell you the
|
||||
number of the note.
|
||||
|
||||
If you want to view the note, type "note 1", if the notenumber
|
||||
was 1.
|
||||
|
||||
If you want to get an overview of all notes, type "note -l".
|
||||
You will get a list of all notes, containing the number,
|
||||
the first line and the creation date.
|
||||
|
||||
To edit a certain note, type "note -e 1". It will invoke your
|
||||
editor (vi or pico). You can edit it, after saving, note
|
||||
will store the changed note to the database.
|
||||
|
||||
Of course you can drop a certain note: "note -d 1" deletes
|
||||
note number 1.
|
||||
|
||||
If you cannot remember, which note you are looking for, you
|
||||
can use the search capability of note: "note -s <searchstring>".
|
||||
note will search the whole note database case insensitive for
|
||||
an occurence of this string and tell you the number and first-
|
||||
line it have.
|
||||
|
||||
|
||||
|
||||
|
||||
Comments
|
||||
========
|
||||
|
||||
You can send any comments to Thomas Linden <tom@daemon.de>.
|
||||
|
||||
|
||||
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This program is GPL.
|
||||
|
||||
|
||||
|
||||
|
||||
Author
|
||||
======
|
||||
|
||||
The author os Thomas Linden.
|
||||
|
||||
|
||||
|
||||
|
||||
Last changed
|
||||
============
|
||||
|
||||
07.11.1999
|
||||
|
||||
19
install.sh
Executable file
19
install.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# installs note
|
||||
|
||||
echo "Welcome to note `cat VERSION` installation."
|
||||
echo "the install script will ask you a view questions,"
|
||||
echo "make sure to answer them correctly!"
|
||||
echo
|
||||
|
||||
/bin/echo -n "creating the note database..."
|
||||
NAME="_note"
|
||||
DBNAME="$USER$NAME"
|
||||
echo "DBNAME=$DBNAME"
|
||||
mysqladmin create $DBNAME
|
||||
echo "done."
|
||||
/bin/echo -n "creating the table structure using defaults..."
|
||||
mysql $DBNAME < sql
|
||||
echo "done."
|
||||
|
||||
|
||||
367
note
Executable file
367
note
Executable file
@@ -0,0 +1,367 @@
|
||||
#!/usr/bin/perl
|
||||
# this is the small console program "note"
|
||||
# It works similar to some well known GUI note programs,
|
||||
# but instead of using X11 it uses the UN*X console.
|
||||
# You can edit existing notes, delete them, create new
|
||||
# ones and, of course display them.
|
||||
# The notes will be stored in a mysql database. Refer to
|
||||
# the README of the desitribution for details about
|
||||
# installation.
|
||||
# It requires a configfile named .noterc in the users home.
|
||||
# If it does not exist, note will create one for you, which
|
||||
# you will have to edit.
|
||||
#
|
||||
# If you find it usefull or find a bug, please let me know:
|
||||
# Thomas Linden <tom@daemon.de>
|
||||
#
|
||||
# note is GPL software.
|
||||
|
||||
|
||||
use Mysql;
|
||||
|
||||
##################################
|
||||
# define some default values.
|
||||
# don't change them, instead use the config file!
|
||||
|
||||
$version = "0.1";
|
||||
$date = `date +%e\".\"%m\".\"%Y\" \"%T`;
|
||||
chomp $date;
|
||||
|
||||
$USER = getlogin || getpwuid($<);
|
||||
chomp $USER;
|
||||
|
||||
$HOME = `echo \$HOME`;
|
||||
chomp $HOME;
|
||||
|
||||
$CONF = $HOME . "/.noterc";
|
||||
|
||||
$DEFAULTDBNAME = $USER . "_note";
|
||||
$dbhost = "";
|
||||
$dbuser = "";
|
||||
$dbpasswd = "";
|
||||
$dbname = "";
|
||||
$dbname = "";
|
||||
$searchstring = "";
|
||||
###################################
|
||||
|
||||
|
||||
sub usage;
|
||||
sub find_editor;
|
||||
|
||||
# process command line args
|
||||
if($ARGV[0] eq "")
|
||||
{
|
||||
$mode = "new";
|
||||
}
|
||||
else
|
||||
{
|
||||
while($ARGV[0] ne "" )
|
||||
{
|
||||
if($ARGV[0] =~ /\d+/)
|
||||
{
|
||||
# first arg is a digit!
|
||||
$number = $ARGV[0];
|
||||
if($mode eq "")
|
||||
{
|
||||
# change mode only, if started with an option
|
||||
# ($mode will be already set)
|
||||
$mode = "display";
|
||||
}
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-l")
|
||||
{
|
||||
$mode = "list";
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-s")
|
||||
{
|
||||
# searching
|
||||
$mode = "search";
|
||||
$searchstring = $ARGV[1];
|
||||
$ARGV[0] = "";
|
||||
}
|
||||
elsif($ARGV[0] eq "-e")
|
||||
{
|
||||
if($mode eq "edit")
|
||||
{
|
||||
# note -e -e !
|
||||
&usage;
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mode = "edit";
|
||||
shift;
|
||||
}
|
||||
}
|
||||
elsif($ARGV[0] eq "-d")
|
||||
{
|
||||
if($mode eq "delete")
|
||||
{
|
||||
&usage;
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mode = "delete";
|
||||
shift;
|
||||
}
|
||||
}
|
||||
elsif($ARGV[0] eq "-v" || $ARGV[0] eq "--version")
|
||||
{
|
||||
print "note $version\nfrom Thomas Linden <tom\@daemon.de>\n";
|
||||
exit(0);
|
||||
}
|
||||
elsif($ARGV[0] eq "-h" || $ARGV[0] eq "--help")
|
||||
{
|
||||
&usage;
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
&usage;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Now we have the following variables set:
|
||||
# $mode (delete | new | edit | list)
|
||||
# $number ("", -l was given)
|
||||
|
||||
|
||||
# open the configfile.
|
||||
|
||||
|
||||
|
||||
if(-e $CONF)
|
||||
{
|
||||
eval `cat $CONF`;
|
||||
}
|
||||
else
|
||||
{
|
||||
# no config, create one and inform the user.
|
||||
open FILE, ">$CONF" or die "Could not create $CONF!\n";
|
||||
select FILE;
|
||||
print qq~\#config for note $version
|
||||
\#automaticallly created by note, $date.
|
||||
\#please refer to the man page for more informations!
|
||||
|
||||
\#the database to be used
|
||||
\$dbname = "$DEFAULTDBNAME";
|
||||
|
||||
\#the database host
|
||||
\$dbhost = "localhost";
|
||||
|
||||
\#the user to connect
|
||||
\$dbuser = $USER;
|
||||
|
||||
\#the password to be used
|
||||
\$dbpasswd = "";
|
||||
|
||||
\# db descriptors...
|
||||
\$table = "note";
|
||||
\$fnum = "number";
|
||||
\$ffirst = "firstline";
|
||||
\$fnote = "note";
|
||||
\$fdate = "date";
|
||||
~;
|
||||
close FILE;
|
||||
select STDOUT;
|
||||
print "$CONF has been created for you. Please don't forget to edit it!\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
# ok, if still here, we got it all, now let's connect to the database
|
||||
$db = Mysql->connect($dbhost,$dbname,$dbuser,$dbpasswd)
|
||||
or die "ERROR: $Mysql::dberrstr\n";
|
||||
|
||||
|
||||
# start processing
|
||||
if($mode eq "display")
|
||||
{
|
||||
# display a certain note
|
||||
print "\ndisplaying note number $number:\n";
|
||||
$res = $db->query("SELECT $ffirst,$fnote,$fdate FROM $table WHERE $fnum = $number")
|
||||
or die "ERROR: $Mysql::dberrstr\n";
|
||||
while(@row = $res->fetchrow)
|
||||
{
|
||||
print "$row[0]\n$row[1]\n\nlast changed: $row[2]\n\n";
|
||||
$match = "yes";
|
||||
}
|
||||
if($match eq "")
|
||||
{
|
||||
print "\nno note with that number found!\n\n";
|
||||
}
|
||||
}
|
||||
elsif($mode eq "search")
|
||||
{
|
||||
if($searchstring eq "")
|
||||
{
|
||||
&usage;
|
||||
exit(1);
|
||||
}
|
||||
print "\nsearching the database $dbname for \"$searchstring\"...\n\n";
|
||||
$sqlstatement = "SELECT DISTINCT $fnum,$ffirst,$fdate FROM $table WHERE "
|
||||
. "$ffirst LIKE '%$searchstring%' OR $fnote LIKE '%$searchstring%'"
|
||||
. " ORDER BY $fnum";
|
||||
|
||||
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
||||
while(@row = $res->fetchrow)
|
||||
{
|
||||
print "[ $row[0]\t\"$row[1]\"\t$row[2] ]\n";
|
||||
$match = "yes";
|
||||
}
|
||||
if($match eq "")
|
||||
{
|
||||
print "\nno matching note found!\n\n";
|
||||
exit(0);
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
elsif($mode eq "list")
|
||||
{
|
||||
print "\nlisting all existing notes:\n";
|
||||
# list all available notes (number and firstline)
|
||||
$res = $db->query("SELECT $fnum,$ffirst,$fdate FROM $table ORDER BY $fnum")
|
||||
or die "ERROR: $Mysql::dberrstr\n";
|
||||
while(@row = $res->fetchrow)
|
||||
{
|
||||
print "[ $row[0]\t\"$row[1]\"\t$row[2] ]\n";
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
elsif($mode eq "new")
|
||||
{
|
||||
# create a new note
|
||||
print "\nenter the text of the note, end with .\n";
|
||||
while($linenum != 1)
|
||||
{
|
||||
$line = <STDIN>;
|
||||
$firstline = $line;
|
||||
$linenum = 1;
|
||||
}
|
||||
do
|
||||
{
|
||||
$line = <STDIN>;
|
||||
$note = $note . $line;
|
||||
} until $line eq ".\n";
|
||||
# remove the . !
|
||||
chop $note;
|
||||
chop $note;
|
||||
chomp $firstline;
|
||||
#print "1: $firstline\n2: $note\n";
|
||||
|
||||
# since we have not number, look for the next available:
|
||||
$res = $db->query("SELECT max($fnum) FROM $table") or die "ERROR: $Mysql::dberrstr\n";
|
||||
while(@row = $res->fetchrow)
|
||||
{
|
||||
$number = $row[0];
|
||||
}
|
||||
$number++;
|
||||
$sqlstatement = "INSERT INTO $table VALUES (0,$number,'$firstline','$note','$date')";
|
||||
|
||||
$db->query($sqlstatement)
|
||||
or die "ERROR: $Mysql::dberrstr\n";
|
||||
|
||||
# everything ok until here!
|
||||
print "note stored. it has been assigned the number $number.\n\n";
|
||||
}
|
||||
elsif($mode eq "delete")
|
||||
{
|
||||
# delete a note
|
||||
$sqlstatement = "DELETE FROM $table WHERE $fnum = $number";
|
||||
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
||||
print "\nnote number $number has been deleted.\n\n";
|
||||
}
|
||||
elsif($mode eq "edit")
|
||||
{
|
||||
# edit a note
|
||||
$sqlstatement = "SELECT $ffirst,$fnote FROM $table WHERE $fnum = $number";
|
||||
$res = $db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
||||
while(@row = $res->fetchrow)
|
||||
{
|
||||
$firstline = $row[0];
|
||||
$note = $row[1];
|
||||
$match = "yes";
|
||||
}
|
||||
if($match eq "")
|
||||
{
|
||||
print "\nno note with that number found!\n\n";
|
||||
exit(0);
|
||||
}
|
||||
$TEMP = "/tmp/note.$USER.$$";
|
||||
open NOTE,">$TEMP" or die "Could not open $TEMP\n";
|
||||
select NOTE;
|
||||
print $firstline . "\n";
|
||||
print $note . "\n";
|
||||
close NOTE;
|
||||
select STDOUT;
|
||||
$editor = &find_editor;
|
||||
if($editor)
|
||||
{
|
||||
system $editor, $TEMP;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Could not find an editor to use!\n";
|
||||
exit(0);
|
||||
}
|
||||
$note = "";
|
||||
open NOTE,"<$TEMP" or die "Could not open $TEMP\n";
|
||||
$c = 0;
|
||||
while(<NOTE>)
|
||||
{
|
||||
if($c == 0)
|
||||
{
|
||||
$firstline = $_;
|
||||
chomp $firstline;
|
||||
}
|
||||
else
|
||||
{
|
||||
$note = $note . $_;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
chomp $note;
|
||||
close NOTE;
|
||||
|
||||
system "/bin/rm -f $TEMP";
|
||||
|
||||
# we got it, now save to db
|
||||
$sqlstatement = "UPDATE $table SET "
|
||||
. "$ffirst = '$firstline', "
|
||||
. "$fnote = '$note' "
|
||||
. "WHERE $fnum = $number";
|
||||
$db->query($sqlstatement) or die "ERROR: $Mysql::dberrstr\n";
|
||||
|
||||
print "\nnote number $number has been changed.\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
#undefined :-(
|
||||
}
|
||||
|
||||
|
||||
# the end.
|
||||
exit(0);
|
||||
|
||||
sub usage
|
||||
{
|
||||
print "\nusage: \nnote [-l | -h | -v] | [-s <searchstring>] | [-e | -d <number>] | [<number>]\n";
|
||||
print "Options: -l lists all existing notes\n";
|
||||
print " -h displays this help screen\n";
|
||||
print " -v displays the version number\n";
|
||||
print " -s searches trough the notes database\n";
|
||||
print " -e <n> edit note number <n>\n";
|
||||
print " -d <n> delete note number <n>\n";
|
||||
print "If you specify only a number (i.e.\"note 4\"), then this note will be\n";
|
||||
print "displayed. If you run note without any parameter, it will create a\n";
|
||||
print "new note and store it.\n\n";
|
||||
|
||||
exit 1;
|
||||
}
|
||||
sub find_editor {
|
||||
return $ENV{"VISUAL"} || $ENV{"EDITOR"} || "vim" || "vi" || "pico";
|
||||
}
|
||||
Reference in New Issue
Block a user