Android OS Forum banner
1 - 1 of 1 Posts

·
Digital Jedi
Joined
·
347 Posts
Hey everyone!

I don't know about you guys, but if there's anything I miss most from the terminal on my laptop on my Tb, it's tab-completion. Thus, I set out to stop using the standard sh at once, since support for it can't really be added in any simple way.

So, I've started using bash (the "Bourne-Again SHell"). It provides several advantages over the standard shell (especially if you're used to having a full-fledged terminal at your finger-tips). For instance, tab completion, color-coding for ls, permanent aliasing, command history (if your terminal emulator doesn't already support this) and even prompt customization.

This how-to will walk you through customizing your terminal emulator, so that it will feel less like an emulator and more like a terminal. It assumes that you are using ConnectBot, but most of these steps will likely be applicable to whatever terminal emulator you are using. And while many ROMs may come with bash installed, I am not aware of which ones do and which ones do not. If your ROM does not, the binary is attached to this post, and you will need to push it to system/xbin before you can do the steps below.

Step 1: Create a Local Session
Open up ConnectBot, and from the dropdown box in the lower left-hand corner of the screen, select "local". Give it whatever nickname you'd like. Mine is called "Bash", then press "Done" on the keyboard. You should now see a local terminal session in front of you.

Step 2: Set Session to run bash at startup
Press the back button so you have all your hosts listed. Long-press on the one you just created, select "Edit Host". Select "Post-login automation". In here type the following exactly (including line-break), then press "OK".
Code:
bash --rcfile /sdcard/.bashrc<br />
clear
While you're there, feel free to change any other cosmetic settings you'd like (font size for instance).

Step 3: Setup your .bashrc file
Press back so that you are viewing your hosts again, select the host we've been working on. You'll now be in a new terminal window with a standard bash prompt. From here, run "touch /sdcard/.bashrc" without quotes. Your .bashrc file has now been created, but it is empty. Now, you can edit this file with Root Explorer, a comparable file manager, a graphical text editor or, if you'd like, a text-based text-editor from the terminal. I use nano, but that is my personal preference. Most people, for their prompt care most about the pwd and not so much about the hostname or user name, so we'll setup the .bashrc file to display only the pwd, and if you wish to show other things in your prompt, you can edit the .bashrc file later, or just customize it now. To make the prompt appear like this, we need to have this line in the .bashrc file:
Code:
PS1="[\w]\\$ "
But, we also want a good command history to be kept. So, we should add this line just after the first:
Code:
HISTFILE=/sdcard/.bash_history
Now your prompt will appear only with the present working directory. However, by default, the su binary will open in a standard shell rather than bash, so we want to add a permanent alias to su so that it will automatically go to bash. I have my alias setup like this:
Code:
alias su='su -c "bash"'
Save and Exit, and your bashrc file has been setup. Keep in mind, if you ever want to add an alias permanently, you can always come back and edit your .bashrc file to have more. My .bashrc file looks like this:
Code:
#Prompt Appearance Customization<br />
PS1="[\w]\\$ "<br />
HISTFILE=/sdcard/.bash_history<br />
<br />
#Personal Functions<br />
function sudo{ <br />
#A friend suggested this. Now, you will [I]not[/I] need to surround the passed command with quotes.<br />
su -c "$*"<br />
}<br />
<br />
#Personal Aliases<br />
alias su='sudo bash'<br />
alias ll='ls -l'<br />
alias la='ls -A'<br />
alias lla='ls -Al'<br />
alias mountrw='sudo mount -o remount,rw /device/block/mmcblk0p25 /system'<br />
alias mountro='sudo mount -o remount,ro /device/block/mmcblk0p25 /system'
Feel free to use it and build upon it if you would like.

Step 4: Finishing touches and customizations
If you haven't yet noticed, Android is a rather silly implementation of Linux (though I do still love it). Perhaps one of the most blaring examples of how silly it is comes in the form of not having a users filesystem, and therefore, you don't have a home folder (i.e., "~"). Bash, luckily, automatically assumes that /sdcard/ is your home directory, which means, from here on out, you can save things to ~ rather than to /sdcard/. But, there are many other directories that are not by default available in their same place. For instance, I am used to there being a /usr folder and an /etc folder. But neither of these exist by default, so the best way is to symlink them from /system.
Code:
<br />
su<br />
mount -o remount,rw rootfs /<br />
ln -s /system/usr/ /<br />
ln -s /system/etc/ /<br />
mount -o remount,ro rootfs /<br />
exit
Now, you should have a /etc and a /usr folder available to you from the root of your internal!

Step 5: Profit???
If you feel like this tutorial has been extremely helpful to you, or if you just think I have a really cool user name, please consider signing up for a dropbox using my referral link in-signature and installing the software. That way I can host more files for the Android Community. Also note, once you've synced the software to the account you've made using my referral, you can uninstall it if you don't want it, I will still have received the space increase.

As always, happy flashing, and all the best!

-HG

Bash.zip: Dropbox Mirror
 
1 - 1 of 1 Posts
Top