Configure and use Termux on Android

I'm sharing here some notes on how i use Termux on my phone. Mainly i use it for two tasks:
Keep up-to-date my git repos for on the go translations and download music without passing via pc.
For those who don't know Termux, it's a fantastic app for Android that you can find in F-Droid. With this app you can transform your phone in a command line terminal.
Let's go!

Setup Termux

Install Termux from F-Droid.
Once installed, at first start it will download the base environment.
Wait few seconds, then let's tweak a bit the UI to make it more comfy.
We will add some commands above the keyboard.

$ pkg install nano
$ mkdir -p ~/.termux/
$ nano ~/.termux/
Paste this into nano:
extra-keys = [['ESC','/','-','HOME','UP','END','PGUP'],['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN']]
This line will spawn some useful keys above the keyboard (without the need to switch to other special layouts).
Generic setup is done. Keep reading if you're interested to know the git repo thing or click here for the download music section.

Manage Git Repositories


Obviously we need to install git.

$ pkg install git
and we should set our username for git:
$ git config --global "NAME"
$ git config --global "USER@EMAIL.TLD"
We're already ready (!) to start! Let's download your forked repository locally. The only thing we need is the URL of your fork, that you can find usually just above the file list of the code, in the top right angle, in github is under the download or copy button, something like
$ git clone [forkURL.git] forkfolder
After some moments, it will download everything into forkfolder (choose the name you want of course). Now, we need to set up a link with the original project. Let's go in the folder that git just created.
$ cd forkfolder
Ok, once you're in we can finally set this link.
Here we need the original git project URL, to keep the same example as before, it will look like
$ git remote add upstream [originalURL.git]
And, to check if everything is good, run
$ git remote -v
It should show you 2 links for your fork and 2 for your original repo:
origin (fetch)
origin (push)
upstream (fetch)
upstream (push)
Ok we finished setup! Now we can finally sync!


First, we need to see what the original repo committed:

$ git fetch upstream
You should see a list of branch where commits were done. Not every repo has the same name as master branch. For example pleroma has develop, pixelfed has dev.
Check it out carefully!
Anyway, Tusky is an easy repository and has master as name of master branch. Check if you are going to merge the upstream work in the correct branch (in this example we should put master as branch).
$ git checkout [branch]
And now you can merge!
$ git merge upstream/[branch]
Once done, push this syncronization data online with
$ git push
It may ask you your credentials (user/password)
Aaand were done! :-)

Make edits locally

You have corrected a typo here locally and want to push to your repo. Very simple!
After an edit you just have to add a commit message with:

$ git commit -m"yourmessage"
$ git push

Update your fork

If you did some edits online instead, you should update your fork locally. It's really simple, you just need:

$ git pull
And you're done!

Download music


The tool we need to do this is Youtube-DL, but beside this we need to grant termux the access to the storage to save files.

$ pkg install termux-tools
$ termux-setup-storage
Now if you list the directories (with the command ls), you should see a storage folder with all the android subfolders.
Good now let's install youtube-dl and its prerequisites
$ pkg install python
$ pip install youtube-dl
$ pip install --upgrade pip
$ pip install --upgrade youtube-dl
$ pkg install ffmpeg


Youtube-DL has plenty of options to do almost anything. Here i'm writing what i use. I usually go to the folder i want to save the file (path may vary from device to device)

$ cd /storage/emulated/0/Music/
Then i launch the command with the URL of the video (it can also be an URL of a playlist)
$ youtube-dl --extract-audio --audio-format vorbis --add-metadata -x URLOFTHEVIDEO
Or if i have multiple video or multiple playlist, i write them all in a file and launch the download with
$ youtube-dl --extract-audio --audio-format vorbis --add-metadata -x -a LIST.TXT
A brief explaination of the parameters i'm using: This is just my choice, but again there are more and more options to use.


Add aliases to avoid to write everytime all that long string!

$ echo 'alias ytdl="youtube-dl --extract-audio --audio-format vorbis --add-metadata -x"' >> ~/.bashrc;
$ source ~/.bashrc;
So the command would become


Now and then launch these commands to keep all the programs updated:
$ pkg upgrade
and if you installed youtube-dl also
$ pip install --upgrade pip
$ pip install --upgrade youtube-dl