mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-29 10:31:14 -03:00
Make fish find config directories in source tree
If one does a make fish; ./fish - don't use the make-installed paths. Also, remove huge chunk of nearly duplicated code #ifdef'd __APPLE__ for relocatable dirs in fish.app: the directories under Resources in the bundle followed by the changes I made around here a few months ago now are not different enough that they require a special case. This works fine for fish.app.
This commit is contained in:
55
src/fish.cpp
55
src/fish.cpp
@@ -122,50 +122,30 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
|
|||||||
bool done = false;
|
bool done = false;
|
||||||
std::string exec_path = get_executable_path(argv0);
|
std::string exec_path = get_executable_path(argv0);
|
||||||
if (get_realpath(exec_path)) {
|
if (get_realpath(exec_path)) {
|
||||||
#if __APPLE__
|
|
||||||
debug(2, L"exec_path: '%s'", exec_path.c_str());
|
debug(2, L"exec_path: '%s'", exec_path.c_str());
|
||||||
|
|
||||||
// On OS X, maybe we're an app bundle, and should use the bundle's files. Since we don't
|
|
||||||
// link CF, use this lame approach to test it: see if the resolved path ends with
|
|
||||||
// /Contents/MacOS/fish, case insensitive since HFS+ usually is.
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
const char *suffix = "Contents/Resources/base/bin/fish";
|
// The next check is that we are in a reloctable directory tree
|
||||||
const size_t suffixlen = strlen(suffix);
|
const char *installed_suffix = "/bin/fish";
|
||||||
if (has_suffix(exec_path, suffix, true)) {
|
const char *just_a_fish = "/fish";
|
||||||
// Looks like we're a bundle. Cut the string at the / prefixing /Contents... and
|
const char *suffix = NULL;
|
||||||
// then the rest.
|
|
||||||
wcstring wide_resolved_path = str2wcstring(exec_path);
|
|
||||||
wide_resolved_path.resize(exec_path.size() - suffixlen);
|
|
||||||
wide_resolved_path.append(L"Contents/Resources/base/");
|
|
||||||
|
|
||||||
// Append share, etc, doc.
|
if (has_suffix(exec_path, installed_suffix, false)) {
|
||||||
paths.data = wide_resolved_path + L"share/fish";
|
suffix = installed_suffix;
|
||||||
paths.sysconf = wide_resolved_path + L"etc/fish";
|
} else if (has_suffix(exec_path, just_a_fish, false)) {
|
||||||
paths.doc = wide_resolved_path + L"doc/fish";
|
debug(2, L"'fish' not in a 'bin/', trying paths relative to source tree");
|
||||||
|
suffix = just_a_fish;
|
||||||
// But the bin_dir is the resolved_path, minus fish (aka the MacOS directory).
|
|
||||||
paths.bin = str2wcstring(exec_path);
|
|
||||||
paths.bin.resize(paths.bin.size() - strlen("/fish"));
|
|
||||||
|
|
||||||
done = true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!done) {
|
if (suffix) {
|
||||||
// The next check is that we are in a reloctable directory tree like this:
|
bool seems_installed = (suffix == installed_suffix);
|
||||||
// bin/fish
|
|
||||||
// etc/fish
|
|
||||||
// share/fish
|
|
||||||
const char *suffix = "/bin/fish";
|
|
||||||
if (has_suffix(exec_path, suffix, false)) {
|
|
||||||
wcstring base_path = str2wcstring(exec_path);
|
wcstring base_path = str2wcstring(exec_path);
|
||||||
base_path.resize(base_path.size() - strlen(suffix));
|
base_path.resize(base_path.size() - strlen(suffix));
|
||||||
|
|
||||||
paths.data = base_path + L"/share/fish";
|
paths.data = base_path + (seems_installed ? L"/share/fish" : L"/share");
|
||||||
paths.sysconf = base_path + L"/etc/fish";
|
paths.sysconf = base_path + (seems_installed ? L"/etc/fish" : L"/etc");
|
||||||
paths.doc = base_path + L"/share/doc/fish";
|
paths.doc = base_path + (seems_installed ? L"/share/doc/fish" : L"/user_doc/html");
|
||||||
paths.bin = base_path + L"/bin";
|
paths.bin = base_path + (seems_installed ? L"/bin" : L"");
|
||||||
|
|
||||||
// Check only that the data and sysconf directories exist. Handle the doc
|
// Check only that the data and sysconf directories exist. Handle the doc
|
||||||
// directories separately.
|
// directories separately.
|
||||||
@@ -183,13 +163,14 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
|
|||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
// Fall back to what got compiled in.
|
// Fall back to what got compiled in.
|
||||||
|
debug(2, L"Using compiled in paths:");
|
||||||
paths.data = L"" DATADIR "/fish";
|
paths.data = L"" DATADIR "/fish";
|
||||||
paths.sysconf = L"" SYSCONFDIR "/fish";
|
paths.sysconf = L"" SYSCONFDIR "/fish";
|
||||||
paths.doc = L"" DOCDIR;
|
paths.doc = L"" DOCDIR;
|
||||||
paths.bin = L"" BINDIR;
|
paths.bin = L"" BINDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(2, "determine_config_directory_paths() results:\npaths.data: %ls\npaths.sysconf: %ls\npaths.doc: %ls\npaths.bin: %ls", paths.data.c_str(), paths.sysconf.c_str(), paths.doc.c_str(), paths.bin.c_str());
|
debug(2, L"determine_config_directory_paths() results:\npaths.data: %ls\npaths.sysconf: %ls\npaths.doc: %ls\npaths.bin: %ls", paths.data.c_str(), paths.sysconf.c_str(), paths.doc.c_str(), paths.bin.c_str());
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user