aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar BanceDev 2024-09-01 23:18:36 -0400
committerGravatar BanceDev 2024-09-01 23:18:36 -0400
commit112a83175cd87f3cedbce61a67d73e86a24d3957 (patch)
tree49bcc3c1fa8ce5254e789c1c5685d6f0a88639be /src
parentlunar shell logo (diff)
updated help and fixed SIGINT
Diffstat (limited to 'src')
-rw-r--r--src/help.h36
-rw-r--r--src/lush.c26
2 files changed, 56 insertions, 6 deletions
diff --git a/src/help.h b/src/help.h
new file mode 100644
index 0000000..80c9bb3
--- /dev/null
+++ b/src/help.h
@@ -0,0 +1,36 @@
+#ifndef HELP_H
+#define HELP_H
+
+char *lush_get_help_text() {
+ return "    ..,;;;;;::::::::cccccclllllooooddddxxxdoc,    \n"
+"  .,;;,,'',,,,,,,,,,,;;;;;;;:::::::cccccllloxkxc  \n"
+" ,,,.                                        'oOk.\n"
+".,,               ......                       dOx\n"
+",;'       .:c.   ;::::::                       cOO\n"
+";;'         :Nl  ;::::::                       :O0\n"
+";;'          KN: ;::::::                       :00\n"
+";;'         :NNl ;::::::                       :00\n"
+";;' l:....;kNNk. ;::::::                       :00\n"
+"::'  ;x0XNX0d,   ;::::::                       :00\n"
+"::'              '''''''                       :00\n"
+"::'                                            :00\n"
+"::'                                            :00\n"
+"::'                                            :00\n"
+"cc,                                            :00\n"
+"cc,                                            :00\n"
+"cc,                                            :00\n"
+":c;                                            c00\n"
+".lc                                            k0;\n"
+" .lc.                                       .,x0; [0\n"
+"    oollccccllllllllooooooodddddddxxxxxxxxxk00.   \n"
+"       .dddddxxxxxxkkkkkkOOOOOO00000000000        \n"
+".____ _________.__ .__ .__ \n"
+"| | __ __ ____ _____ _______ / _____/| |__ ____ | | | | \n"
+"| | | | \\/ \\\\__ \\\\_ __ \\ \\_____ \\ | | \\_/ __ \\| | | | \n"
+"| |___| | / | \\/ __ \\| | \\/ / \\| Y \\ ___/| |_| |__\n"
+"|_______ \\____/|___| (____ /__| /_______ /|___| /\\___ >____/____/\n"
+" \\/ \\/ \\/ \\/ \\/ \\/ \n";
+
+}
+
+#endif // HELP_H
diff --git a/src/lush.c b/src/lush.c
index 9094c57..846ce20 100644
--- a/src/lush.c
+++ b/src/lush.c
@@ -16,9 +16,11 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "lush.h"
+#include "help.h"
#include <bits/time.h>
#include <linux/limits.h>
#include <pwd.h>
+#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -71,8 +73,12 @@ int lush_cd(char ***args) {
}
int lush_help(char ***args) {
- // TODO: make this more fun
- printf("Lunar Shell Help Page\n\n");
+ printf("%s\n", lush_get_help_text());
+#ifdef LUSH_VERSION
+ printf("Lunar Shell, version %s\n", LUSH_VERSION);
+#endif
+ printf("These shell commands are defined internally. Type 'help' at any "
+ "time to reference this list.\n");
printf("Available commands: \n");
for (int i = 0; i < lush_num_builtins(); i++) {
printf("- %s\n", builtin_strs[i]);
@@ -102,7 +108,7 @@ int lush_time(char ***args) {
elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0 +
(end.tv_nsec - start.tv_nsec) / 1e6;
- printf("Time: %.3f milliseconds", elapsed_time);
+ printf("Time: %.3f milliseconds\n", elapsed_time);
// return pointer back to "time" for free()
args[0]--;
@@ -278,12 +284,20 @@ int lush_execute_pipeline(char ***commands, int num_commands) {
void lush_execute_command(char **args, int input_fd, int output_fd) {
// create child
pid_t pid;
- pid_t wpid;
int status;
+ // ignore SIGINT in the parent process
+ struct sigaction sa;
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGINT, &sa, NULL);
+
if ((pid = fork()) == 0) {
// child process content
+ // restore default sigint for child
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGINT, &sa, NULL);
+
// redirect in and out fd's if needed
if (input_fd != STDIN_FILENO) {
dup2(input_fd, STDIN_FILENO);
@@ -307,7 +321,7 @@ void lush_execute_command(char **args, int input_fd, int output_fd) {
} else {
// parent process
do {
- wpid = waitpid(pid, &status, WUNTRACED);
+ waitpid(pid, &status, WUNTRACED);
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
}
@@ -353,7 +367,7 @@ int main() {
}
// Print the prompt
- printf("%s@%s:%s$ ", username, device_name, prompt_cwd);
+ printf("[%s@%s:%s] ", username, device_name, prompt_cwd);
char *line = lush_read_line();
char **commands = lush_split_pipes(line);