Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,17 @@ fn get_available_shells() -> Vec<ShellInfo> {

#[cfg(target_os = "windows")]
{
// CRITICAL: Check explicit paths FIRST, then PATH entries
// This ensures the correct shell is found when multiple versions exist
let mut candidates = vec![
// PowerShell 7 explicit paths (checked first)
("pwsh", r"C:\Program Files\PowerShell\7\pwsh.exe", None),
("pwsh", r"C:\Program Files\PowerShell\6\pwsh.exe", None),
// Windows PowerShell 5 (explicit path)
("powershell", r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", None),
// PATH-based fallbacks (checked last)
("pwsh", "pwsh.exe", None),
("powershell", "powershell.exe", None),
("pwsh", "pwsh.exe", None), // PowerShell 7 via PATH
("pwsh", "C:\\Program Files\\PowerShell\\7\\pwsh.exe", None), // PowerShell 7 explicit path
("cmd", "cmd.exe", None),
("wsl", "wsl.exe", None),
];
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/src/pty/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,12 +994,17 @@ impl PtyManager {
}

// Try PowerShell variants
// CRITICAL: Check explicit paths FIRST, then PATH
if shell == "powershell" || shell == "pwsh" {
let paths = vec![
"pwsh.exe",
"powershell.exe",
// PowerShell 7 explicit paths (checked first)
r"C:\Program Files\PowerShell\7\pwsh.exe",
r"C:\Program Files\PowerShell\6\pwsh.exe",
// Windows PowerShell 5 explicit path
r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",
// PATH-based fallbacks (checked last)
"pwsh.exe",
"powershell.exe",
];
for path in paths {
if let Some(abs_path) = self.get_absolute_shell_path(path) {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/ProjectSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export function ProjectSidebar({
const project = projects.find((p) => p.id === projectId)
const shellSubmenu: ContextMenuSubItem[] = availableShells?.available.map((shell) => ({
label: shell.displayName,
value: shell.name,
isSelected: project?.defaultShell === shell.name
value: shell.path,
isSelected: project?.defaultShell === shell.path
})) || []

const items: ContextMenuItem[] = [
Expand All @@ -237,8 +237,8 @@ export function ProjectSidebar({
label: 'Set Default Shell',
icon: <Terminal size={14} />,
submenu: shellSubmenu,
onSubmenuSelect: (shellName: string) => {
onUpdateProject(projectId, { defaultShell: shellName })
onSubmenuSelect: (shellPath: string) => {
onUpdateProject(projectId, { defaultShell: shellPath })
}
})
}
Expand Down
39 changes: 35 additions & 4 deletions src/renderer/hooks/use-terminal-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTerminalStore } from '../stores/terminal-store'
import { useAppSettingsStore } from '../stores/app-settings-store'
import { useWorkspaceStore } from '../stores/workspace-store'
import { terminalApi } from '@/lib/api'
import { shellApi } from '@/lib/shell-api'
import {
loadPersistedTerminals,
saveTerminalLayout,
Expand Down Expand Up @@ -142,6 +143,34 @@ export function normalizeShellForStartup(shell?: string): string {
return shell
}

/**
* Resolve shell identifier to an absolute path.
* If the shell is already a path (contains \ or /), return it as-is.
* If it's just a name (e.g., "pwsh", "bash"), look up the path from available shells.
*/
async function resolveShellToPath(shell: string): Promise<string> {
// If shell is already a path, return it as-is
if (shell.includes('\\') || shell.includes('/')) {
return shell
}

// Otherwise, look up the path from available shells
try {
const result = await shellApi.getAvailableShells()
if (result.success && result.data.available) {
const match = result.data.available.find((s) => s.name === shell)
if (match) {
return match.path
}
}
} catch (error) {
console.error('Failed to resolve shell path:', error)
}

// Fallback: return original value
return shell
}

/**
* Hook to restore terminals when switching projects
* Loads persisted terminal layout and creates terminal instances
Expand Down Expand Up @@ -415,7 +444,8 @@ async function restoreFromLayout(projectId: string, layout: PersistedTerminalLay
TERMINALS_PENDING_PTY_ASSIGNMENT.add(newId)

try {
const normalizedShell = normalizeShellForStartup(persistedTerminal.shell)
const resolvedShell = await resolveShellToPath(persistedTerminal.shell)
const normalizedShell = normalizeShellForStartup(resolvedShell)
const spawnResult = await terminalApi.spawn({
shell: normalizedShell,
cwd: persistedTerminal.cwd
Expand Down Expand Up @@ -546,10 +576,11 @@ async function createDefaultTerminal(projectId: string): Promise<void> {
}

// Get shell from fallback chain: project -> app settings -> system default
// Then resolve shell name to path for backward compatibility
const project = projectStore.projects.find((p) => p.id === projectId)
const shell = normalizeShellForStartup(
project?.defaultShell || appSettings.settings.defaultShell || ''
)
const shellSetting = project?.defaultShell || appSettings.settings.defaultShell || ''
const resolvedShell = await resolveShellToPath(shellSetting)
const shell = normalizeShellForStartup(resolvedShell)

debugLog('createDefaultTerminal', `Spawning default terminal [${defaultId}]`, {
shell,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/layouts/WorkspaceLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export default function WorkspaceLayout(): React.JSX.Element {
handleCreateTerminalInPane(paneId)
}}
onNewTerminalWithShell={(paneId, shell) => {
handleCreateTerminalInPane(paneId, shell.name)
handleCreateTerminalInPane(paneId, shell.path)
}}
onCloseTerminal={handleCloseTerminal}
onRenameTerminal={renameTerminal}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/pages/AppPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ export default function AppPreferences(): React.JSX.Element {
>
<option value="">System Default</option>
{availableShells?.available?.map((shell) => (
<option key={shell.path} value={shell.name}>
{shell.name} ({shell.path})
<option key={shell.path} value={shell.path}>
{shell.displayName}
</option>
))}
</select>
Expand Down
Loading