Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelfmz <fenix1905@tut.by>2021-06-30 11:02:09 +0300
committerGitHub <noreply@github.com>2021-06-30 11:02:09 +0300
commitfa68e350c8385e57d57caa3d70449de7a407115c (patch)
tree7e3e44e55dc359b7b88a05e8889e041a4f191fa7
parent1b891218e21f89c776efcea4719cd6f12f4a0752 (diff)
parente83316e135cc2fa2205e52229c7b3df3df40d2f9 (diff)
Merge pull request #1018 from elfmz/custom-settingsv2021-06-30_alpha
Custom settings by -u argument now working
-rw-r--r--far2l/main.cpp40
-rw-r--r--utils/include/utils.h3
-rw-r--r--utils/src/InMy.cpp54
3 files changed, 87 insertions, 10 deletions
diff --git a/far2l/main.cpp b/far2l/main.cpp
index a2a80769..00f0dd4a 100644
--- a/far2l/main.cpp
+++ b/far2l/main.cpp
@@ -97,8 +97,8 @@ static void print_help(const char *self)
" -ma Do not execute auto run macros.\n"
" -p[<path>]\n"
" Search for \"common\" plugins in the directory, specified by <path>.\n"
- " -u <username>\n"
- " Allows to have separate settings for different users.\n"
+ " -u <identity> OR </path/name>\n"
+ " Allows to specify separate settings identity or FS location.\n"
" -v <filename>\n"
" View the specified file.\n"
" -v - command line\n"
@@ -719,6 +719,36 @@ int FarDispatchAnsiApplicationProtocolCommand(const char *str)
return r;
}
+static void SetCustomSettings(const char *arg)
+{
+ std::string refined;
+ if (arg[0] == '/') {
+ refined = arg;
+
+ } else if (arg[0] == '.' && arg[1] == '/') {
+ char cwdbuf[MAX_PATH + 1] = {'.', 0};
+ const char *cwd = getcwd(cwdbuf, MAX_PATH);
+ if (cwd) {
+ refined = cwd;
+ }
+ refined+= &arg[1];
+
+ } else {
+ refined = arg;
+ }
+
+ while (!refined.empty() && refined.back() == '/') {
+ refined.resize(refined.size() - 1);
+ }
+
+ fprintf(stderr, "%s: '%s'\n", __FUNCTION__, refined.c_str());
+
+ if (!refined.empty()) {
+ // could use FARPROFILE/FARLOCALPROFILE for that but it would be abusing
+ setenv("FARSETTINGS", refined.c_str(), 1);
+ }
+}
+
int _cdecl main(int argc, char *argv[])
{
char *name = strrchr(argv[0], GOOD_SLASH);
@@ -743,6 +773,12 @@ int _cdecl main(int argc, char *argv[])
}
}
+ for (int i = 1; i + 1 < argc; ++i) {
+ if (strcasecmp(argv[i], "-u") == 0 && argv[i + 1][0] ) {
+ SetCustomSettings(argv[i + 1]);
+ }
+ }
+
setlocale(LC_ALL, "");//otherwise non-latin keys missing with XIM input method
SetupFarPath(argc, argv);
diff --git a/utils/include/utils.h b/utils/include/utils.h
index 4c988b13..5be78299 100644
--- a/utils/include/utils.h
+++ b/utils/include/utils.h
@@ -56,7 +56,8 @@ void QuoteCmdArg(std::wstring &str);
void QuoteCmdArgIfNeed(std::string &str);
void QuoteCmdArgIfNeed(std::wstring &str);
-std::string GetMyHome();
+const std::string &GetMyHome();
+
std::string InMyConfig(const char *subpath = NULL, bool create_path = true);
std::string InMyCache(const char *subpath = NULL, bool create_path = true);
std::string InMyTemp(const char *subpath = NULL);
diff --git a/utils/src/InMy.cpp b/utils/src/InMy.cpp
index 2f9005e4..c453d509 100644
--- a/utils/src/InMy.cpp
+++ b/utils/src/InMy.cpp
@@ -13,7 +13,7 @@
#include <errno.h>
-std::string GetMyHome()
+static std::string GetMyHomeUncached()
{
std::string out;
@@ -31,11 +31,51 @@ std::string GetMyHome()
return out;
}
-static std::string InHomeSubdir(const char *what, const char *subpath, bool create_path)
+
+static std::string GetFarSettingsUncached()
+{
+ std::string out;
+ const char *env = getenv("FARSETTINGS");
+ if (env) {
+ out = env;
+ }
+ return out;
+}
+
+const std::string &GetMyHome()
+{
+ static std::string s_out = GetMyHomeUncached();
+ return s_out;
+}
+
+const std::string &GetFarSettings()
+{
+ static std::string s_out = GetFarSettingsUncached();
+ return s_out;
+}
+
+
+static std::string InProfileSubdir(const char *what, const char *subpath, bool create_path)
{
- std::string path = GetMyHome();
+ const std::string &settings = GetFarSettings();
- path+= what;
+ std::string path;
+
+ if (!settings.empty() && settings[0] == '/') {
+ path = settings;
+ path+= '/';
+ path+= what;
+
+ } else {
+ path = GetMyHome();
+ path+= '/';
+ path+= what;
+ path+= "/far2l";
+ if (!settings.empty()) {
+ path+= "/custom/";
+ path+= settings;
+ }
+ }
if (subpath) {
if (*subpath != GOOD_SLASH) {
@@ -53,18 +93,18 @@ static std::string InHomeSubdir(const char *what, const char *subpath, bool crea
}
}
}
-
+
return path;
}
std::string InMyConfig(const char *subpath, bool create_path)
{
- return InHomeSubdir("/.config/far2l", subpath, create_path);
+ return InProfileSubdir(".config", subpath, create_path);
}
std::string InMyCache(const char *subpath, bool create_path)
{
- return InHomeSubdir("/.cache/far2l", subpath, create_path);
+ return InProfileSubdir(".cache", subpath, create_path);
}