Skip to content

Commit b572896

Browse files
jorgeecardonaDavidy22
authored andcommitted
Proof of concept for changing the title with a yaml file on each directory
1 parent 08f32aa commit b572896

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ black = "==21.8b0"
3535
flakehell = "*"
3636
toml = "*"
3737
dataclasses = "*"
38+
pyyaml = "*"
3839

3940
[packages]
4041
pbr = "*"

docs/source/user/features.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,11 @@ Tab UUID
114114
Tabs are uniquely identified with a UUID. Each terminal receives this UUID in the following
115115
environment varialbe: ``GUAKE_TAB_UUID``. It can be used to rename the tab from the command line
116116
using ``--tab-index 3c542bc1-7c99-4e73-8d37-e08281bd592c``.
117+
118+
119+
Per-directory `.guake.yml` file
120+
=============================
121+
122+
If there is a file named `.guake.yml` in the current working directory of the shell associated with a tab, Guake will try to read the title from there. The current format is very simple and it will probably change in the future::
123+
124+
title: "My Great Project"

guake/guake_app.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Boston, MA 02110-1301 USA
2020
"""
2121
import json
22+
import yaml
2223
import logging
2324
import os
2425
import shutil
@@ -1102,8 +1103,30 @@ def recompute_tabs_titles(self):
11021103
page_num = self.get_notebook().page_num(terminal.get_parent())
11031104
self.get_notebook().rename_page(page_num, self.compute_tab_title(terminal), False)
11041105

1106+
def load_cwd_guake_yaml(self, vte) -> dict:
1107+
# Read the content of .guake.yml in cwd
1108+
cwd = Path(vte.get_current_directory())
1109+
guake_yaml = cwd.joinpath(".guake.yml")
1110+
content = {}
1111+
try:
1112+
if guake_yaml.is_file():
1113+
with guake_yaml.open(encoding="utf-8") as fd:
1114+
content = yaml.safe_load(fd)
1115+
except PermissionError:
1116+
log.debug("PermissionError on accessing .guake.yml")
1117+
1118+
if not isinstance(content, dict):
1119+
conent = {}
1120+
return content
1121+
11051122
def compute_tab_title(self, vte):
11061123
"""Compute the tab title"""
1124+
1125+
guake_yml = self.load_cwd_guake_yaml(vte)
1126+
1127+
if "title" in guake_yml:
1128+
return guake_yml["title"]
1129+
11071130
vte_title = vte.get_window_title() or _("Terminal")
11081131
try:
11091132
current_directory = vte.get_current_directory()
@@ -1117,6 +1140,7 @@ def compute_tab_title(self, vte):
11171140
vte_title = "(root)"
11181141
except OSError:
11191142
pass
1143+
11201144
return TabNameUtils.shorten(vte_title, self.settings)
11211145

11221146
def check_if_terminal_directory_changed(self, term):
@@ -1151,6 +1175,7 @@ def on_terminal_title_changed(self, vte, term):
11511175
page_num = nb.page_num(box)
11521176
if page_num != -1:
11531177
break
1178+
11541179
# if tab has been renamed by user, don't override.
11551180
if not getattr(box, "custom_label_set", False):
11561181
title = self.compute_tab_title(vte)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
release_summary: >
2+
Add a per-directory .guake.yml to configure how guake behaves in that directory
3+
4+
features:
5+
- |
6+
Check for a file .guake.yml on the CWD to extract the label to put in the tab #1758
7+
8+
upgrade:
9+
- |
10+
Users should expect guake.yml files in current directory to override global settings

0 commit comments

Comments
 (0)