View previous topic :: View next topic |
Author |
Message |
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Sat Apr 16, 2005 1:32 pm Post subject: |
|
|
Un ebuild est maintenant disponible
Consultez l'update du premier post pour les instruction d'installation. |
|
Back to top |
|
|
tfh n00b
Joined: 03 Aug 2004 Posts: 59 Location: AFAD
|
Posted: Sat Apr 16, 2005 8:40 pm Post subject: |
|
|
Oula ca m'a l'air tres bien ce script.
Je vais de ce pas l'essayer.
Au niveau des features ou suggestion, je pense que pouvoir interfacer avec une db sql pour socker les memos peut etre interessant. Je jetterai un oeil a ca demain .
Bonne idee sinon car je suppose que tout le monde garde des petits memo papier a cote pour se rappeller des differentes commandes ( tar viens a l'esprit ) _________________ tfh
GPG Key:0x960AAEF2
Key Fingerprint: 6763 E0E0 29AC A928 2612 4B14 15FE 6A45 960A AEF2 |
|
Back to top |
|
|
kernelsensei Bodhisattva
Joined: 22 Feb 2004 Posts: 5619 Location: Woustviller/Moselle/FRANCE (49.07°N;7.02°E)
|
Posted: Sat Apr 16, 2005 9:26 pm Post subject: |
|
|
une db sql je trouve ca un peu disproportionné, surtout que la methode actuelle est tres convenable et rend l'ajout de memos tres simple .. _________________ $ ruby -e'puts " .:@BFegiklnorst".unpack("x4ax7aaX6ax5aX15ax4aax6aaX7ax2aX5aX8 \
axaX3ax8aX4ax6aX3aX6ax3ax3aX9ax4ax2aX9axaX6ax3aX2ax4ax3aX4aXaX12ax10aaX7a").join' |
|
Back to top |
|
|
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Sun Apr 17, 2005 8:32 am Post subject: |
|
|
kernel_sensei wrote: | une db sql je trouve ca un peu disproportionné, surtout que la methode actuelle est tres convenable et rend l'ajout de memos tres simple .. |
oui, je suis d'accord avec toi.
On a essayé d'avoir des fichiers db facilement éditables a la main et aussi d'avoir le moins de dépendances possibles. Ce serait un peu bête d'être obligé d'installer des dép liées a sql par exemple.
Par contre la chose a laquelle on a pensé, c'est organiser les mémos dans des fichiers XML. Ca permettrait d'avoir du code plus lisible je pense et puis si les info qu'on reuni dans ces db sont intéressantes d'autres pourraient les utiliser facilement dans d'autres scripts par exemple.
Le seul petit désavantage serait que les db xml seraient un peu plus "difficile" a éditer par l'utilisateur. Mais ca c'est pour un peu plus tard de tte facon.
Vous en pensez quoi? |
|
Back to top |
|
|
blasserre Veteran
Joined: 10 Feb 2004 Posts: 1362 Location: Lille, Vlaanderen
|
Posted: Sun Apr 17, 2005 8:56 am Post subject: |
|
|
alctraz wrote: | Par contre la chose a laquelle on a pensé, c'est organiser les mémos dans des fichiers XML.
Vous en pensez quoi? |
à fond POUR
c'est vrai qu'on perd en éditabilité, mais après les "gens qui savent" peuvent faire ce qu'ils veulent |
|
Back to top |
|
|
kernelsensei Bodhisattva
Joined: 22 Feb 2004 Posts: 5619 Location: Woustviller/Moselle/FRANCE (49.07°N;7.02°E)
|
Posted: Sun Apr 17, 2005 8:58 am Post subject: |
|
|
franchement je trouve que les balises simples [Description] ... [end-of-item] conviennent parfaitement ... _________________ $ ruby -e'puts " .:@BFegiklnorst".unpack("x4ax7aaX6ax5aX15ax4aax6aaX7ax2aX5aX8 \
axaX3ax8aX4ax6aX3aX6ax3ax3aX9ax4ax2aX9axaX6ax3aX2ax4ax3aX4aXaX12ax10aaX7a").join' |
|
Back to top |
|
|
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Sun Apr 17, 2005 9:09 am Post subject: |
|
|
Oui, je crois que ca fonctionne bien comme ca pour le moment. Peut etre que dans un avenir plus lointain (qd on aura plus de temps), on envisagera ce genre de changements.
Et si jamais on passe a des fichiers xml, on fera un browser/éditeur de mémo avec ncurses :p |
|
Back to top |
|
|
tfh n00b
Joined: 03 Aug 2004 Posts: 59 Location: AFAD
|
Posted: Sun Apr 17, 2005 1:38 pm Post subject: |
|
|
En fait je parlais de base sql, par souci de standardisation, pour pouvoir faire plein de differentes applis pour editer / voir ses memos. Genre un site en php avec une form pour rajouter des mémos. Ca permettrais de faire une tres belle db de Tips and Tricks.
Mais je n'avais pas pense a la solution du fichier xml, qui remplis parfaitement cette fonction.
Donc je plussoie pour l'utilisation d'xml pour le stockage des mémos. _________________ tfh
GPG Key:0x960AAEF2
Key Fingerprint: 6763 E0E0 29AC A928 2612 4B14 15FE 6A45 960A AEF2 |
|
Back to top |
|
|
Thesee Tux's lil' helper
Joined: 02 Jun 2004 Posts: 138 Location: Belgium
|
Posted: Wed Apr 20, 2005 8:38 pm Post subject: |
|
|
C'est extraordinaire!
Je suis en train de reprendre tous mes fichiers pouilleux de mon repertoire "notes" et de les mettre au format .rdb.
C'est reellement une excellente idee que ce programme. Il faudrait le proposer a d'autres que sur le forum French... enfin, c'est mon avis _________________ How does a UNIX expert have sex?
Unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep. |
|
Back to top |
|
|
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Wed Apr 20, 2005 9:10 pm Post subject: |
|
|
Thesee wrote: | C'est extraordinaire!
Je suis en train de reprendre tous mes fichiers pouilleux de mon repertoire "notes" et de les mettre au format .rdb.
C'est reellement une excellente idee que ce programme. Il faudrait le proposer a d'autres que sur le forum French... enfin, c'est mon avis |
oh, merci bcp
Vraiment content que cela puisse te servir.
Maintenant que le script a été testé par qq personnes, je vais suivre ton conseil et poster qq chose sur le forum tip&tricks demain.
merci |
|
Back to top |
|
|
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Fri May 06, 2005 2:12 pm Post subject: |
|
|
Slt, je cherche a collecter des mémos propres a gentoo pour créer un fichier gentoo.rdb qui viendrait avec le shell-reminder.
J'attends vos suggestions, je mettrai la liste a jour au fur et à mesure.
Voici l'état actuel du fichier:
Code: | [gentoo files]
Main settings: /etc/make.conf
World file: /var/lib/portage/world
[end-of-item]
[repair world file]
regenworld
[end-of-item]
[emerge - dependency tree]
emerge -vpet <package>
[end-of-item]
[genlop - building, compiling time]
Specific package:
genlop -t <package>
Current merging package:
genlop --current
[end-of-item]
[rescue]
nano /usr/portage/sys-apps/portage/files/README.RESCUE
[end-of-item]
[emerge - clean config files - purge package]
CONFIG_PROTECT=-* emerge <package>
[end-of-item]
[To avoid problems after gcc 3.3.5 update]
fix_libtool_files.sh 3.3.4
[end-of-item]
[emerge - howto update]
emerge sync
emerge -vatDu world
emerge -va depclean
revdep-rebuild -va
dispatch-conf
[end-of-item]
[ccache]
To set a maximum cache size of 2GB
ccache -M 2G
Ccache statistics:
ccache -s
[end-of-item]
[prelink]
prelink -amfR
[end-of-item]
[esearch - find package]
First time: eupdatedb
Next, to sync: esync
To search: esearch [-S] <package>
[end-of-item]
[g-cpan.pl - install CPAN-provided Perl modules using Gentoo's Portage]
g-cpan.pl <module-name>
[end-of-item]
[overlay]
Edit /etc/make.conf:
PORTDIR_OVERLAY="/usr/local/portage"
Install ebuild:
mkdir -p /usr/local/portage/<category>/<app-name>/<ebuild>
ebuild /usr/local/portage/<category>/<app-name>/<ebuild> digest
Emerge application:
emerge -va <app-name>
[end-of-item]
[init scripts]
Managing scripts:
Add: rc-update add <script> <runlevels>
Remove: rc-update del <script> [runlevels]
Show: rc-update show [runlevels]
Stop/start/restart script:
/etc/init.d/<script> start,stop,restart
Get status:
/etc/init.d/<script> status
Set status to 'stopped' (usefull when service has crashed):
/etc/init.d/<script> zap
[end-of-item]
[System profile update]
rm /etc/make.profile
ln -s ../usr/portage/profiles/default-linux/x86/2005.0 /etc/make.profile
[end-of-item] |
_________________ Shell-reminder |
|
Back to top |
|
|
Thesee Tux's lil' helper
Joined: 02 Jun 2004 Posts: 138 Location: Belgium
|
Posted: Fri Oct 21, 2005 9:06 am Post subject: |
|
|
Salut alctraz!
J'ai du récemment réinstaller ma Gentoo pour des problème de disque dur de ma partition root, et j'ai vu que ton shell-reminder n'était pas dans le tree . Ils n'en n'ont pas voulu?
Enfin, tu me diras que ce n'est pas trop grave, il suffit de revenir sur le forum et de suivre la procédure mais bon, c'est plus qu'un chouette outil et plus que mériterait d'être dans le tree...
C'était "my two cents" _________________ How does a UNIX expert have sex?
Unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep. |
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
|
Back to top |
|
|
fribadeau Apprentice
Joined: 13 Jul 2003 Posts: 153 Location: Thonon (France)
|
Posted: Sat Oct 22, 2005 10:29 am Post subject: |
|
|
Super,
merci
|
|
Back to top |
|
|
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Sat Oct 22, 2005 12:25 pm Post subject: |
|
|
Ca fait plaisir de constater que c'est utile a d'autre.
J'avais un peu mis ca de coté, je vais peut etre m'y remettre et preparer qqs rdb avec les commandes/trucs les plus communs.
Si vous avez des mémos a me soumettre, ca m'interesse :)
@Thesee: en fait j'ai jamais pris la peine de soumettre l'ebuild. Je suis pas certain que le script soit assez 'abouti' pour ca. ;) _________________ Shell-reminder |
|
Back to top |
|
|
alctraz Tux's lil' helper
Joined: 12 May 2004 Posts: 117 Location: belgium
|
Posted: Mon Oct 24, 2005 12:06 pm Post subject: |
|
|
Slt,
Je tenais simplement a faire part du fait que j'ai installé un wiki a la place de la page qui se trouvait sur http://shell-reminder.org.
Ca serait sympa que les qqs utilisateurs du script partagent leurs tips/mémos ou bien contribuent a l'élaboration d'un fichier rdb sur un thème qui les interessent.
Creez les pages que vous souhaitez (dans le namespace 'reminders' pour les mémos/fichiers rdb).
J'espère que ca profitera a d'autres ;)
Merci _________________ Shell-reminder |
|
Back to top |
|
|
truz Apprentice
Joined: 26 Feb 2005 Posts: 293 Location: France - Paris
|
Posted: Mon Nov 21, 2005 11:51 pm Post subject: |
|
|
Thesee wrote: | c'est plus qu'un chouette outil et plus que mériterait d'être dans le tree... | Entièrement d'accord, tu devrais soumettre ton ebuild, au pire tu saura pourquoi il est refusé et tu pourras l'améliorer en conséquence. C'est tellement simple et puissant comme outil que l'accoutumance survient dès qu'on lit sa description
Juste une suggestion: et s'il y avait la possibilité d'utiliser (en lecture seulement) des rdb distants, quitte à synchroniser les fichiers de temps en temps ? Ca pourrait servir de référence "d'autorité" en quelque sorte pour certains trucs (genre ah mince je viens d'installer le dernier gcc mais là ça marche plus, j'ai vu passer un post y'a 2 semaines, mais je retrouve plus. Là on pourrait avoir les retours d'expérience des autres) voire aussi pour certaines applis (imaginez une sorte de 'man' super concis et plus concret mis à jour en permanence par l'auteur ou une communauté)...
Je m'emballe peut-être, mais c'est un super script, merci ! _________________ Je sais que mes droits s'arrêtent là où commencent ceux des autres. Mais est-ce ma faute si les droits des autres commencent si loin ? [Quino] -- Mafalda |
|
Back to top |
|
|
LaMs Apprentice
Joined: 10 Sep 2005 Posts: 151 Location: Quebec
|
Posted: Tue Nov 29, 2005 5:06 am Post subject: |
|
|
Simply .... The Best Overall!!! Vraiment bien comme truc
Portage serait content de l'avoir |
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
Posted: Tue Nov 29, 2005 9:20 pm Post subject: |
|
|
truz wrote: | Juste une suggestion: et s'il y avait la possibilité d'utiliser (en lecture seulement) des rdb distants, quitte à synchroniser les fichiers de temps en temps ? Ca pourrait servir de référence "d'autorité" en quelque sorte pour certains trucs (genre ah mince je viens d'installer le dernier gcc mais là ça marche plus, j'ai vu passer un post y'a 2 semaines, mais je retrouve plus. Là on pourrait avoir les retours d'expérience des autres) voire aussi pour certaines applis (imaginez une sorte de 'man' super concis et plus concret mis à jour en permanence par l'auteur ou une communauté)... |
whowww ! En voilà une excellente idée... sait pas trop comment le mettre en oeuvre mais c'est une question à creuser je pense car bien que le man fonctionne très bien il n'existe que peu d'évolutions le concernant
Complexe certes mais l'idée est séduisante en tout cas faudrait voir si des projets existent ou si d'autres on déjà travaillé sur cette problématique... m'en vais googler tiens _________________ " Un psychotique, c'est quelqu'un qui croit dur comme fer que 2 et 2 font 5, et qui en est pleinement satisfait.
Un névrosé, c'est quelqu'un qui sait pertinemment que 2 et 2 font 4, et ça le rend malade ! " |
|
Back to top |
|
|
Grobalo n00b
Joined: 23 May 2010 Posts: 2
|
Posted: Sun May 23, 2010 1:57 pm Post subject: |
|
|
Vraiment dsl de déterrer ce sujet...
Je cherche une personne qui aurait encore une copie de ce script que j'ai perdu après un crash de mon HD. Il est impossible à retrouver sur le net.
D'avance merci. |
|
Back to top |
|
|
boozo Advocate
Joined: 01 Jul 2004 Posts: 3193
|
Posted: Wed Jun 02, 2010 10:01 pm Post subject: |
|
|
'alute
il y a belle lurettte que alctraz n'est plus passé ici et je ne sais pas si son profil est à jour - cependant tu peux toujours essayer par pm ; d'autant plus honorable si tu comptes reprendre/étendre/maintenir le bidule
En attendant pour la cause - see below -
Code: |
#!/usr/bin/perl -w
#
# Shell-reminder is a small Perl script aimed at displaying
# reminders in your shell when you need it.
# Shell-reminder-20050416 Copyright (C) 2005
# E. Theeten <etheeten /<At>" gmail "<D0T>" com>,
# S. Wernerus <s.wernerus /<At>" gmail "<D0T>" gmail.com>.
#
# 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.
# 59 Temple Place Suite 330 Boston MA 02111-1307 USA
use strict;
use Term::ANSIColor;
use Tie::File;
# DECLARE
# environment
my $version = '20050416';
my $prog_name = eval {my @table = split (/\//, $0); pop @table;};
my $home= $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($<))[7];
#my $pager = $ENV{PAGER} || "(less || more)";
# directories, files
my $config_dir = '/etc/reminder';
my $home_db_dir = $home.'/.reminder';
my $personnal_db = $home_db_dir.'/reminders.rdb';
my @config_files = ($home_db_dir.'/reminder.conf', $config_dir.'/reminder.conf');
my @db_dirs = ('/etc/reminder', $home_db_dir);
my @db_files;
my @user_db_selection;
my $db_file_to_edit = '';
# parse vars
my ($index_found, $version_found, $help_found, $file_found, $add_reminder_found);
my %options = ( 'OR_SEARCH' => '0',
'HEADER_SEARCH' => '0',
'PERSO_SEARCH' => '0',
'DB_DIRS' => '' ,
'VERBOSE' => '0',
'DISP_COLORS' => '1',
'EDITOR' => '' );
my @regex;
my %colors = ( 'blue' => 'bold blue',
'green' => 'bold green',
'red' => 'bold red' );
# SUB
sub help () {
# display help information and exit
print
"Usage: ", colorise("$prog_name ", $colors{'blue'}),
"[", colorise("options", $colors{'green'}), "] [",
colorise("-f ", $colors{'green'}), "database_file] [",
colorise("words_to_match", $colors{'green'}), "]\n\n",
colorise("Options:\n", $colors{'green'}),
colorise(" none ", $colors{'green'}),
"display a list of available database files for selection\n",
colorise(" -h ", $colors{'green'}),
"display this help message\n",
colorise(" -v ", $colors{'green'}),
"display the version\n",
colorise(" -H ", $colors{'green'}),
"perform a header search only\n",
colorise(" -F ", $colors{'green'}),
"perform a full search, namely headers+content\n",
colorise(" -a ", $colors{'green'}),
"AND search\n",
colorise(" -o ", $colors{'green'}),
"OR search\n",
colorise(" -p ", $colors{'green'}),
"performs a search in the personal db only\n",
colorise(" -c ", $colors{'green'}),
"performs a complete search (all available db's)\n",
colorise(" -k ", $colors{'green'}),
"use colors in output\n",
colorise(" -n ", $colors{'green'}),
"don't use colors in output\n",
colorise(" -i ", $colors{'green'}),
"display an index of all the headers\n",
colorise(" -A ", $colors{'green'}),
"[database_file] Add a reminder using the editor defined by \$EDITOR\n",
colorise("\nNote:\n", $colors{'green'}),
"Notice that the default behaviour is configurable in the config file reminder.conf\n";
exit 0;
}
sub version () {
# display version information and exit
print "Shell-reminder-$version Copyright (C) 2005, E. Theeten, S. Wernerus.\n",
"Distributed under the GPL v2.\n";
exit 0;
}
sub colorise {
# in: a string we want to print
# out: this string colorised or unmodified, depending on user's choice
my $string = shift;
my $color = shift;
if ($options{'DISP_COLORS'}) {
return colored($string, $color);
} else {
return ($string || 0);
}
}
#my $colorise;
#if ($options{'DISP_COLORS'}) {
# $colorise = sub {return (colored($_[0], $_[1]) || $_[0] || 0)};
#} else {
# $colorise = sub {return ($_[0] || 0)};
#}
#sub colorise {
# return &$colorise($_[0], $_[1]);
#}
sub open_file {
# in: reference to a file handle
# check if the specified file is readable and a text file, then open it
my ($fh, $file) = @_;
unless (-r $file) {
print "Could not read $file... \n"; return 0;
}
unless (-T $file) {
print "Not a text file: $file... \n"; return 0;
}
unless (open($$fh, "< $file")) {
print "Could not open $file: $!\n"; return 0;
}
return 1;
}
sub ls_db_files {
# in: list of directories
# out: the @table of .rdb files contained in the passed list of directories
my @dir_list = @_;
my @returned_list;
DIR:
foreach my $dir (@dir_list) {
#unless (opendir(DH, $dir)) {print "Not fatal: could not open directory $dir: $!\n"; next DIR};
unless (opendir(DH, $dir)) {
next DIR;
}
my @ls = readdir DH;
closedir DH or print "Not fatal: could not close directory $dir: $!\n";
@ls = grep(/\.rdb$/, @ls);
map {$_ = $dir.'/'.$_} @ls;
push @returned_list, @ls;
}
die "No database found ! Please supply at least one database..." unless (@returned_list);
return @returned_list;
}
sub print_db_list() {
# print a list of the available database files for selection and exit
# print help info
print 'To get help: ', colorise($prog_name, $colors{'blue'}),
colorise(' -h', $colors{'green'}), ' or ',
colorise($prog_name, $colors{'blue'}),
colorise(' remind-me', $colors{'green'}), "\n\n",
'Available database files to search in:', "\n";
#colorise('Available database files to search in:', $colors{'green'}), "\n";
# print file list
my $i = 1;
foreach (ls_db_files(@db_dirs)) {
print colorise("$i. $_", $colors{'green'}), "\n";
$i++;
}
# print file list usage
print "\nUsage: ", colorise("$prog_name ", $colors{'blue'}),
colorise(":1-3,5,7 words_to_match\n", $colors{'green'});
exit 0;
}
sub add_template {
unless (-e $db_file_to_edit) {
print "The file $db_file_to_edit does not exist...\n";
#"Use 'remind-me -A' to edit your personnal data base $personnal_db\n";
exit 0;
}
my @lines;
tie @lines, 'Tie::File', $db_file_to_edit or die "Could not open $db_file_to_edit: $!\n";
unshift @lines, "[ ]\n\n[end-of-item]\n\n";
untie @lines;
}
sub add_reminder {
if ($options{'EDITOR'} && -e $options{'EDITOR'}) {
add_template;
exec "$options{'EDITOR'} $db_file_to_edit";
} elsif ($ENV{'EDITOR'} && -e $ENV{'EDITOR'}) {
add_template;
exec "$ENV{'EDITOR'} $db_file_to_edit";
} else {
die 'Please specify an editor either through the $EDITOR environment variable ',
"or in the config file\n";
}
}
sub parse_config {
# parse the right config file
my $FH;
my $config_file;
# foreach $config_file (@config_files) {
# if (-e $config_file) {print "$config_file\n"; last}
# }
# use the config file from home directory if available
foreach (@config_files) {
$config_file = $_;
if (-e $config_file) {last}
}
unless (open_file(\$FH, $config_file)) {
print "Using default config.\n";
return 0;
}
while (<$FH>) {
my $option = $_;
#if ($option =~ /(\w*)\s*=\s*"(.*?)"/ && $` !~ /#/) {
if ($option =~ /^\s*(\w*)\s*=\s*"(.*?)"/) {
$options{$1} = $2;
}
}
close($FH) || print "Could not close $config_file\n";
if ($options{'DB_DIRS'}) {
my @splited = split (/\s+/, $options{'DB_DIRS'});
push @db_dirs, @splited;
}
# uncomment for debugging the regex...
#while ( my ($key, $value) = each %options) {
#print "$key = $value\n";
#}
#exit 0;
}
sub parse_arg ($) {
# parse command line arguments
my $arg = $_[0];
if ($arg =~ /^-(.*)/) {
$arg = $1;
while ($arg) {
my $opt = chop($arg);
OPT: {
$help_found = 1, last OPT if ($opt eq "h");
$version_found = 1, last OPT if ($opt eq "v");
$index_found = 1, last OPT if ($opt eq "i");
$options{'HEADER_SEARCH'} = 1, last OPT if ($opt eq "H");
$options{'HEADER_SEARCH'} = 0, last OPT if ($opt eq "F");
$options{'OR_SEARCH'} = 1, last OPT if ($opt eq "o");
$options{'OR_SEARCH'} = 0, last OPT if ($opt eq "a");
$options{'PERSO_SEARCH'} = 1, last OPT if ($opt eq "p");
$options{'PERSO_SEARCH'} = 0, last OPT if ($opt eq "c");
$options{'DISP_COLORS'} = 1, last OPT if ($opt eq "k");
$options{'DISP_COLORS'} = 0, last OPT if ($opt eq "n");
if ($opt eq "f") {
if (!$ARGV[0]) {
print colorise("No database file specified!", $colors{'red'}), "\n";
exit -1;
}
if (!-r $ARGV[0]) {
print colorise("Database file ".$ARGV[0]." not readable or not found.",
$colors{'red'}), "\n";
exit -1;
}
#print "Using database file $ARGV[0] \n";
#unshift @db_files, shift @ARGV;
#@db_files = shift @ARGV;
$file_found = shift @ARGV;
last OPT;
}
if ($opt eq "A") {
if ($ARGV[0]) {
$db_file_to_edit = $ARGV[0];
} else {
$db_file_to_edit = $personnal_db;
}
$add_reminder_found = 1;
last OPT;
}
print colorise("Unknown option: -$opt", $colors{'red'}), "\n";
help ();
}
}
} elsif ($arg =~ /^:(.*)/) {
my @splitted_arg = split (/,/, $1);
foreach (@splitted_arg) {
if (/^(\d+)(?:-(\d+))?$/) {
push @user_db_selection, $1..($2 || $1);
} else {
print colorise("Please supply a well formed request!\n\n", $colors{'red'});
print_db_list();
}
}
# grep only non-repeted items
my %seen;
@user_db_selection = grep {!$seen{$_}++} @user_db_selection;
return 1;
} else {
push @regex, $arg;
return 1;
}
}
# MAIN
# parse config file
parse_config;
# display list of available db files if no argument at all
print_db_list() if (!$ARGV[0]);
# then, parse arguments
parse_arg(shift @ARGV) while ($ARGV[0]);
# display help/version if help/version requested
help() if ($help_found);
version() if ($version_found);
# add a reminder ?
add_reminder if ($add_reminder_found);
# display help if no patern to match and no index requested
help() if (!$regex[0] && !$index_found);
# take only the files corresponding to the user selection
DB_FILES: {
@db_files = ($home_db_dir.'/reminders.rdb'), last DB_FILES if ($options{'PERSO_SEARCH'});
@db_files = $file_found, last DB_FILES if ($file_found);
if (@user_db_selection) {
my @all_dbs = ls_db_files(@db_dirs);
foreach (@user_db_selection) {
if (($_-1) <= $#all_dbs) {
push @db_files, $all_dbs[$_-1];
} else {
print colorise("Value out of range!\n", $colors{'red'});
print_db_list();
}
}
last DB_FILES;
}
push @db_files, ls_db_files(@db_dirs);
}
# modify regex table depending on the header/full search type
REGEX: {
# Index
if ($index_found) {
print colorise("Index:\n", $colors{'green'}); last REGEX;
}
# Header search...
if ($options{'HEADER_SEARCH'}) {
print colorise("Header search:", $colors{'green'}), "\n";
#map {$_ = "^\\\[.*$_.*\\\]"} @regex;
map {$_ = qr/^\[.*$_.*\]/i} @regex;
last REGEX;
}
# Full search...
print colorise("Full search:", $colors{'green'}), "\n";
map {$_ = qr/$_/i} @regex;
}
# compile frequently used regexes
my $header_regex = qr/^\[.*\]$/; # used to match headers with //m
my $not_header_regex = qr/^[^\[].*/; # used to match item content lines
# patern for OR search
my $string = join('|', @regex);
my $patern = qr/$string/;
# MAIN LOOPS
$/ = "[end-of-item]"; # read file by item
my $FH;
FILE:
foreach my $db_file (@db_files) {
open_file(\$FH, $db_file) || next FILE;
print colorise("\n$db_file\n", $colors{'green'}) if ($options{'VERBOSE'});
LOOP:
while (<$FH>) {
chomp;
my $item = $_;
$item =~ s/\s*//; # remove the leading spaces
if ($index_found) {
# print headers only...
#if ($item =~ /(^\[.*\]$)/m) {
if ($item =~ /($header_regex)/m) {
print colorise("$1\n", $colors{'blue'});
}
next LOOP;
}
if (!$options{'OR_SEARCH'}) {
# AND search...
foreach $patern (@regex) {
#if ($item =~ /$patern/i) {
if ($item =~ /$patern/) {
# patern in red in item content
$item =~ s/($not_header_regex)($patern)/$1.colorise($2, $colors{'red'})/egm;
} else {
next LOOP;
}
}
# header in blue
$item =~ s/($header_regex)/colorise($1, $colors{'blue'})/em;
print "\n$item";
} else {
# OR search...
#if ($item =~ /$patern/i) {
if ($item =~ /$patern/) {
# patern in red in item content
$item =~ s/($not_header_regex)($patern)/$1.colorise($2, $colors{'red'})/egm;
# header in blue
$item =~ s/($header_regex)/colorise($1, $colors{'blue'})/em;
print "\n$item";
}
}
}
close($FH) or die "Could not close $db_file: $!";
}
undef $/;
|
_________________ " Un psychotique, c'est quelqu'un qui croit dur comme fer que 2 et 2 font 5, et qui en est pleinement satisfait.
Un névrosé, c'est quelqu'un qui sait pertinemment que 2 et 2 font 4, et ça le rend malade ! " |
|
Back to top |
|
|
Grobalo n00b
Joined: 23 May 2010 Posts: 2
|
Posted: Thu Jun 03, 2010 8:48 am Post subject: |
|
|
Merci infiniment boozo! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|