Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to detect if inside floating Termux #51

Open
mentalisttraceur opened this issue May 9, 2023 · 6 comments
Open

Provide a way to detect if inside floating Termux #51

mentalisttraceur opened this issue May 9, 2023 · 6 comments

Comments

@mentalisttraceur
Copy link

mentalisttraceur commented May 9, 2023

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
Copy link
Member

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
Copy link
Author

mentalisttraceur commented May 9, 2023

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
Copy link
Member

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
Copy link

sudomain commented Mar 12, 2024

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
Copy link
Author

mentalisttraceur commented Mar 12, 2024

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants