[BusyBox] uber-embedded lash prompt patch

Bryan Rittmeyer bryan at ixiacom.com
Tue Jan 30 22:31:47 UTC 2001


Hi,

The default lash prompt in BusyBox has, IMHO, been getting uglier and
uglier for those of us working on really deep embedded systems without
usernames or hostnames. Here's what the current prompt looks like for
me:

BusyBox v0.49 (2001.01.30-21:15+0000) Built-in shell (lash)
Enter 'help' for a list of built-in commands.

[0        @(none) /]# 

hideous! so today, I finally snapped and decided I just couldn't take
any more of it.

I've attached a really minimal patch that does the following:

1. Adds code to sh.c to create old-school (busybox-0.47) prompts.
2. Adds a Config.h option, disabled by default, to use the old-school
prompt code.

Here's the patch (which, as an added bonus, reduces binary size by a
whopping 150 bytes):

--- Config-old.h        Tue Jan 30 13:57:50 2001
+++ Config.h    Tue Jan 30 14:17:05 2001
@@ -262,6 +262,16 @@
 // Only relevant if BB_SH is enabled.
 #define BB_FEATURE_SH_TAB_COMPLETION
 //
+// Enable a simpler shell prompt of the form "path #"
+// instead of the default "[username at hostname path]#"
+//
+// Some deeply embedded systems don't have usernames or even hostnames,
+// and the default prompt can look rather hideous on them. Uncomment
+// this option for a simpler, path-only prompt (which was the default
until
+// around BusyBox-0.48):
+//
+//#define BB_FEATURE_SH_SIMPLE_PROMPT
+//
 // Attempts to match usernames in a ~-prefixed path
 // XXX: Doesn't work without NSS, off by default
 //#define BB_FEATURE_USERNAME_COMPLETION  /* require NSS */

--- sh-old.c    Tue Jan 30 13:57:46 2001
+++ sh.c        Tue Jan 30 14:26:31 2001
@@ -779,6 +779,24 @@
        }
 }
 
+#if defined(BB_FEATURE_SH_SIMPLE_PROMPT)
+static char* setup_prompt_string(int state)
+{
+       char prompt_str[BUFSIZ];
+
+       /* Set up the prompt */
+       if (state == 0) {
+               /* simple prompt */
+               sprintf(prompt_str, "%s %s", cwd, ( geteuid() != 0 ) ?
"$ ":"# ");
+       } else {
+               strcpy(prompt_str,"> ");
+       }
+
+       return(strdup(prompt_str));  /* Must free this memory */
+}
+
+#else
+
 static char* setup_prompt_string(int state)
 {
        char user[9],buf[255],*s;
@@ -809,6 +827,8 @@
        }
        return(strdup(prompt_str));  /* Must free this memory */
 }
+
+#endif 
 
 static int get_command(FILE * source, char *command)
 {

---

Apply if desired...

Regards,

Bryan

-- 
Bryan Rittmeyer
mailto:bryan at ixiacom.com
Ixia Communications
26601 W. Agoura Rd.
Calabasas, CA 91302





More information about the busybox mailing list