Move built-in commands to CustomCommands module and improve command handling

This commit is contained in:
kake26 2025-04-15 13:59:48 -05:00
parent 5d879616e8
commit 3b6dffa176
Signed by: kake26
GPG key ID: E0A989B571D1F99F
2 changed files with 37 additions and 26 deletions

View file

@ -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);