3

I had to resort to using Termux since the developer of Servers Ultimate Pro has not been updating the Node.js package for a long time and the new ES6 features are breaking my scripts. After browsing instructions, I've got latest Node.js installed through apt-get and I can run my script.

However, I have to type:

$node storage/shared/folder_in_internal_android_memory/app.js

If possible could I make a bash script called "bot.sh" with:

#!bin/bash
node storage/shared/folder_in_internal_android_memory/app.js

Then run with:

$bot

I can cp an already created script but I don't know where to place it to allow me to shortcut it.

4

How about using aliases?

nano/vi (or whatever you edit with) /data/data/com.termux/files/usr/etc/bash.bashrc

Add for each alias;

alias nodeapp='node storage/shared/folder_in_internal_android_memory/app.js'

8
  • I just tested alias s="node storage/shared/folder_in_internal_android_memory/app.js" and ran s`. It works but it's not remembered for all sessions. Once I close Termux it forgets the command. Is it possible to set it to permanent remember it for all future sessions? – Nova Oct 6 '17 at 0:50
  • Did you just enter the alias, or did you edit the mentioned file and the alias still didn't persist? – anders Oct 6 '17 at 1:13
  • The node file still exist. It just forgets the alias. – Nova Oct 6 '17 at 1:18
  • That was not what I meant. Did you edit: /data/data/com.termux/files/usr/etc/bash.bashrc ? – anders Oct 6 '17 at 1:18
  • Actually, I'm actually following this plus.google.com/+KanatTabaldiev/posts/RKavjA1zaCp now but I can't seem to get VIM to exit when I type :x and enter. I presume I just type s="node storage/shared/folder_in_internal_android_memory/app.js on one line and save. – Nova Oct 6 '17 at 1:22
6

You need to place the script in ~/.shortcuts/ and install the Termux:Widget app. Then Termux:Widget options appear in your homescreen launcher's widgets list.

Per nico's comment below, to access a typical launcher's widget list, long-press an empty space and tap the option that says "widgets" or "all shortcuts". Then find and long-press the desired Termux shortcut widget and drop it where you want.

Also note that Android lacks /bin and /usr/bin, so it is necessary to change LD_PRELOAD by running pkg install termux-exec and then restarting Termux.

2
  • 1
    I spent a long time googling to find “the usual place to add widgets to your home screen”, because I thought it was a Termux feature, when in fact it is an Android feature. For those who don’t know it yet, the solution is to press and hold on an empty space on your home screen and then tap Widgets / All shortcuts. I found the solution here: samsung.com/uk/support/mobile-devices/… – nico May 26 '18 at 19:06
  • @nico Thanks for the feedback! I updated the answer to be clearer (and also updated the /bin and /usr/bin workaround while I was at it). – Mark Haferkamp Jun 30 '18 at 10:40
1

Mark's answer got me on the right trail which is probably beyond the scope of what the OP asked for but I guess this might help other looking for some more automated solution:

The Termux:Task (com.termux.tasker) app allows to integrate execution of scripts into custom flows for tasker (and compatible, like Automate) programs.

Note that scripts to be executed need to be put to ~/.termux/tasker/ (folder also needs to be created).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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