prompt zsh style : quelques petits trucs a revoir
This commit is contained in:
parent
74713d84b0
commit
ab66992500
2 changed files with 61 additions and 13 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit b53fcb9db8b4baf53c73b17726f1740c4af12be0
|
Subproject commit acd7e54fb8045b3958dd239d469f1476404468b7
|
||||||
|
|
@ -1,22 +1,62 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* prompt.c :+: :+: :+: */
|
/* ftprompt.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/05 17:42:23 by gwojda ### ########.fr */
|
/* Updated: 2017/02/10 18:19:16 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static int ft_git_status(void)
|
||||||
|
{
|
||||||
|
int pip[2];
|
||||||
|
char *tmp;
|
||||||
|
char *line;
|
||||||
|
pid_t soon;
|
||||||
|
char *exec[] = {"git", "status", "--porcelain", "--branch", NULL};
|
||||||
|
|
||||||
|
pipe(pip);
|
||||||
|
if ((soon = fork()))
|
||||||
|
{
|
||||||
|
wait(&soon);
|
||||||
|
if (WEXITSTATUS(soon))
|
||||||
|
return (0);
|
||||||
|
close(pip[1]);
|
||||||
|
get_next_line(pip[0], &line);
|
||||||
|
tmp = line;
|
||||||
|
if (ft_strrchr(line, '/'))
|
||||||
|
line = ft_strdup(ft_strrchr(line, '/') + 1);
|
||||||
|
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
|
||||||
|
free(tmp);
|
||||||
|
if (!get_next_line(pip[0], &tmp))
|
||||||
|
printf("\x1b[38;5;83m %C ", L'✓');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\x1b[38;5;1m %C ", L'✗');
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
fflush(NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dup2(pip[1], 1);
|
||||||
|
dup2(pip[1], 2);
|
||||||
|
close(pip[0]);
|
||||||
|
execve("/usr/bin/git", exec, data_singleton()->env);
|
||||||
|
}
|
||||||
|
return (ft_strlen(line) + 8);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**ft_printf de la lib bug avec unicode
|
**ft_printf de la lib bug avec unicode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void ft_get_date(void)
|
static int ft_get_date(void)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
|
@ -32,6 +72,7 @@ static void ft_get_date(void)
|
||||||
else
|
else
|
||||||
printf("\x1b[38;5;184m%C ", L'★');
|
printf("\x1b[38;5;184m%C ", L'★');
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
|
return (10);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_currend_dir(void)
|
static int ft_currend_dir(void)
|
||||||
|
|
@ -47,21 +88,28 @@ static int ft_currend_dir(void)
|
||||||
j = ft_strlen(env[i]);
|
j = ft_strlen(env[i]);
|
||||||
while (j && env[i][j] != '/')
|
while (j && env[i][j] != '/')
|
||||||
--j;
|
--j;
|
||||||
ft_putstr(env[i] + j + 1);
|
ft_printf("%s ", env[i] + j + 1);
|
||||||
return (ft_strlen(env[i] + j + 1));
|
return (ft_strlen(env[i] + j + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_prompt(void)
|
void ft_prompt()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
do_job_notification();
|
do_job_notification();
|
||||||
ft_get_date();
|
// ft_get_date();
|
||||||
ft_putstr("\x1b[38;5;254m");
|
if (ft_getenv(data_singleton()->env, "?") && ft_atoi(ft_getenv(data_singleton()->env, "?")))
|
||||||
ret = ft_currend_dir();
|
printf("\x1b[38;5;1m%C ", L'➜');
|
||||||
ft_putstr("\x1b[38;5;184m");
|
else
|
||||||
printf(" %C ", L'›');
|
printf("\x1b[38;5;10m%C ", L'➜');
|
||||||
|
fflush(NULL);
|
||||||
|
ft_putstr("\x1b[38;5;361m");
|
||||||
|
ret += ft_currend_dir();
|
||||||
|
if (!(ret += ft_git_status()))
|
||||||
|
ret += ft_get_date();
|
||||||
|
printf("\x1b[38;5;184m%C ", L'›');
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
ft_putstr("\033[22;37m");
|
ft_putstr("\033[22;37m");
|
||||||
data_singleton()->line.prompt_size = ret + 13;
|
data_singleton()->line.prompt_size = ret + 6;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue