Skip to content

Commit

Permalink
Get TERMUX_VERSION while building shell environment via Termux packag…
Browse files Browse the repository at this point in the history
…e context
  • Loading branch information
agnostic-apollo committed Mar 29, 2021
1 parent 49f53f5 commit d4653d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private TermuxSession(TerminalSession terminalSession, ExecutionCommand executio
public static TermuxSession create(@NonNull final TermuxService service, @NonNull ExecutionCommand executionCommand, @NonNull TermuxSessionClientBase termuxSessionClient, String sessionName) {
if (executionCommand.workingDirectory == null || executionCommand.workingDirectory.isEmpty()) executionCommand.workingDirectory = TermuxConstants.TERMUX_HOME_DIR_PATH;

String[] environment = ShellUtils.buildEnvironment(executionCommand.isFailsafe, executionCommand.workingDirectory);
String[] environment = ShellUtils.buildEnvironment(service, executionCommand.isFailsafe, executionCommand.workingDirectory);

boolean isLoginShell = false;
if (executionCommand.executable == null) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/app/terminal/TermuxTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private TermuxTask(Process process, ExecutionCommand executionCommand) {
public static TermuxTask create(@NonNull final TermuxService service, @NonNull ExecutionCommand executionCommand) {
if (executionCommand.workingDirectory == null || executionCommand.workingDirectory.isEmpty()) executionCommand.workingDirectory = TermuxConstants.TERMUX_HOME_DIR_PATH;

String[] env = ShellUtils.buildEnvironment(false, executionCommand.workingDirectory);
String[] env = ShellUtils.buildEnvironment(service, false, executionCommand.workingDirectory);

final String[] commandArray = ShellUtils.setupProcessArgs(executionCommand.executable, executionCommand.arguments);
// final String commandDescription = Arrays.toString(commandArray);
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/com/termux/app/utils/ShellUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.termux.app.utils;

import com.termux.BuildConfig;
import android.content.Context;

import com.termux.app.TermuxConstants;

import java.io.File;
Expand All @@ -13,14 +14,21 @@

public class ShellUtils {

public static String[] buildEnvironment(boolean isFailSafe, String workingDirectory) {
public static String[] buildEnvironment(Context currentPackageContext, boolean isFailSafe, String workingDirectory) {
TermuxConstants.TERMUX_HOME_DIR.mkdirs();

if (workingDirectory == null || workingDirectory.isEmpty()) workingDirectory = TermuxConstants.TERMUX_HOME_DIR_PATH;

List<String> environment = new ArrayList<>();

environment.add("TERMUX_VERSION=" + BuildConfig.VERSION_NAME);
// This function may be called by a different package like a plugin, so we get version for Termux package via its context
Context termuxPackageContext = TermuxUtils.getTermuxPackageContext(currentPackageContext);
if(termuxPackageContext != null) {
String termuxVersionName = PackageUtils.getVersionNameForPackage(termuxPackageContext);
if(termuxVersionName != null)
environment.add("TERMUX_VERSION=" + termuxVersionName);
}

environment.add("TERM=xterm-256color");
environment.add("COLORTERM=truecolor");
environment.add("HOME=" + TermuxConstants.TERMUX_HOME_DIR_PATH);
Expand Down

0 comments on commit d4653d0

Please sign in to comment.