]> Sergey Matveev's repositories - nnn.git/commitdiff
Replace $HOME by '~' in terminal title
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 27 Mar 2021 16:43:39 +0000 (22:13 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 27 Mar 2021 16:45:11 +0000 (22:15 +0530)
src/nnn.c

index 02020402b42258d615e126b90f930479d1be0164..06830c7ba11e647acc6358c04cba2743cc694ddc 100644 (file)
--- 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;
@@ -1131,6 +1131,23 @@ static char *abspath(const char *path, const char *cwd)
        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)
 {
        xstrsncpy(g_tmpfpath + tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - tmpfplen);
@@ -5998,8 +6015,13 @@ begin:
 
        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 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
        DPRINTF_S(home);
+       homelen = (uchar_t)xstrlen(home);
 
        if (!setup_config())
                return EXIT_FAILURE;