diff --git a/README.asciidoc b/README.asciidoc index 3d9d46b8..9136b593 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -776,6 +776,7 @@ Some of Kakoune state is available through environment variables: * `kak_reg_`: value of register * `kak_session`: name of the current session * `kak_client`: name of current client + * `kak_source`: path of the file currently getting executed (through the source command) * `kak_cursor_line`: line of the end of the main selection * `kak_cursor_column`: column of the end of the main selection (in byte) * `kak_cursor_char_column`: column of the end of the main selection (in character) diff --git a/doc/manpages/expansions.asciidoc b/doc/manpages/expansions.asciidoc index 4d3304b1..fcf9701a 100644 --- a/doc/manpages/expansions.asciidoc +++ b/doc/manpages/expansions.asciidoc @@ -84,6 +84,9 @@ informations about Kakoune's state: name of the current session *kak_client*:: name of current client +*kak_source*:: + path of the file currently getting executed (through the source + command) *kak_cursor_line*:: line of the end of the main selection *kak_cursor_column*:: diff --git a/src/commands.cc b/src/commands.cc index 5b5eefcd..62b35c9d 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1180,10 +1180,12 @@ const CommandDesc source_cmd = { filename_completer, [](const ParametersParser& parser, Context& context, const ShellContext&) { - String file_content = read_file(parse_filename(parser[0]), true); + String path = real_path(parse_filename(parser[0])); + String file_content = read_file(path, true); try { - CommandManager::instance().execute(file_content, context); + CommandManager::instance().execute(file_content, context, + {{}, {{"source", path}}}); } catch (Kakoune::runtime_error& err) {