From ca62f8dacc6a5459e0ba34f06803c91cf80d9dce Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:48:59 +0200 Subject: [PATCH] refactor(terminal): simplify command construction for SSH execution --- app/Livewire/Project/Shared/Terminal.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Livewire/Project/Shared/Terminal.php b/app/Livewire/Project/Shared/Terminal.php index 8b0f3229f..de2deeed4 100644 --- a/app/Livewire/Project/Shared/Terminal.php +++ b/app/Livewire/Project/Shared/Terminal.php @@ -68,9 +68,15 @@ class Terminal extends Component // Escape the identifier for shell usage $escapedIdentifier = escapeshellarg($identifier); - $command = SshMultiplexingHelper::generateSshCommand($server, "docker exec -it {$escapedIdentifier} sh -c 'PATH=\$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && if [ -f ~/.profile ]; then . ~/.profile; fi && if [ -n \"\$SHELL\" ] && [ -x \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'"); + $shellCommand = 'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && '. + 'if [ -f ~/.profile ]; then . ~/.profile; fi && '. + 'if [ -n "$SHELL" ] && [ -x "$SHELL" ]; then exec $SHELL; else sh; fi'; + $command = SshMultiplexingHelper::generateSshCommand($server, "docker exec -it {$escapedIdentifier} sh -c '{$shellCommand}'"); } else { - $command = SshMultiplexingHelper::generateSshCommand($server, 'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && if [ -f ~/.profile ]; then . ~/.profile; fi && if [ -n "$SHELL" ] && [ -x "$SHELL" ]; then exec $SHELL; else sh; fi'); + $shellCommand = 'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && '. + 'if [ -f ~/.profile ]; then . ~/.profile; fi && '. + 'if [ -n "$SHELL" ] && [ -x "$SHELL" ]; then exec $SHELL; else sh; fi'; + $command = SshMultiplexingHelper::generateSshCommand($server, $shellCommand); } // ssh command is sent back to frontend then to websocket // this is done because the websocket connection is not available here