introduce a property for configuring default working directory

Issue https://github.com/termux/termux-app/issues/1192.
This commit is contained in:
Leonid Pliushch 2021-02-03 20:22:38 +02:00
parent 407e4e003a
commit 496da3f877
No known key found for this signature in database
GPG Key ID: 45F2964132545795
2 changed files with 18 additions and 2 deletions

View File

@ -652,7 +652,14 @@ public final class TermuxActivity extends Activity implements ServiceConnection
.setPositiveButton(android.R.string.ok, null).show();
} else {
TerminalSession currentSession = getCurrentTermSession();
String workingDirectory = (currentSession == null) ? null : currentSession.getCwd();
String workingDirectory;
if (currentSession == null) {
workingDirectory = mSettings.mDefaultWorkingDir;
} else {
workingDirectory = currentSession.getCwd();
}
TerminalSession newSession = mTermService.createTermSession(null, null, workingDirectory, failSafe);
if (sessionName != null) {
newSession.mSessionName = sessionName;

View File

@ -78,6 +78,7 @@ final class TermuxPreferences {
boolean mBackIsEscape;
boolean mDisableVolumeVirtualKeys;
boolean mShowExtraKeys;
String mDefaultWorkingDir;
ExtraKeysInfos mExtraKeys;
@ -113,7 +114,7 @@ final class TermuxPreferences {
} catch (NumberFormatException | ClassCastException e) {
mFontSize = defaultFontSize;
}
mFontSize = clamp(mFontSize, MIN_FONTSIZE, MAX_FONTSIZE);
mFontSize = clamp(mFontSize, MIN_FONTSIZE, MAX_FONTSIZE);
}
boolean toggleShowExtraKeys(Context context) {
@ -227,6 +228,14 @@ final class TermuxPreferences {
mUseFullScreenWorkAround = false;
}
mDefaultWorkingDir = props.getProperty("default-working-directory", TermuxService.HOME_PATH);
File workDir = new File(mDefaultWorkingDir);
if (!workDir.exists() || !workDir.isDirectory()) {
// Fallback to home directory if user configured working directory is not exist
// or is a regular file.
mDefaultWorkingDir = TermuxService.HOME_PATH;
}
String defaultExtraKeys = "[[ESC, TAB, CTRL, ALT, {key: '-', popup: '|'}, DOWN, UP]]";
try {