Tag: bash

Enabling command history in terminal programs like Sicstus

When you get used to pressing the up arrow for history items, the tab auto-complete feature and other handy features in the Linux terminal, it can be irritating when the occasional program behaves differently.

I have been using SICStus Prolog for my CS Prolog course and have been irritated by SICStus picking up the up arrow key as ^[[A and not retrieving the last thing I typed.

To get it to work like the Bash shell and other programs do, you can use rlwrap [program].

This program allows you to ‘wrap’ a program you’re running, like SICStus, in the readline attribute. This contains the features you’re used to. Just type something like this at the terminal, e.g.

It will ‘wrap’ your program in the readline function and work as expected. Voila!

If you want more information on rlwrap, check out the man (manual) page.

Updating files and folders to Android device with one click via adb

I like to keep an updated copy of certain files on my Android phone at all times, such as the latest copy of certain code so I can look at it when I’m on the train.

I’ve done it in quite a few different ways:

  • Mount SD card as a removable storage device via USB
  • Run an FTP server on my phone and transfer files over wifi
  • Bluetooth file transfer

But these are all tedious because they’re all manual and they take too long.

Then I realised that ADB push and ADB shell are run from the command line/terminal, which means I can run a batch script. (A batch script is a text file with commands written that all run one after another in the command line)

Now all I need to do is click the file on my desktop and the files get updated within a fraction of a second on my phone.

So here’s an example version of my batch file that automatically updates a folder on my phone:

‘rm -r’ delete the folder and everything in it.

‘mkdir’ creates a folder by that name.

‘push’ copies the folder contents from the first argument to the second argument.

Note for those running emulators on their computers: Add ‘-d’ after the word adb on each line to send the commands to a device and not an emulator.

All that’s left is to write it up in Notepad and save it as Filename.bat. After that, just double-click the file and the operation should run in a fraction of a second.