# HG changeset patch # User Davor Ocelic # Date 1556567877 -7200 # Node ID 24340fdef27618783bd77b1bbd8d14f3578078ef # Parent 3e31beb6c84556378bb18d01046934f13cf50941 Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols Make Ctrl+C behave like in the shell (abort current line, redisplay) Add '?' and 'man' as aliases for help Add qw// on module 'use's to not import any symbols diff -r 3e31beb6c845 -r 24340fdef276 shelldap --- a/shelldap Mon Apr 29 00:16:14 2019 +0200 +++ b/shelldap Mon Apr 29 21:57:57 2019 +0200 @@ -461,9 +461,9 @@ package LDAP::Shell; use strict; use warnings; -use Term::ReadKey; -use Term::Shell; -use Digest::MD5; +use Term::ReadKey qw//; +use Term::Shell qw//; +use Digest::MD5 qw//; use Net::LDAP qw/ LDAP_SUCCESS LDAP_SERVER_DOWN @@ -478,16 +478,16 @@ LDAP_CONNECT_ERROR LDAP_CONTROL_PAGED /; use Net::LDAP::Util qw/ canonical_dn ldap_explode_dn /; -use Net::LDAP::LDIF; -use Net::LDAP::Extension::SetPassword; -use Net::LDAP::Control::Paged; -use Data::Dumper; -use File::Temp; -use Algorithm::Diff; +use Net::LDAP::LDIF qw//; +use Net::LDAP::Extension::SetPassword qw//; +use Net::LDAP::Control::Paged qw//; +use Data::Dumper qw//; +use File::Temp qw//; +use Algorithm::Diff qw//; use Carp 'confess'; +use POSIX qw//; use base 'Term::Shell'; - my $conf = $main::conf; # make 'die' backtrace in debug mode @@ -1410,6 +1410,8 @@ 'mv' => [ 'move', 'comp_cwd' ], 'touch' => [ 'create', 'comp_create' ], 'export' => [ 'setenv', 'comp_setenv' ], + '?' => [ 'help' ], + 'man' => [ 'help' ], ); @@ -2457,9 +2459,22 @@ $conf->{'timeout'} ||= 10; $conf->{'attributes'} ||= ['*']; -# create and enter shell loop -my $shell = LDAP::Shell->new(); + +# create and enter shell loop while also handling Ctrl+C correctly. +my $shell = LDAP::Shell->new; +my $sigset = POSIX::SigSet->new(); +sub ctrl_c_handler { + print "\n"; + $shell->term->on_new_line; + $shell->term->replace_line('', 0); + $shell->term->redisplay; +} +my $sigaction = POSIX::SigAction->new( \&ctrl_c_handler, $sigset, 0); +my $old_action = POSIX::SigAction->new; +POSIX::sigaction(&POSIX::SIGINT, $sigaction, $old_action); # save default one $shell->cmdloop(); +POSIX::sigaction(&POSIX::SIGINT, $old_action); # restore default one + ### load YAML config into global conf. ###