Fixed autocompletion after command separators, spacing after quotes and somem more errors
This commit is contained in:
parent
844b413f26
commit
3ab9e3a769
@ -1,9 +1,6 @@
|
||||
#ifndef _SHELL_H
|
||||
#define _SHELL_H
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <features.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -23,5 +23,6 @@ void free_str_arr(char **arr);
|
||||
char **slice_array(char **arr, int beg, int end, bool asc);
|
||||
int get_null_term_arr_size(char **arr);
|
||||
int append_to_str_arr(char ***arr, int *sz, char *str);
|
||||
char *get_curr_dir_name();
|
||||
|
||||
#endif
|
@ -76,7 +76,7 @@ ssize_t get_dir_list(char ***dir_list, char *path, int ex)
|
||||
* @param size
|
||||
* @return ssize_t
|
||||
*/
|
||||
ssize_t append_builtin_list(char ***commands_list, size_t *size)
|
||||
ssize_t append_builtin_list(char ***commands_list, ssize_t *size)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
|
@ -106,6 +106,7 @@ char *read_line()
|
||||
}
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
|
14
src/shell.c
14
src/shell.c
@ -39,10 +39,12 @@ void process_command()
|
||||
status = execute(curr);
|
||||
|
||||
if (curr->stat.invert)
|
||||
{
|
||||
if (status == 0)
|
||||
status = 1;
|
||||
else
|
||||
status = 0;
|
||||
}
|
||||
|
||||
curr->stat.s = status;
|
||||
term.last_status = curr->stat.s;
|
||||
@ -350,19 +352,19 @@ char *compose_prompt()
|
||||
char *ip = get_ip_addr();
|
||||
if (ip == NULL)
|
||||
ip = "none";
|
||||
prompt = realloc(prompt, strlen(prompt) + 1 + strlen(ip) + strlen("\033[39m") + strlen("\033[48;2;28;32;35m") + 2);
|
||||
prompt = realloc(prompt, strlen(prompt) + 1 + strlen(ip) + strlen("\033[39m") + strlen("\033[0m") + 2);
|
||||
prompt = strcat(prompt, "@");
|
||||
prompt = strcat(prompt, ip);
|
||||
prompt = strcat(prompt, "\033[39m");
|
||||
prompt = strcat(prompt, "\033[48;2;28;32;35m");
|
||||
prompt = strcat(prompt, "\033[0m");
|
||||
prompt = strcat(prompt, ":");
|
||||
|
||||
// Current path
|
||||
char *full_path = get_current_dir_name();
|
||||
prompt = realloc(prompt, strlen(prompt) + strlen("\033[92;1m") + strlen("\033[39;0m") + strlen(full_path) + 2);
|
||||
char *full_path = get_curr_dir_name();
|
||||
prompt = realloc(prompt, strlen(prompt) + strlen("\033[92;1m") + strlen("\033[0m") + strlen(full_path) + 2);
|
||||
prompt = strcat(prompt, "\033[92;1m");
|
||||
prompt = strcat(prompt, full_path);
|
||||
prompt = strcat(prompt, "\033[39;0m");
|
||||
prompt = strcat(prompt, "\033[0m");
|
||||
free(full_path);
|
||||
|
||||
// Previous status
|
||||
@ -394,4 +396,6 @@ cmds_p *new_cmd()
|
||||
new->stat.s = 0;
|
||||
new->stat.invert = false;
|
||||
new->next = NULL;
|
||||
|
||||
return new;
|
||||
}
|
@ -169,3 +169,11 @@ int append_to_str_arr(char ***arr, int *sz, char *str)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *get_curr_dir_name()
|
||||
{
|
||||
char *pwd = malloc(FILENAME_MAX);
|
||||
getcwd(pwd, FILENAME_MAX);
|
||||
|
||||
return pwd;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user