- Inject shell integration (PROMPT_COMMAND/precmd) on SSH connect that
emits OSC 7 escape sequences reporting the working directory on every
prompt. Supports bash and zsh.
- Frontend captures OSC 7 via xterm.js parser, updates session store CWD.
- SFTP sidebar watches session CWD and navigates when it changes.
- SFTP starts at ~/ (user home) instead of / on initial connect, resolved
via SFTP realpath('.') on the backend.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
interface Session {
|
|
key: string // stable Vue key — never changes after creation
|
|
id: string // uuid from backend (starts as pending-XXX, replaced with real UUID)
|
|
hostId: number
|
|
hostName: string
|
|
protocol: 'ssh' | 'rdp'
|
|
color: string | null
|
|
active: boolean
|
|
cwd?: string // current working directory (SSH only, set via OSC 7 shell integration)
|
|
}
|
|
|
|
export const useSessionStore = defineStore('sessions', {
|
|
state: () => ({
|
|
sessions: [] as Session[],
|
|
activeSessionId: null as string | null,
|
|
}),
|
|
getters: {
|
|
activeSession: (state) => state.sessions.find(s => s.id === state.activeSessionId),
|
|
hasSessions: (state) => state.sessions.length > 0,
|
|
},
|
|
actions: {
|
|
addSession(session: Session) {
|
|
this.sessions.push(session)
|
|
this.activeSessionId = session.id
|
|
},
|
|
removeSession(id: string) {
|
|
this.sessions = this.sessions.filter(s => s.id !== id)
|
|
if (this.activeSessionId === id) {
|
|
this.activeSessionId = this.sessions.length ? this.sessions[this.sessions.length - 1].id : null
|
|
}
|
|
},
|
|
replaceSession(oldId: string, newSession: Session) {
|
|
const idx = this.sessions.findIndex(s => s.id === oldId)
|
|
if (idx !== -1) {
|
|
// Preserve the stable key so Vue doesn't remount the component
|
|
newSession.key = this.sessions[idx].key
|
|
this.sessions[idx] = newSession
|
|
} else {
|
|
this.sessions.push(newSession)
|
|
}
|
|
this.activeSessionId = newSession.id
|
|
},
|
|
setActive(id: string) {
|
|
this.activeSessionId = id
|
|
},
|
|
updateCwd(sessionId: string, cwd: string) {
|
|
const session = this.sessions.find(s => s.id === sessionId)
|
|
if (session) {
|
|
session.cwd = cwd
|
|
}
|
|
},
|
|
},
|
|
})
|