Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
class.tpl.powershell.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
17{
18 // Icon constants - Currently unused as native PowerShell consoles do not support custom icons
19 // These icons were used with ConsoleZ but are not supported by standard PowerShell console host
20 // To use icons, consider using a terminal emulator like ConEmu, Cmder, or Windows Terminal
21 // Icon files are located at: core/resources/homepage/img/icons/
22 /*
23 const ICON_APP = 'app.ico';
24 const ICON_POWERSHELL = 'powershell.ico';
25 const ICON_PEAR = 'pear.ico';
26 const ICON_DB = 'db.ico';
27 const ICON_GHOSTSCRIPT = 'ghostscript.ico';
28 const ICON_GIT = 'git.ico';
29 const ICON_NODEJS = 'nodejs.ico';
30 const ICON_COMPOSER = 'composer.ico';
31 const ICON_PYTHON = 'python.ico';
32 const ICON_RUBY = 'ruby.ico';
33 const ICON_PERL = 'perl.ico';
34 const ICON_NGROK = 'ngrok.ico';
35 */
36
40 private function __construct()
41 {
42 }
43
50 public static function process()
51 {
52 // PowerShell uses profile scripts (Microsoft.PowerShell_profile.ps1)
53 // and Oh My Posh for configuration - no processing needed here
54 return true;
55 }
56
83
95 private static function getTabCmdSection()
96 {
97 global $bearsamppRoot, $bearsamppTools;
98
99 return self::getTab(
100 $bearsamppTools->getPowerShell()->getTabTitleDefault(),
101 null, // self::ICON_APP - Icon not supported in native PowerShell console
102 $bearsamppTools->getPowerShell()->getShell(),
103 $bearsamppRoot->getRootPath()
104 ) . PHP_EOL;
105 }
106
118 private static function getTabPowerShellSection()
119 {
120 global $bearsamppRoot, $bearsamppTools;
121
122 $powerShellPath = Util::getPowerShellPath();
123 if ($powerShellPath !== false) {
124 return self::getTab(
125 $bearsamppTools->getPowerShell()->getTabTitlePowershell(),
126 null, // self::ICON_POWERSHELL - Icon not supported in native PowerShell console
127 $powerShellPath,
128 $bearsamppRoot->getRootPath()
129 ) . PHP_EOL;
130 }
131
132 return "";
133 }
134
146 private static function getTabPearSection()
147 {
148 global $bearsamppBins, $bearsamppTools;
149
150 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppBins->getPhp()->getPearExe() . '&quot;');
151 if (!file_exists($bearsamppBins->getPhp()->getPearExe())) {
152 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppBins->getPhp()->getPearExe() . ' not found');
153 }
154
155 return self::getTab(
156 $bearsamppTools->getPowerShell()->getTabTitlePear(),
157 null, // self::ICON_PEAR - Icon not supported in native PowerShell console
158 $shell,
159 $bearsamppBins->getPhp()->getSymlinkPath() . '/pear'
160 ) . PHP_EOL;
161 }
162
174 private static function getTabMysqlSection()
175 {
176 global $bearsamppBins, $bearsamppTools;
177
178 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppBins->getMysql()->getCliExe() . '&quot; -u' .
179 $bearsamppBins->getMysql()->getRootUser() .
180 ($bearsamppBins->getMysql()->getRootPwd() ? ' -p' : ''));
181 if (!file_exists($bearsamppBins->getMysql()->getCliExe())) {
182 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppBins->getMysql()->getCliExe() . ' not found');
183 }
184
185 return self::getTab(
186 $bearsamppTools->getPowerShell()->getTabTitleMysql(),
187 null, // self::ICON_DB - Icon not supported in native PowerShell console
188 $shell,
189 $bearsamppBins->getMysql()->getSymlinkPath()
190 ) . PHP_EOL;
191 }
192
204 private static function getTabMariadbSection()
205 {
206 global $bearsamppBins, $bearsamppTools;
207
208 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppBins->getMariadb()->getCliExe() . '&quot; -u' .
209 $bearsamppBins->getMariadb()->getRootUser() .
210 ($bearsamppBins->getMariadb()->getRootPwd() ? ' -p' : ''));
211 if (!file_exists($bearsamppBins->getMariadb()->getCliExe())) {
212 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppBins->getMariadb()->getCliExe() . ' not found');
213 }
214
215 return self::getTab(
216 $bearsamppTools->getPowerShell()->getTabTitleMariadb(),
217 null, // self::ICON_DB - Icon not supported in native PowerShell console
218 $shell,
219 $bearsamppBins->getMariadb()->getSymlinkPath()
220 ) . PHP_EOL;
221 }
222
234 private static function getTabPostgresqlSection()
235 {
236 global $bearsamppBins, $bearsamppTools;
237
238 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppBins->getPostgresql()->getCliExe() . '&quot;' .
239 ' -h 127.0.0.1' .
240 ' -p ' . $bearsamppBins->getPostgresql()->getPort() .
241 ' -U ' . $bearsamppBins->getPostgresql()->getRootUser() .
242 ' -d postgres');
243 if (!file_exists($bearsamppBins->getPostgresql()->getCliExe())) {
244 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppBins->getPostgresql()->getCliExe() . ' not found');
245 }
246
247 return self::getTab(
248 $bearsamppTools->getPowerShell()->getTabTitlePostgresql(),
249 null, // self::ICON_DB - Icon not supported in native PowerShell console
250 $shell,
251 $bearsamppBins->getPostgresql()->getSymlinkPath()
252 ) . PHP_EOL;
253 }
254
266 private static function getTabGitSection()
267 {
268 global $bearsamppRoot, $bearsamppTools;
269
270 $shell = $bearsamppTools->getPowerShell()->getShell();
271 if (!file_exists($bearsamppTools->getGit()->getExe())) {
272 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getGit()->getExe() . ' not found');
273 }
274
275 return self::getTab(
276 $bearsamppTools->getPowerShell()->getTabTitleGit(),
277 null, // self::ICON_GIT - Icon not supported in native PowerShell console
278 $shell,
279 $bearsamppRoot->getWwwPath()
280 ) . PHP_EOL;
281 }
282
295 private static function getTabNodejsSection()
296 {
297 global $bearsamppRoot, $bearsamppBins, $bearsamppTools;
298
299 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppBins->getNodejs()->getLaunch() . '&quot;');
300 if (!file_exists($bearsamppBins->getNodejs()->getLaunch())) {
301 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppBins->getNodejs()->getLaunch() . ' not found');
302 }
303
304 return self::getTab(
305 $bearsamppTools->getPowerShell()->getTabTitleNodejs(),
306 null, // self::ICON_NODEJS - Icon not supported in native PowerShell console
307 $shell,
308 $bearsamppRoot->getWwwPath()
309 ) . PHP_EOL;
310 }
311
323 private static function getTabComposerSection()
324 {
325 global $bearsamppRoot, $bearsamppTools;
326
327 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppTools->getComposer()->getExe() . '&quot;');
328 if (!file_exists($bearsamppTools->getComposer()->getExe())) {
329 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getComposer()->getExe() . ' not found');
330 }
331
332 return self::getTab(
333 $bearsamppTools->getPowerShell()->getTabTitleComposer(),
334 null, // self::ICON_COMPOSER - Icon not supported in native PowerShell console
335 $shell,
336 $bearsamppRoot->getWwwPath()
337 ) . PHP_EOL;
338 }
339
351 private static function getTabPythonSection()
352 {
353 global $bearsamppRoot, $bearsamppTools;
354
355 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppTools->getPython()->getExe() . '&quot;');
356 if (!file_exists($bearsamppTools->getPython()->getExe())) {
357 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getPython()->getExe() . ' not found');
358 }
359
360 return self::getTab(
361 $bearsamppTools->getPowerShell()->getTabTitlePython(),
362 null, // self::ICON_PYTHON - Icon not supported in native PowerShell console
363 $shell,
364 $bearsamppRoot->getWwwPath()
365 ) . PHP_EOL;
366 }
367
379 private static function getTabRubySection()
380 {
381 global $bearsamppRoot, $bearsamppTools;
382
383 // Check if Ruby exists first
384 if (!file_exists($bearsamppTools->getRuby()->getExe())) {
385 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getRuby()->getExe() . ' not found');
386 } else {
387 // Use irb (Interactive Ruby) for an interactive shell
388 $rubyDir = dirname($bearsamppTools->getRuby()->getExe());
389 $irbExe = $rubyDir . '/irb.bat';
390
391 // Check if irb.bat exists, otherwise try irb.cmd or just use ruby with -i flag
392 if (file_exists($irbExe)) {
393 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $irbExe . '&quot;');
394 } elseif (file_exists($rubyDir . '/irb.cmd')) {
395 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $rubyDir . '/irb.cmd' . '&quot;');
396 } elseif (file_exists($rubyDir . '/irb')) {
397 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $rubyDir . '/irb' . '&quot;');
398 } else {
399 // Fallback to just opening a shell in the Ruby directory
400 $shell = $bearsamppTools->getPowerShell()->getShell();
401 }
402 }
403
404 return self::getTab(
405 $bearsamppTools->getPowerShell()->getTabTitleRuby(),
406 null, // self::ICON_RUBY - Icon not supported in native PowerShell console
407 $shell,
408 $bearsamppRoot->getWwwPath()
409 ) . PHP_EOL;
410 }
411
423 private static function getTabPerlSection()
424 {
425 global $bearsamppRoot, $bearsamppTools;
426
427 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppTools->getPerl()->getExe() . '&quot;');
428 if (!file_exists($bearsamppTools->getPerl()->getExe())) {
429 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getPerl()->getExe() . ' not found');
430 }
431
432 return self::getTab(
433 $bearsamppTools->getPowerShell()->getTabTitlePerl(),
434 null, // self::ICON_PERL - Icon not supported in native PowerShell console
435 $shell,
436 $bearsamppRoot->getWwwPath()
437 ) . PHP_EOL;
438 }
439
453 private static function getTabGhostscriptSection()
454 {
455 global $bearsamppRoot, $bearsamppTools;
456
457 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppTools->getGhostscript()->getExeConsole() . '&quot;');
458 if (!file_exists($bearsamppTools->getGhostscript()->getExeConsole())) {
459 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getGhostscript()->getExeConsole() . ' not found');
460 }
461
462 return self::getTab(
463 $bearsamppTools->getPowerShell()->getTabTitleGhostscript(),
464 null, // self::ICON_GHOSTSCRIPT - Icon not supported in native PowerShell console
465 $shell,
466 $bearsamppRoot->getWwwPath()
467 ) . PHP_EOL;
468 }
469
483 private static function getTabNgrokSection()
484 {
485 global $bearsamppRoot, $bearsamppTools;
486
487 $shell = $bearsamppTools->getPowerShell()->getShell('&quot;' . $bearsamppTools->getNgrok()->getExe() . '&quot;');
488 if (!file_exists($bearsamppTools->getNgrok()->getExe())) {
489 $shell = $bearsamppTools->getPowerShell()->getShell('echo ' . $bearsamppTools->getNgrok()->getExe() . ' not found');
490 }
491
492 return self::getTab(
493 $bearsamppTools->getPowerShell()->getTabTitleNgrok(),
494 null, // self::ICON_NGROK - Icon not supported in native PowerShell console
495 $shell,
496 $bearsamppRoot->getWwwPath()
497 ) . PHP_EOL;
498 }
499
517 private static function getTab($title, $icon, $shell, $initDir)
518 {
519 global $bearsamppCore;
520 // Icon parameter is ignored as native PowerShell console does not support custom icons
521 // Return tab information as a formatted string
522 return "Title: $title | Shell: $shell | InitDir: $initDir";
523 }
524}
global $bearsamppBins
global $bearsamppRoot
global $bearsamppCore
static getTab($title, $icon, $shell, $initDir)
static getTabGhostscriptSection()
static getPowerShellPath()