Skip to content

Commit b93d02f

Browse files
get default terminal (thanks diablosat)
1 parent b30982f commit b93d02f

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/mainwindow.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from src.killaethread import KillAEThread
1212
from src.removeaethread import RemoveAEThread
1313
from src.utils import (
14-
check_aegnux_tip_marked, get_wine_bin_path_env,
14+
check_aegnux_tip_marked, get_default_terminal, get_wine_bin_path_env,
1515
get_cep_dir, get_ae_plugins_dir, get_wineprefix_dir,
1616
check_aegnux_installed, mark_aegnux_tip_as_shown, get_ae_install_dir, get_aegnux_installation_dir
1717
)
@@ -248,10 +248,11 @@ def run_command_alt_t(self):
248248
env['WINEPREFIX'] = get_wineprefix_dir()
249249
env['PATH'] = get_wine_bin_path_env('/usr/bin')
250250

251-
process = subprocess.Popen(
252-
['./bin/kitty/bin/kitty', 'bash'],
253-
env=env
254-
)
251+
try:
252+
terminal = get_default_terminal()
253+
subprocess.Popen([terminal, "bash"], env=env)
254+
except RuntimeError as e:
255+
print("[CRITICAL ERROR]:", e)
255256

256257
@Slot()
257258
def run_command_ctrl_q(self):

src/utils.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,52 @@ def get_wine_bin_path_env(old_path: str | None):
148148
old_path = old_path if old_path is not None else os.getenv('PATH')
149149
return f'{get_wine_runner_dir().as_posix()}/bin:{old_path}'
150150

151-
151+
def get_default_terminal() -> str:
152+
DEFAULT_ENVS = ["TERMINAL", "TERM_PROGRAM"]
153+
TERMINALS = [
154+
"konsole",
155+
"kitty",
156+
"alacritty",
157+
"gnome-terminal",
158+
"xfce4-terminal",
159+
"terminator",
160+
"lxterminal",
161+
"tilix",
162+
"st",
163+
"mate-terminal",
164+
"xterm",
165+
"urxvt",
166+
"deepin-terminal",
167+
"sakura",
168+
"tilda",
169+
"guake",
170+
"hyper",
171+
"eterm",
172+
"rxvt",
173+
"lxterm",
174+
"cosmic-terminal",
175+
]
176+
177+
candidates = (
178+
shutil.which(os.environ.get(var)) for var in DEFAULT_ENVS if os.environ.get(var)
179+
)
180+
181+
# Debian/Ubuntu
182+
alt = "/etc/alternatives/x-terminal-emulator"
183+
if os.path.exists(alt):
184+
candidates = (shutil.which(os.readlink(alt)), *candidates)
185+
186+
# Popular terminals
187+
candidates = (*candidates, *(shutil.which(term) for term in TERMINALS))
188+
189+
terminal = next((t for t in candidates if t), None)
190+
if terminal:
191+
return terminal
192+
193+
raise RuntimeError(
194+
"Your terminal was not found or is not supported.\n"
195+
"Install one of the following: " + ", ".join(TERMINALS)
196+
)
152197

153198
def get_aegnux_tip_marked_flag_path():
154199
hades = get_aegnux_installation_dir()

0 commit comments

Comments
 (0)