[BusyBox] New version cmdedit

Vladimir N. Oleynik dzo at simtreas.ru
Sun Feb 18 12:25:40 UTC 2001


Erik Andersen wrote:

> > Similar, I shall not have time to finish 
> > BB_FEATURE_VARIABLE_COMPLETION
> > up to an exit of the version busybox 0.50.
> > The final variant cmdedit for inclusion lays as always:
> >
> > ftp://ftp.simtreas.ru/pub/my/bb/new/
> 
> Applied, this looks very good.  I think we need to decide were 
> to put the prompt functions.  Right now, we have 
> setup_prompt_string() in sh.c and
> BB_FEATURE_BASH_STYLE_PROMT in cmdedit.c 
> doing the same type of thing.  
> I think the prompt code really should be in sh.c and the shell should
> just pass a final prompt string to cmdedit.  Do you agree?

Thanks.

I think:


1) Add code to init (and login.c in tynylogin) :

+ static char *prmt_str;

char *environment[] = { 
+ prmt_str,
0
};


init.c(login.c):main()

+ prmt_str = first_setup_prompt_string();



2) add first_setup_prompt_string() to utilites.c

char* first_setup_prompt_string(void)
{

#ifdef BB_FEATURE_BASH_STYLE_PROMPT
	return "PS1=\\[\\033[34;1m\\]\\u@\\[\\033[0m\\]\\h:\\w \\!\\$ ";
#else

#ifndef BB_FEATURE_SH_SIMPLE_PROMPT
        char user[9],buf[255],*s;
	char prompt_str[BUFSIZ];
#endif
        char prompt[3];
        

        /* Set up the prompt */
        /* get User Name and setup prompt */
        strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# ");
        my_getpwuid(user, geteuid());

#ifdef BB_FEATURE_SH_SIMPLE_PROMPT
	return xstrdup(prompt);
#else
        /* get HostName */
        gethostname(buf, 255);
        s = strchr(buf, '.');
        if (s) 
                 *s = 0;
        snprintf(prompt_str, BUFSIZ-1, "[%s@%s %s]%s", user, buf,
                        get_last_path_component(cwd), prompt);

#endif	/* BB_FEATURE_SH_SIMPLE_PROMPT */

	return xstrdup(prompt_str);

#endif	/* BB_FEATURE_BASH_STYLE_PROMPT */
}
 

3) Change in sh.c:

+	startic char *env_prompt_str;

get_command(....)

-       prompt_str = setup_prompt_string(shell_context);
+	if(env_prompt_str==0) {
+		env_prompt_str = getenv("PS1");
+		if(env_prompt_str==0) 
+			env_prompt_str=first_setup_prompt_string();
+	}
+	
+	prompt_str = shell_context==0 ? env_prompt_str : "> ";

...

- 	free(prompt_str);


Bonuses: 

a) can rewrite env_prompt_str in builtin_env()!
b) users can change in runtime also with compiled mode
BB_FEATURE_SH_SIMPLE_PROMPT!
c) remove any xstrdup() and free() - speed and size gain!


--w
vodz





More information about the busybox mailing list