[konsole] /: Tweak tab title options: home and Bourne prompt sigils
Kurt Hindenburg
null at kde.org
Fri Aug 23 13:50:01 BST 2019
Git commit 08931fbd335ac097385baae2b24955085daff81b by Kurt Hindenburg, on behalf of Raphael Rosch.
Committed on 23/08/2019 at 12:49.
Pushed by scmsync into branch 'master'.
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
M +1 -0 doc/manual/index.docbook
M +22 -9 src/Session.cpp
M +2 -1 src/TabTitleFormatButton.cpp
https://commits.kde.org/konsole/08931fbd335ac097385baae2b24955085daff81b
diff --git a/doc/manual/index.docbook b/doc/manual/index.docbook
index 97af65b4..43f08de5 100644
--- a/doc/manual/index.docbook
+++ b/doc/manual/index.docbook
@@ -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>%h : local host (short)</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>%# : session number</para></listitem>
</itemizedlist>
diff --git a/src/Session.cpp b/src/Session.cpp
index 0dee779e..83364ceb 100644
--- a/src/Session.cpp
+++ b/src/Session.cpp
@@ -1115,6 +1115,7 @@ QString Session::getDynamicTitle()
* <br>
* The markers recognized are:
* <ul>
+ * <li> %B - User's Bourne prompt sigil ($, or # for superuser). </li>
* <li> %u - Name of the user which owns 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
@@ -1128,6 +1129,20 @@ QString Session::getDynamicTitle()
*/
QString title = tabTitleFormat(Session::LocalTabTitle);
// 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("%h"), Konsole::ProcessInfo::localHost());
title.replace(QLatin1String("%n"), process->name(&ok));
@@ -1143,17 +1158,15 @@ QString Session::getDynamicTitle()
title.replace(QLatin1String("%d"), QStringLiteral("-"));
title.replace(QLatin1String("%D"), QStringLiteral("-"));
} else {
- if (title.contains(QLatin1String("%D"))) {
- const QString homeDir = process->userHomeDir();
- if (!homeDir.isEmpty()) {
- // Change User's Home Dir w/ ~ only at the beginning
- if (dir.startsWith(homeDir)) {
- dir.remove(0, homeDir.length());
- dir.prepend(QLatin1Char('~'));
- }
+ // allow for shortname to have the ~ as homeDir
+ const QString homeDir = process->userHomeDir();
+ if (!homeDir.isEmpty()) {
+ if (dir.startsWith(homeDir)) {
+ dir.remove(0, homeDir.length());
+ dir.prepend(QLatin1Char('~'));
}
- title.replace(QLatin1String("%D"), dir);
}
+ title.replace(QLatin1String("%D"), dir);
title.replace(QLatin1String("%d"), process->formatShortDir(dir));
}
diff --git a/src/TabTitleFormatButton.cpp b/src/TabTitleFormatButton.cpp
index c492328e..c48fed3d 100644
--- a/src/TabTitleFormatButton.cpp
+++ b/src/TabTitleFormatButton.cpp
@@ -36,7 +36,8 @@ const TabTitleFormatButton::Element TabTitleFormatButton::_localElements[] = {
{ QStringLiteral("%w"), I18N_NOOP("Window Title Set by Shell: %w") },
{ QStringLiteral("%#"), I18N_NOOP("Session Number: %#") },
{ 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
= sizeof(_localElements) / sizeof(TabTitleFormatButton::Element);
More information about the kde-doc-english
mailing list