Commit 08931fbd authored by Raphael Rosch's avatar Raphael Rosch Committed by Kurt Hindenburg

Tweak tab title options: home and Bourne prompt sigils

Add the home sigil "~" for short cwd (it was only present for long cwd
for some reason), and the Bourne prompt sigils "$" (for regular user)
and "#" for superuser as the variable %B.

https://invent.kde.org/kde/konsole/merge_requests/19
parent 4d5d7281
...@@ -1013,6 +1013,7 @@ These changes can be made permanent by editing the current profile. ...@@ -1013,6 +1013,7 @@ These changes can be made permanent by editing the current profile.
<listitem><para>%D : current directory (long)</para></listitem> <listitem><para>%D : current directory (long)</para></listitem>
<listitem><para>%h : local host (short)</para></listitem> <listitem><para>%h : local host (short)</para></listitem>
<listitem><para>%u : user name</para></listitem> <listitem><para>%u : user name</para></listitem>
<listitem><para>%B : user's Bourne prompt sigil ($ = normal user, # = superuser)</para></listitem>
<listitem><para>%w : window title set by shell</para></listitem> <listitem><para>%w : window title set by shell</para></listitem>
<listitem><para>%# : session number</para></listitem> <listitem><para>%# : session number</para></listitem>
</itemizedlist> </itemizedlist>
......
...@@ -1115,6 +1115,7 @@ QString Session::getDynamicTitle() ...@@ -1115,6 +1115,7 @@ QString Session::getDynamicTitle()
* <br> * <br>
* The markers recognized are: * The markers recognized are:
* <ul> * <ul>
* <li> %B - User's Bourne prompt sigil ($, or # for superuser). </li>
* <li> %u - Name of the user which owns the process. </li> * <li> %u - Name of the user which owns the process. </li>
* <li> %n - Replaced with the name of the process. </li> * <li> %n - Replaced with the name of the process. </li>
* <li> %d - Replaced with the last part of the path name of the * <li> %d - Replaced with the last part of the path name of the
...@@ -1128,6 +1129,20 @@ QString Session::getDynamicTitle() ...@@ -1128,6 +1129,20 @@ QString Session::getDynamicTitle()
*/ */
QString title = tabTitleFormat(Session::LocalTabTitle); QString title = tabTitleFormat(Session::LocalTabTitle);
// search for and replace known marker // search for and replace known marker
int UID = process->userId(&ok);
if(!ok) {
title.replace(QLatin1String("%B"), QStringLiteral("-"));
} else {
//title.replace(QLatin1String("%I"), QString::number(UID));
if (UID == 0) {
title.replace(QLatin1String("%B"), QStringLiteral("#"));
} else {
title.replace(QLatin1String("%B"), QStringLiteral("$"));
}
}
title.replace(QLatin1String("%u"), process->userName()); title.replace(QLatin1String("%u"), process->userName());
title.replace(QLatin1String("%h"), Konsole::ProcessInfo::localHost()); title.replace(QLatin1String("%h"), Konsole::ProcessInfo::localHost());
title.replace(QLatin1String("%n"), process->name(&ok)); title.replace(QLatin1String("%n"), process->name(&ok));
...@@ -1143,17 +1158,15 @@ QString Session::getDynamicTitle() ...@@ -1143,17 +1158,15 @@ QString Session::getDynamicTitle()
title.replace(QLatin1String("%d"), QStringLiteral("-")); title.replace(QLatin1String("%d"), QStringLiteral("-"));
title.replace(QLatin1String("%D"), QStringLiteral("-")); title.replace(QLatin1String("%D"), QStringLiteral("-"));
} else { } else {
if (title.contains(QLatin1String("%D"))) { // allow for shortname to have the ~ as homeDir
const QString homeDir = process->userHomeDir(); const QString homeDir = process->userHomeDir();
if (!homeDir.isEmpty()) { if (!homeDir.isEmpty()) {
// Change User's Home Dir w/ ~ only at the beginning if (dir.startsWith(homeDir)) {
if (dir.startsWith(homeDir)) { dir.remove(0, homeDir.length());
dir.remove(0, homeDir.length()); dir.prepend(QLatin1Char('~'));
dir.prepend(QLatin1Char('~'));
}
} }
title.replace(QLatin1String("%D"), dir);
} }
title.replace(QLatin1String("%D"), dir);
title.replace(QLatin1String("%d"), process->formatShortDir(dir)); title.replace(QLatin1String("%d"), process->formatShortDir(dir));
} }
......
...@@ -36,7 +36,8 @@ const TabTitleFormatButton::Element TabTitleFormatButton::_localElements[] = { ...@@ -36,7 +36,8 @@ const TabTitleFormatButton::Element TabTitleFormatButton::_localElements[] = {
{ QStringLiteral("%w"), I18N_NOOP("Window Title Set by Shell: %w") }, { QStringLiteral("%w"), I18N_NOOP("Window Title Set by Shell: %w") },
{ QStringLiteral("%#"), I18N_NOOP("Session Number: %#") }, { QStringLiteral("%#"), I18N_NOOP("Session Number: %#") },
{ QStringLiteral("%u"), I18N_NOOP("User Name: %u") }, { QStringLiteral("%u"), I18N_NOOP("User Name: %u") },
{ QStringLiteral("%h"), I18N_NOOP("Local Host: %h") } { QStringLiteral("%h"), I18N_NOOP("Local Host: %h") },
{ QStringLiteral("%B"), I18N_NOOP("User's Bourne prompt sigil: %B") } // ($, or # for superuser)
}; };
const int TabTitleFormatButton::_localElementCount const int TabTitleFormatButton::_localElementCount
= sizeof(_localElements) / sizeof(TabTitleFormatButton::Element); = sizeof(_localElements) / sizeof(TabTitleFormatButton::Element);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment