Make split_path public

This commit is contained in:
Maxime Coste 2015-03-12 20:39:34 +00:00
parent 2f20399d03
commit b4f6b50dbb
4 changed files with 13 additions and 19 deletions

View File

@ -591,9 +591,10 @@ const CommandDesc add_hook_cmd = {
},
[](const ParametersParser& parser, Context& context)
{
// copy so that the lambda gets a copy as well
Regex regex(parser[2].begin(), parser[2].end());
String command = parser[3];
Regex regex(parser[2].begin(), parser[2].end(),
Regex::optimize | Regex::nosubs | Regex::ECMAScript);
const String& command = parser[3];
auto hook_func = [=](StringView param, Context& context) {
if (context.user_hooks_support().is_disabled())
return;

View File

@ -56,19 +56,11 @@ String parse_filename(StringView filename)
std::pair<StringView, StringView> split_path(StringView path)
{
StringView dir, file = path;
ByteCount dir_end = -1;
for (ByteCount i = 0; i < path.length(); ++i)
{
if (path[i] == '/')
dir_end = i;
}
if (dir_end != -1)
{
dir = path.substr(0, dir_end + 1);
file = path.substr(dir_end + 1);
}
return { dir, file };
auto it = find(reversed(path), '/');
if (it == path.rend())
return { {}, path };
const char* slash = it.base()-1;
return { {path.begin(), slash}, {slash+1, path.end()} };
}
String real_path(StringView filename)

View File

@ -32,6 +32,9 @@ String parse_filename(StringView filename);
String real_path(StringView filename);
String compact_path(StringView filename);
// returns pair { directory, filename }
std::pair<StringView, StringView> split_path(StringView path);
String get_kak_binary_path();
String read_fd(int fd);

View File

@ -22,9 +22,7 @@ ShellManager::ShellManager()
if (path)
new_path = path + ":"_str;
String kak_path = get_kak_binary_path();
StringView kak_dir{kak_path.begin(), find(reversed(kak_path), '/').base()-1};
new_path += kak_dir;
new_path += split_path(get_kak_binary_path()).first;
setenv("PATH", new_path.c_str(), 1);
}