diff --git a/doc/json_schema.json b/doc/json_schema.json index c2ce9b318..db5824f46 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -498,7 +498,7 @@ "type": "string" }, "titleFormat": { - "description": "Output format of the module `Title`. See Wiki for formatting syntax\n 1. {user-name}: User name\n 2. {host-name}: Host name\n 3. {home-dir}: Home directory\n 4. {exe-path}: Executable path of current process\n 5. {user-shell}: User's default shell\n 6. {user-name-colored}: User name (colored)\n 7. {at-symbol-colored}: @ symbol (colored)\n 8. {host-name-colored}: Host name (colored)\n 9. {full-user-name}: Full user name\n 10. {user-id}: UID (*nix) / SID (Windows)\n 11. {pid}: PID of current process\n 12. {cwd}: Current working directory", + "description": "Output format of the module `Title`. See Wiki for formatting syntax\n 1. {user-name}: User name\n 2. {host-name}: Host name\n 3. {home-dir}: Home directory\n 4. {exe-path}: Executable path of current process\n 5. {user-shell}: User's default shell\n 6. {user-name-colored}: User name (colored)\n 7. {at-symbol-colored}: @ symbol (colored)\n 8. {host-name-colored}: Host name (colored)\n 9. {full-user-name}: Full user name\n 10. {user-id}: UID (*nix) / SID (Windows)\n 11. {pid}: PID of current process\n 12. {cwd}: Current working directory\n 13. {cwd-tilde}: CWD with home dir replaced by ~", "type": "string" }, "themeFormat": { diff --git a/src/modules/title/title.c b/src/modules/title/title.c index 6d9fa3290..dcd765f48 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -54,6 +54,22 @@ bool ffPrintTitle(FFTitleOptions* options) } else { + FF_STRBUF_AUTO_DESTROY cwdTilde = ffStrbufCreate(); + if ( + #if _WIN32 + ffStrbufStartsWithIgnCase + #else + ffStrbufStartsWith + #endif + (&instance.state.platform.cwd, &instance.state.platform.homeDir)) + { + ffStrbufAppendS(&cwdTilde, "~/"); + ffStrbufAppendNS(&cwdTilde, instance.state.platform.cwd.length - instance.state.platform.homeDir.length, &instance.state.platform.cwd.chars[instance.state.platform.homeDir.length]); + } + else + ffStrbufSet(&cwdTilde, &instance.state.platform.cwd); + ffStrbufTrimRight(&cwdTilde, '/'); + FF_PRINT_FORMAT_CHECKED(FF_TITLE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ FF_FORMAT_ARG(instance.state.platform.userName, "user-name"), FF_FORMAT_ARG(hostName, "host-name"), @@ -71,6 +87,7 @@ bool ffPrintTitle(FFTitleOptions* options) #endif FF_FORMAT_ARG(instance.state.platform.pid, "pid"), FF_FORMAT_ARG(instance.state.platform.cwd, "cwd"), + FF_FORMAT_ARG(cwdTilde, "cwd-tilde"), })); } @@ -186,5 +203,6 @@ FFModuleBaseInfo ffTitleModuleInfo = { {"UID (*nix) / SID (Windows)", "user-id"}, {"PID of current process", "pid"}, {"Current working directory", "cwd"}, + {"CWD with home dir replaced by `~`, and trims trailing `/`", "cwd-tilde"}, })) };