mirror of
https://github.com/nix-community/nix-on-droid-app.git
synced 2025-12-06 17:11:09 +01: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:
parent
7f7c1efac1
commit
e28be01dc2
2 changed files with 25 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue