mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-06 06:54:56 +00:00
optional script
This commit is contained in:
@@ -4,6 +4,7 @@ export interface LoginScript {
|
||||
expect?: string
|
||||
send: string
|
||||
isRegex?: boolean
|
||||
optional?: boolean
|
||||
}
|
||||
|
||||
export interface SSHConnection {
|
||||
@@ -38,26 +39,36 @@ export class SSHSession extends BaseSession {
|
||||
if (this.scripts) {
|
||||
let found = false
|
||||
for (let script of this.scripts) {
|
||||
let match = false
|
||||
let cmd = ""
|
||||
if (script.isRegex) {
|
||||
let re = new RegExp(script.expect, "g");
|
||||
|
||||
let re = new RegExp(script.expect, "g")
|
||||
if (dataString.match(re)) {
|
||||
let cmd = dataString.replace(re, script.send);
|
||||
console.log('Executing script:', cmd)
|
||||
this.shell.write(cmd + '\n')
|
||||
this.scripts = this.scripts.filter(x => x !== script)
|
||||
cmd = dataString.replace(re, script.send)
|
||||
match = true
|
||||
found = true
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dataString.includes(script.expect)) {
|
||||
console.log('Executing script:', script.send)
|
||||
this.shell.write(script.send + '\n')
|
||||
this.scripts = this.scripts.filter(x => x !== script)
|
||||
cmd = script.send
|
||||
match = true
|
||||
found = true
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
if (match) {
|
||||
console.log('Executing script: "' + cmd + '"')
|
||||
this.shell.write(cmd + '\n')
|
||||
this.scripts = this.scripts.filter(x => x !== script)
|
||||
}
|
||||
else {
|
||||
if (script.optional) {
|
||||
console.log("Skip optional script: " + script.expect)
|
||||
found = true
|
||||
this.scripts = this.scripts.filter(x => x !== script)
|
||||
}
|
||||
else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user