Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

Has anyone had any success modifying the shell prompt in Cyanogenmod? Presently, # is pretty useless, it would be much nicer to at least display the working directory. Also, is tab-completion possible?

share|improve this question
    
Usually the bash shell prompt can be modified by changing the environment variable PS1. –  Joachim Sauer Jul 18 '11 at 13:59
add comment

1 Answer 1

up vote 2 down vote accepted

I'm not too keen on the why, but sh on CyanogenMod is a bit watered down. As Joachim noted in the comments, usually you can modify PS1 to change your prompt, but it doesn't properly expand prompt variables:

# ps $$  <-- Just showing that the current shell is /system/bin/sh
ps $$
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
root      1055  129   756    340   c006abb8 afd0c44c S /system/bin/sh
# echo $PS1
echo $PS1
#
# PS1="\w # "
PS1="\w # "
\w #   <-- \w should be PWD

However, CyanogenMod does ship with a modified version of sh called ash (I believe this is for Android Shell), which does support a subset of these prompt variables. Here's some examples of what does and doesn't work, with local echo removed for the sake of clutter/space:

# ash
~ # echo $PS1
\w \$
~ # PS1="\u \w \\$ "
root ~ # PS1="\t \w \\$ "
         ~ # PS1="\l \w \\$ "
l ~ # PS1="\H \w \\$ "
H ~ # PS1="\h \w \\$ "  
localhost ~ # cd /sdcard
localhost /mnt/sdcard #

As for tab-completion: I don't personally know of a way to make this work. I imagine the main problem is actually that the adb shell buffers input up until you press enter, so the tab isn't actually sent to the shell program when you hit it. A good illustration of this is to open a file with more. The q key exits the more program, but you actually have to press q and then hit enter to quit because the initial q keystroke isn't sent until you press enter to send the whole buffer.


Okay, SSH is a different beast. Assuming you have a reasonably sane client ash will give you tab-completion along with the prompt variable expansion noted above. If you're using dropbear (the ssh daemon that ships with CyanogenMod) then you can configure ash to be the default prompt by logging into your device (either SSH or adb shell works here) and doing the following:

# echo "/system/xbin/ash" > /data/dropbear/.profile

This assumes /data/dropbear/.profile doesn't yet exist, because it will overwrite any existing version (this file is not created automatically, though). It can be edited instead if the file already exists, of course. Then restart dropbear and log in again. You should land at an ash session:

login as: root
Authenticating with public key "rsa-key-20110718"
TRACE (1391): entering fake-getpwnam
TRACE (1391): leaving fake-getpwnam
TRACE (1391): enter sign_key_free
TRACE (1391): enter dsa_key_free
TRACE (1391): leave dsa_key_free
TRACE (1391): enter rsa_key_free
TRACE (1391): leave rsa_key_free
TRACE (1391): leave sign_key_free
/data/dropbear # ps $$
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
root      1392  1391  1084   416   c006abb8 afd0c44c S /system/xbin/ash
/data/dropbear #
share|improve this answer
    
So how do I change SSH on the phone to have the default shell of ash rather than sh? –  Naftuli Tzvi Kay Jul 18 '11 at 15:40
    
@TKKocheran: Oh, I was thinking adb shell and not SSH. You'll get tab-completion with ash via an SSH connection. You're using dropbear, I'm guessing? To use ash by default you can just echo "/system/xbin/ash" > /data/dropbear/.profile and then restart dropbear. –  eldarerathis Jul 18 '11 at 16:43
    
@TKKocheran: This assumes you don't have a /data/dropbear/.profile file already, of course. Just edit or append if you have stuff in there that you don't want to overwrite. –  eldarerathis Jul 18 '11 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.