aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 0c48e8179..c3b5738e2 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -57,12 +57,23 @@
57#if ENABLE_FEATURE_EDITING 57#if ENABLE_FEATURE_EDITING
58 58
59 59
60#if !ENABLE_SHELL_ASH && !ENABLE_SHELL_HUSH
61/* so far only shells use these features */
62# undef ENABLE_FEATURE_EDITING_FANCY_PROMPT
63# undef ENABLE_FEATURE_TAB_COMPLETION
64# undef ENABLE_FEATURE_USERNAME_COMPLETION
65# define ENABLE_FEATURE_EDITING_FANCY_PROMPT 0
66# define ENABLE_FEATURE_TAB_COMPLETION 0
67# define ENABLE_FEATURE_USERNAME_COMPLETION 0
68#endif
69
70
60#define ENABLE_USERNAME_OR_HOMEDIR \ 71#define ENABLE_USERNAME_OR_HOMEDIR \
61 (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) 72 (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT)
62#define IF_USERNAME_OR_HOMEDIR(...)
63#if ENABLE_USERNAME_OR_HOMEDIR 73#if ENABLE_USERNAME_OR_HOMEDIR
64# undef IF_USERNAME_OR_HOMEDIR
65# define IF_USERNAME_OR_HOMEDIR(...) __VA_ARGS__ 74# define IF_USERNAME_OR_HOMEDIR(...) __VA_ARGS__
75#else
76# define IF_USERNAME_OR_HOMEDIR(...) /*nothing*/
66#endif 77#endif
67 78
68 79
@@ -743,11 +754,11 @@ static unsigned path_parse(char ***p)
743 char *tmp; 754 char *tmp;
744 char **res; 755 char **res;
745 756
746#if EDITING_HAS_path_lookup 757# if EDITING_HAS_path_lookup
747 if (state->flags & WITH_PATH_LOOKUP) 758 if (state->flags & WITH_PATH_LOOKUP)
748 pth = state->path_lookup; 759 pth = state->path_lookup;
749 else 760 else
750#endif 761# endif
751 pth = getenv("PATH"); 762 pth = getenv("PATH");
752 763
753 /* PATH="" or PATH=":"? */ 764 /* PATH="" or PATH=":"? */
@@ -1885,9 +1896,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1885{ 1896{
1886 int prmt_size = 0; 1897 int prmt_size = 0;
1887 char *prmt_mem_ptr = xzalloc(1); 1898 char *prmt_mem_ptr = xzalloc(1);
1888# if ENABLE_USERNAME_OR_HOMEDIR
1889 char *cwd_buf = NULL; 1899 char *cwd_buf = NULL;
1890# endif
1891 char flg_not_length = '['; 1900 char flg_not_length = '[';
1892 char cbuf[2]; 1901 char cbuf[2];
1893 1902
@@ -1954,11 +1963,9 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1954 c = *prmt_ptr++; 1963 c = *prmt_ptr++;
1955 1964
1956 switch (c) { 1965 switch (c) {
1957# if ENABLE_USERNAME_OR_HOMEDIR
1958 case 'u': 1966 case 'u':
1959 pbuf = user_buf ? user_buf : (char*)""; 1967 pbuf = user_buf ? user_buf : (char*)"";
1960 break; 1968 break;
1961# endif
1962 case 'H': 1969 case 'H':
1963 case 'h': 1970 case 'h':
1964 pbuf = free_me = safe_gethostname(); 1971 pbuf = free_me = safe_gethostname();
@@ -1976,7 +1983,6 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1976 strftime_HHMMSS(timebuf, sizeof(timebuf), NULL)[-3] = '\0'; 1983 strftime_HHMMSS(timebuf, sizeof(timebuf), NULL)[-3] = '\0';
1977 pbuf = timebuf; 1984 pbuf = timebuf;
1978 break; 1985 break;
1979# if ENABLE_USERNAME_OR_HOMEDIR
1980 case 'w': /* current dir */ 1986 case 'w': /* current dir */
1981 case 'W': /* basename of cur dir */ 1987 case 'W': /* basename of cur dir */
1982 if (!cwd_buf) { 1988 if (!cwd_buf) {
@@ -2003,7 +2009,6 @@ static void parse_and_put_prompt(const char *prmt_ptr)
2003 if (cp) 2009 if (cp)
2004 pbuf = (char*)cp + 1; 2010 pbuf = (char*)cp + 1;
2005 break; 2011 break;
2006# endif
2007// bb_process_escape_sequence does this now: 2012// bb_process_escape_sequence does this now:
2008// case 'e': case 'E': /* \e \E = \033 */ 2013// case 'e': case 'E': /* \e \E = \033 */
2009// c = '\033'; 2014// c = '\033';
@@ -2064,10 +2069,8 @@ static void parse_and_put_prompt(const char *prmt_ptr)
2064 free(free_me); 2069 free(free_me);
2065 } /* while */ 2070 } /* while */
2066 2071
2067# if ENABLE_USERNAME_OR_HOMEDIR
2068 if (cwd_buf != (char *)bb_msg_unknown) 2072 if (cwd_buf != (char *)bb_msg_unknown)
2069 free(cwd_buf); 2073 free(cwd_buf);
2070# endif
2071 /* see comment (above this function) about multiline prompt redrawing */ 2074 /* see comment (above this function) about multiline prompt redrawing */
2072 cmdedit_prompt = prompt_last_line = prmt_mem_ptr; 2075 cmdedit_prompt = prompt_last_line = prmt_mem_ptr;
2073 prmt_ptr = strrchr(cmdedit_prompt, '\n'); 2076 prmt_ptr = strrchr(cmdedit_prompt, '\n');
@@ -2075,7 +2078,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
2075 prompt_last_line = prmt_ptr + 1; 2078 prompt_last_line = prmt_ptr + 1;
2076 put_prompt(); 2079 put_prompt();
2077} 2080}
2078#endif 2081#endif /* FEATURE_EDITING_FANCY_PROMPT */
2079 2082
2080#if ENABLE_FEATURE_EDITING_WINCH 2083#if ENABLE_FEATURE_EDITING_WINCH
2081static void cmdedit_setwidth(void) 2084static void cmdedit_setwidth(void)