diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-03 16:48:04 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-03 16:48:04 -0500 |
commit | a566e529522940f011aa1fa08d44753b6bea9562 (patch) | |
tree | 957ca3816b49ab12a32bddb9bee38ae84ffbc1c2 /main.c | |
parent | ad9559da432f1ea84f1f350f0edf42b94fe79d4c (diff) |
change cwd to directory of last buffer
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1,4 +1,5 @@ // @TODO: +// - ensure buffer->filename never contains / on windows // - split // - Windows installation #include "base.h" @@ -435,6 +436,24 @@ int main(int argc, char **argv) { ted->drag_buffer = NULL; } + { // ted->cwd should be the directory containing the last active buffer + TextBuffer *buffer = ted->active_buffer; + if (buffer) { + char const *buffer_path = buffer_get_filename(buffer); + if (buffer_path && !buffer_is_untitled(buffer)) { + assert(*buffer_path); + char *last_sep = strrchr(buffer_path, PATH_SEPARATOR); + if (last_sep) { + size_t dirname_len = (size_t)(last_sep - buffer_path); + if (dirname_len == 0) dirname_len = 1; // make sure "/x" sets our cwd to "/", not "" + // set cwd to buffer's directory + memcpy(ted->cwd, buffer_path, dirname_len); + ted->cwd[dirname_len] = 0; + } + } + } + } + u32 key_modifier = (u32)ctrl_down << KEY_MODIFIER_CTRL_BIT | (u32)shift_down << KEY_MODIFIER_SHIFT_BIT |