diff options
Diffstat (limited to 'gmi.pl')
-rwxr-xr-x | gmi.pl | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -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; } |