holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.69k stars 117 forks source link

can i alias 2 command in one word? #832

Open Mrlaolu opened 1 month ago

Mrlaolu commented 1 month ago

like this

[~/Documents]$ alias run="'clang++ a.cpp -o a' ;'./a'"
[~/Documents]$ run
clang++ a.cpp -o a: command not found
[~/Documents]$ clang++ a.cpp -o a
[~/Documents]$ 
holzschu commented 1 month ago

The default shell in a-Shell is highly simplified, both for performance reasons and for historical reasons (backward compatibility). It doesn't have the ability to run two commands on the same line (also, if you enclose the command in quotes, it means you want to run the command "clang++ a.cpp -o a" in a single word, which results in "Command not found").

For advanced stuff, there is another shell (dash), which has more abilities. Your alias might work there. Otherwise, the simplest version is to make a shell script:

#! sh

programname=$1

clang++ $programname.cpp -o $programname
./$programname
Mrlaolu commented 1 month ago

It works,Thanks!And I want to know use shortcut key to stop(or kill) a command.(where i can learn all the shortcut keys that a-shell have)

holzschu commented 1 month ago

The shortcut keys are the usual ones for a Unix terminal: ^C to stop a program, ^D for harder interupt, ^E to the end of line when editing, ^A for begining of line when editing... They're all based on control + key, unless you have an external keyboard connected.

The catch is that ^C will only send interupt to the program. It's up to the program to listen to that interruption (which is unlikely for small C++ programs). You would need to add a line in your code that checks if there is something new on stdin (without stopping) and stops if that something new is ^C.