Move built-in commands to CustomCommands module and improve command handling
This commit is contained in:
parent
5d879616e8
commit
3b6dffa176
2 changed files with 37 additions and 26 deletions
25
pshell.pl
25
pshell.pl
|
@ -61,32 +61,15 @@ while (1) {
|
|||
next unless length $command;
|
||||
|
||||
# Try custom commands first
|
||||
if (CustomCommands::handle($command)) {
|
||||
my $cmd_status = CustomCommands::handle($command, $env);
|
||||
if ($cmd_status == 1) {
|
||||
next;
|
||||
}
|
||||
|
||||
# Handle cd command specially
|
||||
if ($command =~ /^cd\s*(.*)/) {
|
||||
my $dir = $1 || $ENV{HOME};
|
||||
chdir $dir or warn "Could not change to directory $dir: $!";
|
||||
elsif ($cmd_status == -1) {
|
||||
print "Command not found: $command\n";
|
||||
next;
|
||||
}
|
||||
|
||||
# Handle environment variable assignment
|
||||
if ($command =~ /^export\s+(\w+)=(.*)/) {
|
||||
$ENV{$1} = $2;
|
||||
$env->set($1, $2);
|
||||
next;
|
||||
}
|
||||
|
||||
# Handle environment variable display
|
||||
if ($command eq 'env') {
|
||||
print "$_=$ENV{$_}\n" for sort keys %ENV;
|
||||
next;
|
||||
}
|
||||
|
||||
# I guess we can insert more custom commands here
|
||||
|
||||
# Save command to history
|
||||
$history->add($command);
|
||||
$term->addhistory($command);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue