mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Get TERMUX_VERSION while building shell environment via Termux package context
This commit is contained in:
@@ -33,7 +33,7 @@ public class TermuxSession {
|
|||||||
public static TermuxSession create(@NonNull final TermuxService service, @NonNull ExecutionCommand executionCommand, @NonNull TermuxSessionClientBase termuxSessionClient, String sessionName) {
|
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;
|
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;
|
boolean isLoginShell = false;
|
||||||
if (executionCommand.executable == null) {
|
if (executionCommand.executable == null) {
|
||||||
|
@@ -34,7 +34,7 @@ public final class TermuxTask {
|
|||||||
public static TermuxTask create(@NonNull final TermuxService service, @NonNull 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;
|
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[] commandArray = ShellUtils.setupProcessArgs(executionCommand.executable, executionCommand.arguments);
|
||||||
// final String commandDescription = Arrays.toString(commandArray);
|
// final String commandDescription = Arrays.toString(commandArray);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.termux.app.utils;
|
package com.termux.app.utils;
|
||||||
|
|
||||||
import com.termux.BuildConfig;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.termux.app.TermuxConstants;
|
import com.termux.app.TermuxConstants;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -13,14 +14,21 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ShellUtils {
|
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();
|
TermuxConstants.TERMUX_HOME_DIR.mkdirs();
|
||||||
|
|
||||||
if (workingDirectory == null || workingDirectory.isEmpty()) workingDirectory = TermuxConstants.TERMUX_HOME_DIR_PATH;
|
if (workingDirectory == null || workingDirectory.isEmpty()) workingDirectory = TermuxConstants.TERMUX_HOME_DIR_PATH;
|
||||||
|
|
||||||
List<String> environment = new ArrayList<>();
|
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("TERM=xterm-256color");
|
||||||
environment.add("COLORTERM=truecolor");
|
environment.add("COLORTERM=truecolor");
|
||||||
environment.add("HOME=" + TermuxConstants.TERMUX_HOME_DIR_PATH);
|
environment.add("HOME=" + TermuxConstants.TERMUX_HOME_DIR_PATH);
|
||||||
|
Reference in New Issue
Block a user