mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cache terminall shell env (#274)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
c7f92494e0
commit
81c7590732
@ -30,7 +30,7 @@ export class NodeShellSession extends ShellSession {
|
|||||||
}
|
}
|
||||||
args = ["exec", "-i", "-t", "-n", "kube-system", this.podId, "--", "sh", "-c", "((clear && bash) || (clear && ash) || (clear && sh))"]
|
args = ["exec", "-i", "-t", "-n", "kube-system", this.podId, "--", "sh", "-c", "((clear && bash) || (clear && ash) || (clear && sh))"]
|
||||||
|
|
||||||
const shellEnv = this.getShellEnv()
|
const shellEnv = await this.getCachedShellEnv()
|
||||||
this.shellProcess = pty.spawn(shell, args, {
|
this.shellProcess = pty.spawn(shell, args, {
|
||||||
cols: 80,
|
cols: 80,
|
||||||
cwd: this.cwd() || shellEnv["HOME"],
|
cwd: this.cwd() || shellEnv["HOME"],
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import { Cluster, ClusterPreferences } from "./cluster"
|
|||||||
import { helmCli } from "./helm-cli"
|
import { helmCli } from "./helm-cli"
|
||||||
|
|
||||||
export class ShellSession extends EventEmitter {
|
export class ShellSession extends EventEmitter {
|
||||||
|
static shellEnv: any
|
||||||
|
|
||||||
protected websocket: WebSocket
|
protected websocket: WebSocket
|
||||||
protected shellProcess: pty.IPty
|
protected shellProcess: pty.IPty
|
||||||
protected kubeconfigPath: string
|
protected kubeconfigPath: string
|
||||||
@ -30,8 +32,7 @@ export class ShellSession extends EventEmitter {
|
|||||||
public async open() {
|
public async open() {
|
||||||
this.kubectlBinDir = await this.kubectl.binDir()
|
this.kubectlBinDir = await this.kubectl.binDir()
|
||||||
this.helmBinDir = helmCli.getBinaryDir()
|
this.helmBinDir = helmCli.getBinaryDir()
|
||||||
await helmCli.binaryPath()
|
const env = await this.getCachedShellEnv()
|
||||||
const env = this.getShellEnv()
|
|
||||||
const shell = env.PTYSHELL
|
const shell = env.PTYSHELL
|
||||||
const args = await this.getShellArgs(shell)
|
const args = await this.getShellArgs(shell)
|
||||||
this.shellProcess = pty.spawn(shell, args, {
|
this.shellProcess = pty.spawn(shell, args, {
|
||||||
@ -75,8 +76,25 @@ export class ShellSession extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getShellEnv() {
|
protected async getCachedShellEnv() {
|
||||||
const env = JSON.parse(JSON.stringify(shellEnv.sync()))
|
let env: any
|
||||||
|
if (!ShellSession.shellEnv) {
|
||||||
|
env = await this.getShellEnv()
|
||||||
|
ShellSession.shellEnv = env
|
||||||
|
} else {
|
||||||
|
env = ShellSession.shellEnv
|
||||||
|
|
||||||
|
// refresh env in the background
|
||||||
|
this.getShellEnv().then((shellEnv: any) => {
|
||||||
|
ShellSession.shellEnv = shellEnv
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async getShellEnv() {
|
||||||
|
const env = JSON.parse(JSON.stringify(await shellEnv()))
|
||||||
const pathStr = [this.kubectlBinDir, this.helmBinDir, process.env.PATH].join(path.delimiter)
|
const pathStr = [this.kubectlBinDir, this.helmBinDir, process.env.PATH].join(path.delimiter)
|
||||||
|
|
||||||
if(process.platform === "win32") {
|
if(process.platform === "win32") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user