mirror of
https://github.com/zoriya/ash.git
synced 2026-06-02 10:45:07 +00:00
Merge branch 'prompt' of github.com:AnonymusRaccoon/ash into prompt
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
char *prompt_attr(int attr, bool off);
|
||||
char *minimal_hostname(char *hostname);
|
||||
char *date_format(int date);
|
||||
|
||||
char *get_prompt_value(char c, env_t *env);
|
||||
|
||||
|
||||
@@ -25,4 +25,12 @@ char *prompt_attr(int attr, bool off)
|
||||
|
||||
sprintf(str, "\x1B[%dm", attr + (off ? DISABLE_ATTR : 0));
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *date_format(int date)
|
||||
{
|
||||
static char format[3];
|
||||
|
||||
sprintf(format, "%02d", date);
|
||||
return (format);
|
||||
}
|
||||
@@ -13,6 +13,32 @@
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
char *get_prompt_value3(char c, env_t *env)
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm *tm = localtime(&t);
|
||||
static char name[10];
|
||||
|
||||
if (c == 'd') {
|
||||
strftime(name, sizeof(name), "%a", tm);
|
||||
return (name);
|
||||
}
|
||||
if (c == 'D')
|
||||
return (date_format(tm->tm_mday));
|
||||
if (c == 'w') {
|
||||
strftime(name, sizeof(name), "%b", tm);
|
||||
return (name);
|
||||
}
|
||||
if (c == 'W')
|
||||
return (date_format(tm->tm_mon + 1));
|
||||
if (c == 'y')
|
||||
return (&tostr(tm->tm_year + 1900)[2]);
|
||||
if (c == 'Y')
|
||||
return (tostr(tm->tm_year + 1900));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *get_prompt_value2(char c, env_t *env)
|
||||
{
|
||||
@@ -34,7 +60,7 @@ char *get_prompt_value2(char c, env_t *env)
|
||||
return (prompt_attr(REVERSE, true));
|
||||
if (c == '!' || c == 'h')
|
||||
return (tostr(history_size(env->history)));
|
||||
return (NULL);
|
||||
return (get_prompt_value3(c, env));
|
||||
}
|
||||
|
||||
char *get_prompt_value(char c, env_t *env)
|
||||
|
||||
Reference in New Issue
Block a user