aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjake <jake@jakes-mail.top>2022-01-31 17:50:52 -0500
committerjake <jake@jakes-mail.top>2022-01-31 17:50:52 -0500
commit31e894411a74c4cddfb1edcfb6fa5c3769d87fb6 (patch)
treedabd3a702f4be6334ae8a4495abcc482767cde3f
parent4afa0b8da16769c38050e0d3f499ed1045cad42a (diff)
Save history to disk. also clear history command
-rwxr-xr-xgmi.pl30
1 files changed, 29 insertions, 1 deletions
diff --git a/gmi.pl b/gmi.pl
index d61353c..0ff093c 100755
--- a/gmi.pl
+++ b/gmi.pl
@@ -45,6 +45,7 @@ my %config = (
'auto_redirect' => 3,
'pager' => 'less -R',
'doc_out' => 1,
+ 'keep_history' => 0,
);
my @doc;
my @links;
@@ -142,7 +143,7 @@ my %commands = (
'help' => [sub { help($_[0]); }, 'Use help before a command to get extra info.' .
'(<tab><tab> to see commands)'],
'ver' => [sub {print $OUT "$VERSION\n"}, "Returns the version ($VERSION)"],
- 'exit' => [sub {exit 0;}, "This exits the program with a status code of 0."],
+ 'exit' => [sub {begin_exit();}, "This exits the program with a status code of 0."],
'autoredirection' => [sub { value_number($config{auto_redirect},$_[0],'autoredirect') },
"The amount of times this program is allowed to auto redirect. 0 = none."],
@@ -159,6 +160,10 @@ my %commands = (
'cert-use' => [sub { cert_use() }, "Use a cert. Interactive.\n" .
"If a cert has already been loaded, it will unload it."],
'cert-del' => [sub {cert_del() }, "Delete a cert. Interactive." ],
+
+ 'keep-history' => [sub {toggle($config{keep_history})}, 'Toggle whether to save history to disk or not,' .
+ ' after \'exit\'. By default it does not.' ],
+ 'clear-history' => [sub { undef(@history) }, 'Clears your history. (The file itself is very parsable)' ],
);
my @completions = keys %commands;
@@ -648,7 +653,9 @@ sub get_links {
sub hist {
my $hist;
my $counter = 1;
+ ### @history
for my $item (@history) {
+ ### $item
$hist .= "[$counter] ". colored("$$item[0]", 'underline') ." $$item[1]\n";
$counter++;
}
@@ -1123,4 +1130,25 @@ sub load_config {
for (keys %$config) {
$config{$_} = %$config{$_};
}
+ if (-e "$xdg_data/history") {
+ open(my $FH, '<', "$xdg_data/history");
+ while (<$FH>) {
+ my @h = split(' ',$_);
+ push(@history, [@h]);
+ }
+ close $FH;
+ }
+ ### @history
+}
+
+sub begin_exit {
+ if ($config{keep_history}) {
+ # over writes the history with old and new
+ open(my $FH, '>', "$xdg_data/history");
+ for my $item (@history) {
+ print $FH "$$item[0] $$item[1]\n";
+ }
+ close $FH;
+ }
+ exit 0;
}