diff --git a/src/builtins/builtin_history.c b/src/builtins/builtin_history.c index 671638a..19db479 100644 --- a/src/builtins/builtin_history.c +++ b/src/builtins/builtin_history.c @@ -80,7 +80,7 @@ char *his_last_same_command(char *line, char *new_line = &line[his_variable->coord_variable + 1]; char *new_str = NULL; - for (int i = his_command->sz - 1; i >= 0; i--) { + for (int i = his_command->sz - 1; i > 0; i--) { if (his_command[i].command == NULL) { printf("%s: Event not found\n", new_line); return NULL; @@ -111,7 +111,7 @@ char *his_id_command(char *line, } new_line = concat_cmd_arg(his_command[id].command, his_command[id].arg); new_str = cat_in_str(his_variable, line, new_line); - printf("%s\n", new_line); + printf("%s\n", new_str); free(new_line); free(line); return new_str; @@ -151,7 +151,7 @@ char *his_last_word(char *line, if (!new_line) return NULL; new_str = cat_in_str(his_variable, line, new_line); - printf("%s\n", new_line); + printf("%s\n", new_str); free(new_line); free(line); return new_str; diff --git a/src/builtins/history.c b/src/builtins/history.c index 1779618..c28f1f8 100644 --- a/src/builtins/history.c +++ b/src/builtins/history.c @@ -14,7 +14,7 @@ int builtins_history(ef_t *ef, char **args __attribute__((unused))) { his_command_t *cmd_history = ef->builtin_handler->history_command; - for (int i = 0; i < cmd_history->sz; i++){ + for (int i = 1; i < cmd_history->sz; i++){ if (cmd_history[i].arg) { printf("%d %s %s\n", i, cmd_history[i].command, cmd_history[i].arg); diff --git a/src/shell.c b/src/shell.c index 26f8fe2..1ed7eff 100644 --- a/src/shell.c +++ b/src/shell.c @@ -94,12 +94,12 @@ his_command_t *init_cmd_history(void) if (cmd_history == NULL) return NULL; - for (int i = 0; i != 100; i++){ + for (int i = 1; i != 100; i++){ cmd_history[i].arg = NULL; cmd_history[i].command = NULL; cmd_history[i].id = i; } - cmd_history->sz = 0; + cmd_history->sz = 1; return cmd_history; }