Sitemap
Mohamed Abdul Latheef

Mohamed Abdul Latheef

A Project Manager, Civil Engineer, Web programmer but not necessarily in that order

Adding some bling to your Android terminal

Customizing Termux

8 min readAug 26, 2020

--

Termux application running on an android device
Background image by Markus Spiske from Pexels

After installing Termux and playing around with it for a while, you might be tempted to adjust the look and feel of Termux. Possibly you have in the past, worked on some Linux distro and been accustomed with adding eye candy to it by using themes, and would like to do the same here. Or you are not comfortable with the bland default setup that Termux provides out of the box.

A possibility to customize Termux would be to buy the styling add-on available from the store. Doing some of the things covered in this article is a bit easier that way and you support the app developers. It’s a win win.

Setting up dark mode

You might be wondering, well, Termux is already dark enough. Termux, even though not obvious initially because the terminal itself is set to using a dark palette by default, is using light mode. This is obvious when you open the side panel housing all the Termux sessions. Open this side panel by swiping from the left edge of the screen and you’ll see that it’s distinctively white.

Press enter or click to view image in full size
Termux with light theme showing up in the side panel
Termux, using default light theme

Let’s fix that. If it doesn’t already exist, create a file called termux.propeties within the Termux config folder

touch ~/.termux/termux.properties

Open this file in your favorite editor. Throughout this article I’m using Vim.

vim ~/.termux/termux.properties

Add the following line to this file

use-black-ui = true

Save and exit the file. Restart your Termux session completely. Now if you open the side panel, you will find it that it’s appealingly black in appearance and consistent with the terminal itself.

Press enter or click to view image in full size
Termux with dark theme showing in the side panel
Using the dark theme in it’s interface

Some usability hacks

To create and switch between sessions, you’ll find yourself increasingly opening and closing the side panel. This becomes a menial task quickly, specially as your app becomes bigger and more complicated. Wouldn’t it be easier to use a shortcut to do these tasks?

If you skipped the first step, create the config file used by Termux and open it in your editor of choice (vim in my case)

touch ~/.termux/termux.propertiesvim ~/.termux/termux.properties

Add the following lines to the config

...
...
shortcut.create-session = ctrl + t
shortcut.next-session = ctrl + 2
shortcut.previous-session = ctrl + 1

Exit the editor and Termux. Restart it and now to create a new session, hit Ctrl-T. To switch back and forth between the sessions hit Ctrl-1 and Ctrl-2. The Ctrl key is within the Termux interface, at the very bottom.

Change the default shell to zsh

Bash is the default shell in Termux, but not the only option available. You can also switch it use zsh or fish. This article focuses on using zsh. Zsh let’s you do a lot of useful things that is not possible with bash. You can have syntax highlighting of your input command, auto suggestions, type ahead auto completion, customizing the prompt and enabling vi-mode, just a few selection of things that can be done in zsh which will be covered in this article.

Install zsh and set it to be your default shell by running the following commands

pkg install zsh
chsh zsh

To customize zsh you’ll need to create zsh config file in your home directory, if it doesn’t already exist.

touch ~/.zshrc

Install Oh My Zsh

Oh my zsh is a community maintained plugin framework that helps to customize zsh easily. To cite the developers own tongue in cheek description:

Oh My Zsh will not make you a 10x developer...but you may feel like one. — oh-my-zsh developers

Oh my zsh, it’s plugins and themes are not found on the Termux repos so the following steps are required manual installation. If you don’t already have it, you’ll also need to install wget

pkg install wget
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

The installation script should take care of everything, including adding some lines to your zsh config file. You can inspect the changes by using the less command

less ~/.zshrc

All your zsh related scripts are now housed in the oh-my-zsh folder, hidden in your home directory. Oh-my-zsh will prompt you for updates every once in awhile, useful to keep the framework, it’s themes and plugins updated.

Get syntax highlighting

After installing zsh, you might have expected the commands you input to be colorful. It won’t, it’ll be still a dull white. You might have expected it to be so after installing oh-my-zsh but alas, still no. Still bland. To get that feature, you’ll need an unofficial plugin (unofficial as it’s not maintained either by zsh or by oh-my-zsh)

Get Mohamed Abdul Latheef’s stories in your inbox

Join Medium for free to get updates from this writer.

Now would be a good time to install git, if you don’t already have it. If you are doing some serious programming, you’ll will need it anyway, now is a good time as any.

pkg install git

To use the unofficial plugin along side oh-my-zsh, run the following code

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Now that it’s inside the oh-my-zsh’s plugin folder, you need to specify, zsh to use it. While doing that, also add the git plugin, since it’s a plugin that’s already installed along with oh-my-zsh framework. Open up zsh config file in vim (or text editor of your choice)

vim ~/.zshrc

Scroll down to the plugins section, which in a standard installation, should be empty. Let’s update it to use the aforementioned plugins¹.

...
...
plugins=(
git
zsh-syntax-highlighting

)
...
...

Notice that there are no commas, or any other delimiters at the end of the plugin names. Save your file and source your config file to see the effect.

source ~/.zshrc

Your input commands should now show some syntax highlighting. To read about the git plugin and what it does you can go here

  1. Just make sure that this plugin is always the last one sourced in the plugin section

Type ahead hinting

This is a great feature to have, and useful too while adding some subtle eye candy. Grab the needed plugin zsh-autosuggestions. The plugin addition goes in a similar manner to the previous plugin we added

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
vim ~/.zshrc

Add the zsh-autosuggestions plugin to the zsh config file, in the plugin section. If you followed along from the previous section, the plugin section should like this now

...
...
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
...
...

To see the changes in effect open a new terminal session (from the side panel in Termux or Ctrl-T if you have setup the shortcut), or source the modified zsh config file

source ~/.zshrc

Now, as you type, you would get suggestions on the fly in a way that’s not obstructive, based on your command history. To accept the suggestion, hit the tab button on your Termux interface.

Press enter or click to view image in full size
Termux with type-ahead hinting enabled in zsh shell
Type ahead hinting enabled.

Changing the zsh theme

By default, zsh comes with a theme ‘robbyrussel’ enabled. If you went through the zsh config file, you would have seen the ZSH_THEME variable that controls this.

oh-my-zsh comes with a handful of themes with it’s standard installation. Some themes require use of special fonts, others may even require separate packages to be installed. After finding the one that suites you, change the ZSH_THEME variable to the name of the theme. For example, to change to agnoster theme, just change the variable to

ZSH_THEME="agnoster" 

To view the changes, source the modified .zshrc file again, or open a new terminal session

source ~/.zshrc

If you do change the theme to agnoster, just note that it may not look so good as it requires patched Vim-Powerline fonts. Not all themes looks great on the form factor we are working on either. I stick with the default in my configuration because for my purpose, it looks good

Enabling Vi-mode

If you don’t use vim, or hate vim in general, you can skip this section all together. zsh by default is setup to use the emacs-mode, which is good but I’ve fallen head over heels to vim so enabling vi-mode is the natural next step for me.

vi-mode is a plugin available in the standard installation of oh-my-zsh. Enabling it is simple; add it to the plugin sections of your zsh config file

plugins=(
git
vi-mode
zsh-autosuggestions
zsh-syntax-highlighting
)

Source the modified config file to see the change in effect

source ~/.zshrc

Zsh always open in insert mode. To go to visual mode, hit ESC on the Termux interface and make changes to the written command. To go back to insert mode, press i

vi-mode isn’t perfect and it isn’t for everyone. It also conflicts with the zsh-autosuggestions plugin so after getting the command hint, you will have to go to visual mode and hit the l-key (the direction key).

Customizing startup prompt

Termux comes with a startup prompt with useful information about itself, basic commands to help a first time user. But it gets boring real quick. Let’s replace that altogether with something fancy and useful

To remove the default startup messages is easy; create an empty file called .hushlogin in your home folder

touch ~/.hushlogin

Now new sessions of Termux should open without any messages. To add a more useful and at the same time, colorful startup message we are going to make use of neofetch

Install neofetch by issuing the following command

pkg install neofetch

Once it pulls in all the needed packages append the neofetch command to the the end of the zsh config file

# ~/.zshrc...
...
neofetch

New sessions of Termux now opens up with a nice ASCII art logo of android and useful system information. The nice thing about neofetch is how well it fits inside the form factor we are using.

To customize the information in neofetch, you will need to open the neofetch config file

vim ~/.config/neofetch/config.conf

For example, to show your public and local ip address just uncomment the following lines in the config file

print_info() {
...
...
info "Local IP" local_ip
info "Public IP" public_ip

...
...
}

You have a fine tuned control of different aspects of neofetch in this file, including the ASCII art and the colors used. Have a look at the documentation

Press enter or click to view image in full size
Press enter or click to view image in full size
Before and after comparison with default Termux welcome screen (left) and neofetch enabled (right)

Conclusion

Now that Termux looks nice and is useful, it’s time to create your next great application, right on your phone.

Good luck

--

--

Written by Mohamed Abdul Latheef

A Project Manager, Civil Engineer, Web programmer but not necessarily in that order