这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,15 @@ void addNewSession(boolean failSafe, String sessionName) {
}
}
String executablePath = (failSafe ? "/system/bin/sh" : null);
TerminalSession newSession = mTermService.createTermSession(executablePath, null, null, failSafe);
String workingDirectory = null;
if (mSettings.mUseCurrentSessionCwd) {
final TerminalSession currentSession = getCurrentTermSession();
if (currentSession != null) {
workingDirectory = currentSession.getCwd();
}
}

TerminalSession newSession = mTermService.createTermSession(executablePath, null, workingDirectory, failSafe);
if (sessionName != null) {
newSession.mSessionName = sessionName;
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/termux/app/TermuxPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ final static class KeyboardShortcut {
boolean mBackIsEscape;
boolean mShowExtraKeys;

boolean mUseCurrentSessionCwd;

String[][] mExtraKeys;

final List<KeyboardShortcut> shortcuts = new ArrayList<>();
Expand Down Expand Up @@ -192,6 +194,8 @@ void reloadFromProperties(Context context) {

mBackIsEscape = "escape".equals(props.getProperty("back-key", "back"));

mUseCurrentSessionCwd = "current".equals(props.getProperty("session.cwd-on-create", "default"));

shortcuts.clear();
parseAction("shortcut.create-session", SHORTCUT_ACTION_CREATE_SESSION, props);
parseAction("shortcut.next-session", SHORTCUT_ACTION_NEXT_SESSION, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.system.OsConstants;
import android.util.Log;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -166,6 +167,25 @@ public String getTitle() {
return (mEmulator == null) ? null : mEmulator.getTitle();
}

/** Returns the shell's working directory or null if it was unavailable. */
public String getCwd() {
if (mShellPid < 1)
return null;
try {
final String cwdSymlink = String.format("/proc/%s/cwd/", mShellPid);
String outputPath = new File(cwdSymlink)
.getCanonicalPath();
if (!outputPath.endsWith("/"))
outputPath += '/';

if (!cwdSymlink.equals(outputPath))
return outputPath;
} catch (IOException | SecurityException e) {
// Ignore.
}
return null;
}

/**
* Set the terminal emulator's window size and start terminal emulation.
*
Expand Down