termux / termux-api

Termux add-on app which exposes device functionality as API to command line programs.
https://f-droid.org/en/packages/com.termux.api/
2.33k stars 458 forks source link

Better functionality for 'termux-file-editor' & 'termux-url-opener' #378

Open nerd190 opened 4 years ago

nerd190 commented 4 years ago

Feature description

Combine `termux-url-opener` and `termux-file-opener` into one simple bash binary called `termux-opener`, it will be basic, make it a builtin or `termux-api` pkg, users may modify it or make their own still, if exists then `$HOME/bin` takes precedence over the builtin one at `$PREFIX/bin` and dont have the current java implementation determine what is being shared first. This allows the user to fully control its behaviour and still able to maintain both functions, to open a URL or file. **Reason?** I recently made a *very* advanced `termux-url-opener`, by far the most advanced I have seen on Github & [r/termux](https://reddit.com/r/termux) whilst doing so I noticed its restrictions/caveats, heres just a couple examples, I can share more if needed: - **termux-url-opener** - Quite a few apps contain other than just the URL when sharing, a good example is Spotify, sharing a link looks like this: ```Here’s a song for you… 44 More by Logic https://open.spotify.com/track/3e7Y6sfFlIdBMJhX7wpqVO?si=2tY4mUslRTKkUKzLYlyu1w``` This invokes `termux-file-opener` but this isnt what we want. First thought... easy, lets just: ```echo "$1" | awk 'NF>1{print $NF}'``` to remove all the text first before streaming/downloading it, but unfortunately this is not possible as java already said "this is a file" and opened `termux-file-opener` instead. - **termux-file-editor** - Even less customisable, defaults to `$HOME/downloads` is another process to move it elsewhere, has potential to do much more, a quick example off the top of my head: ```bash echo "Title:" read TITLE if '.hex' || '.apk' || '.blahblah' ; then kak "$@" > "$HOME/storage/downloads" || \ kak "$@" > "/sdcard/Downloads" else micro "$@" > "$HOME/storage/downloads" || \ micro "$@" > "/sdcard/Downloads" fi ``` Even this would be a quick fix/improvement... ```bash select opts in 'termux-url-opener' 'termux-file-editor'; do case "$opts" in 'termux-url-opener') ..... 'termux-file-editor') ..... esac done ``` This asks us which we want to invoke, obviously we could add `dialog` etc. That and possibly an optional environment variable for our .termux.properties like "TERMUX_OPENER_DIR" to allow users to use another "default" directory if they need and "TERMUX_OPENER_INTERACTIVE" just in case being asked first is annoying to someone and they want default/legacy behaviour. **Solution?** Apart from what I already stated.... If java didnt pre-determine, you could keep functionality of both files (url-opener/file-editor) in one, its simple, a URL will never have spaces in it, so this is what I suggest the new builtin/api pkg "termux-opener" should contain... ```bash if [[ "$#" -eq 1 ]]; then termux-url-opener else termux-file-editor fi ``` "Have scripting do the talking to java, not the other way around, bash/python/lua/perl scripting are **much** more flexible, we can use them from Termux freely, much more we can a compiled/dexed java APK, even `xdg-open` is better than current java solution, I see no need for it, if this java-fu is really needed, make it a `termux-api` solution, atleast then, once again, we can hack at the scripts easily, possibly leading to further contributions from the public. Also ranger uses a "rifle.conf" (there are many like it) that configure opening any file type with any program, this and the fact that Termux is an app (which means it can list other installed apps and get their launchable activities) makes the possibility of a similar "rifle.conf" that could pick exactly what we want to with, e.g: 'txt = micro' (a CLi app) but also 'hex = com.mixplorer/.activities.HexViewerActivity' (an Android app)' **Note** My python isnt amazing, but I am more than happy to contribute to the `termux-opener` binary. **Finally...** A **HUGE** thank you to you all, it truly is appreciated! **Reference implementation** Have you checked if the feature is accessible through the Android API? yes Do you know of other open-source apps that has a similar feature as the one you want? (Provide links)
AbdullahM0hamed commented 4 years ago

Since that is handled via the Termux app (https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java), this should probably be an issue in the termux-app repo

Quasic commented 3 years ago

I symlinked them together in https://github.com/Quasic/termux-home-bin but I kind of abandoned it after I had weird trouble with the dialog package. I've been planning on adding API interfaces to avoid that. There's interesting reading, here.

nerd190 commented 3 years ago

I symlinked them together in https://github.com/Quasic/termux-home-bin but I kind of abandoned it after I had weird trouble with the dialog package. I've been planning on adding API interfaces to avoid that. There's interesting reading, here.

@Quasic sorry for the long reply! awesome work by the way! you should finish yours and perhaps it would encourage me to fully finish mine too! 😂