How to write android shell history to file


Question

Using Terminal Emulator for Android, is there a way to enable a persistent command history?



So far, I've tried the following:




  • initial command of export HISTFILE=$HOME/.mksh_history


  • user mksh profile /data/data/jackpal.androidterm/app_HOME/.mkshrc containing export HISTFILE=$HOME/.mksh_history


  • system mksh profile /system/etc/mkshrc containing export HISTFILE=/data/data/jackpal.androidterm/app_HOME/.mksh_history (though preferably the solution does not involve writing to /system)



I'm able to get other Android shells (ash and bash) to write histories into app_HOME without issue. I'm also able to get mksh to write HISTFILE on Linux without issue.


Answer

mksh developer here.



We disabled persistent history for mksh on Android, in order to not tax the flash memory with too many write requests.



You can re-enable it in a custom ROM by setting -DHAVE_PERSISTENT_HISTORY=1 in LOCAL_CFLAGS in Android.mk. You can also recompile mksh like that and copy that onto your ROM, if it’s rooted and the base OS version is the same.



Furthermore, you can copy any statically-linked binary for the same architecture on the phone and use that. The mksh-static binaries in the Debian package, however, also exclude persistent history.



If you really think this feature is worthwhile, persuade Google to enable it; for that, they need to edit mkmf.sh and remove the following lines…



# even the idea of persistent history on a phone is funny
HAVE_PERSISTENT_HISTORY=0; export HAVE_PERSISTENT_HISTORY


… then rebuild Android.mk from it (which they do for every new version anyway).



Oh, and you could ask the Terminal Emulator for Android developer to bundle a version of mksh with history enabled. This is probably no bad idea anyway, as it’ll be newer than what you get in the stock ROMs, and it won’t overwrite the system shell /system/bin/sh, but be available to CLI users.



That all still won’t enable persistent history by default (I’m strictly opposed to it, as it’s a surveillance feature), but enables users to set $HISTFILE themselves to enable it.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes