src/nnn.c | 27 +++++++++++++++++++++++++-- diff --git a/src/nnn.c b/src/nnn.c index 02020402b42258d615e126b90f930479d1be0164..06830c7ba11e647acc6358c04cba2743cc694ddc 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -425,7 +425,7 @@ static blkcnt_t dir_blocks; static ulong_t num_files; static kv *bookmark; static kv *plug; -static uchar_t tmpfplen; +static uchar_t tmpfplen, homelen; static uchar_t blk_shift = BLK_SHIFT_512; #ifndef NOMOUSE static int middle_click_key; @@ -1129,6 +1129,23 @@ resolved_path[1] = '\0'; } return resolved_path; +} + +static bool set_tilde_in_path(char *path) +{ + if (is_prefix(path, home, homelen)) { + home[homelen] = path[homelen - 1]; + path[homelen - 1] = '~'; + return TRUE; + } + + return FALSE; +} + +static void reset_tilde_in_path(char *path) +{ + path[homelen - 1] = home[homelen]; + home[homelen] = '\0'; } static int create_tmp_file(void) @@ -5998,8 +6015,13 @@ } if (!g_state.picker) { /* Set terminal window title */ - printf("\033]2;%s (%s)\007", xbasename(path), path); + r = set_tilde_in_path(path); + + printf("\033]2;%s\007", r ? &path[homelen - 1] : path); fflush(stdout); + + if (r) + reset_tilde_in_path(path); } if (g_state.selmode && lastdir[0]) @@ -7810,6 +7832,7 @@ fprintf(stderr, "set HOME\n"); return EXIT_FAILURE; } DPRINTF_S(home); + homelen = (uchar_t)xstrlen(home); if (!setup_config()) return EXIT_FAILURE;