termux / termux-float

Termux add-on app to show the terminal in a floating terminal window.
https://f-droid.org/en/packages/com.termux.window
Other
460 stars 77 forks source link

Provide a way to detect if inside floating Termux #51

Open mentalisttraceur opened 1 year ago

mentalisttraceur commented 1 year ago

Feature Description

I want a way for scripts/programs in Termux to detect if the current terminal is shown in the floating Termux window.

Couple possible ways, doesn't matter to me which:

  1. Have Termux's floating app export an additional environment variable, for example TERMUX_FLOAT, before starting the user's shell.

  2. Add a program to termux-api, for example termux-api-in-floating-window, which could for example report the value as the exit status.

Why

I use both Termux and Termux:Float, and they have different roles in my workflow. It would help me make my tools automatically do what I want if I could code them to know which of the two they're in.

Current Alternatives

I can think of two currently possible ways to get close to this:

  1. Manually running a command when I start Termux:Float, which would set up some indicator that I'm in a floating window, but that's an extra manual step every time, and not exactly reliable if I forget.

  2. Checking the terminal size, but that's really not reliable if I resize the terminal, change Termux font size, or use something like a terminal multiplexer.

agnostic-apollo commented 1 year ago

Next version will export $TERMUX__PACKAGE_NAME variable for the app package in which the shell is running, different from $TERMUX_APP__PACKAGE_NAME for the core app. However, Termux:Float is eventually going to be integrated into Termux app itself so would require an API to check current status, including fullscreen mode, etc.

mentalisttraceur commented 1 year ago

However, Termux:Float is eventually going to be integrated into Termux app itself

Will we still be able to have both a normal terminal and a floating terminal open at the same time? And two separate shortcuts on the home screen, one for the floating terminal and one for the normal terminal?

agnostic-apollo commented 1 year ago

I haven't really thought much of the design but supporting both at same time would complicate things a lot, but might be possible, will see what can be done. It won't happen anytime soon anyways, much higher priority things to work on in coming months.

sudomain commented 6 months ago

I also would like to run some code only in Termux:Float. I thought I had a solution by putting this in my bashrc:

if [ "$(pwd)" = "$HOME/.termux/termux_float" ]; then
    echo "In termux float"
fi

And setting: default-working-directory = ~/.termux/termux_float/ in ~/.termux/termux.float.properties

I think this should work, however I can't get default-working-directory to change the directory in either termux.float.properties or termux.properties. I've run termux-reload-settings and checked that my bashrc and profile files aren't changing the directory. Any ideas?

mentalisttraceur commented 6 months ago

For whatever it's worth, I no longer have any foreseeable use for this part:

Will we still be able to have both a normal terminal and a floating terminal open at the same time? And two separate shortcuts on the home screen, one for the floating terminal and one for the normal terminal?

agnostic-apollo commented 5 months ago

default-working-directory = ~/.termux/termux_float/

The ~/ in path won't be expanded and an error in logcat will be logged. Use absolute path /data/data/com.termux/files/home/

https://github.com/termux/termux-app/blob/8e3a8980a849046adbd4156741e1d84047ee1df6/termux-shared/src/main/java/com/termux/shared/termux/settings/properties/TermuxSharedProperties.java#L514