diff --git a/src/commands.cc b/src/commands.cc index 3a0251a4..dd6d9878 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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; diff --git a/src/file.cc b/src/file.cc index ec409df8..268cd47d 100644 --- a/src/file.cc +++ b/src/file.cc @@ -56,19 +56,11 @@ String parse_filename(StringView filename) std::pair 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) diff --git a/src/file.hh b/src/file.hh index 8fc4eac0..0515c89a 100644 --- a/src/file.hh +++ b/src/file.hh @@ -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 split_path(StringView path); + String get_kak_binary_path(); String read_fd(int fd); diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 6b82ba91..1c614455 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -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); }