summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-03 16:48:04 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-03 16:48:04 -0500
commita566e529522940f011aa1fa08d44753b6bea9562 (patch)
tree957ca3816b49ab12a32bddb9bee38ae84ffbc1c2 /main.c
parentad9559da432f1ea84f1f350f0edf42b94fe79d4c (diff)
change cwd to directory of last buffer
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.c b/main.c
index 12e9549..894ed85 100644
--- a/main.c
+++ b/main.c
@@ -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