diff --git a/lib/CustomCommands.pm b/lib/CustomCommands.pm index 033195d..63120f8 100644 --- a/lib/CustomCommands.pm +++ b/lib/CustomCommands.pm @@ -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 } diff --git a/pshell.pl b/pshell.pl index 8b3cf35..ba27f74 100755 --- a/pshell.pl +++ b/pshell.pl @@ -60,20 +60,17 @@ while (1) { # Skip empty commands next unless length $command; - # Try custom commands first + # Handle command my $cmd_status = CustomCommands::handle($command, $env); - if ($cmd_status == 1) { - next; - } - elsif ($cmd_status == -1) { - print "Command not found: $command\n"; + if ($cmd_status >= 0) { # 1=handled, 2=system command + # Save valid commands to history + $history->add($command); + $term->addhistory($command); next; } - # Save command to history - $history->add($command); - $term->addhistory($command); - - # Execute command - system($command); + # Command not found + #print STDERR "DEBUG: Main program detected command not found\n"; + print "Command not found: $command\n"; + next; }