Add PATH command lookup and improve command handling logic
This commit is contained in:
parent
3b6dffa176
commit
9204a8f519
2 changed files with 25 additions and 13 deletions
|
@ -36,14 +36,29 @@ our %COMMANDS = (
|
|||
|
||||
sub handle {
|
||||
my ($command, $env) = @_;
|
||||
|
||||
#print STDERR "DEBUG: Handling command: $command\n";
|
||||
# Check if this is a custom command
|
||||
foreach my $cmd (keys %COMMANDS) {
|
||||
if ($command =~ /^$cmd\b/) {
|
||||
#print STDERR "DEBUG: Found custom command: $cmd\n";
|
||||
return $COMMANDS{$cmd}->($command, $env) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
# Check if it's a system command
|
||||
my ($cmd_name) = split(/\s+/, $command);
|
||||
#print STDERR "DEBUG: Checking system command: $cmd_name\n";
|
||||
|
||||
# Check PATH directly
|
||||
foreach my $path (split(/:/, $ENV{PATH})) {
|
||||
my $full_path = "$path/$cmd_name";
|
||||
if (-x $full_path) {
|
||||
#print STDERR "DEBUG: Found in PATH: $full_path\n";
|
||||
system($command);
|
||||
return 2; # System command executed
|
||||
}
|
||||
}
|
||||
#print STDERR "DEBUG: Command not found: $command\n";
|
||||
return -1; # Command not found
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue