mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-05 02:05:25 +08:00
Create new terminal sessions with directory of active session
This mimics the behaviour of most tabbed terminal emulators. Fixes #1009.
This commit is contained in:
@@ -8,6 +8,7 @@ import android.system.Os;
|
||||
import android.system.OsConstants;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -339,4 +340,25 @@ public final class TerminalSession extends TerminalOutput {
|
||||
return mShellPid;
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
Log.e(EmulatorDebug.LOG_TAG, "Error getting current directory", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user