mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-24 17:16:03 +00:00
add regex support
This commit is contained in:
@@ -3,6 +3,7 @@ import { BaseSession } from 'terminus-terminal'
|
|||||||
export interface LoginScript {
|
export interface LoginScript {
|
||||||
expect?: string
|
expect?: string
|
||||||
send: string
|
send: string
|
||||||
|
isRegex?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SSHConnection {
|
export interface SSHConnection {
|
||||||
@@ -37,13 +38,28 @@ export class SSHSession extends BaseSession {
|
|||||||
if (this.scripts) {
|
if (this.scripts) {
|
||||||
let found = false
|
let found = false
|
||||||
for (let script of this.scripts) {
|
for (let script of this.scripts) {
|
||||||
if (dataString.includes(script.expect)) {
|
if (script.isRegex) {
|
||||||
console.log('Executing script:', script.send)
|
let re = new RegExp(script.expect, "g");
|
||||||
this.shell.write(script.send + '\n')
|
|
||||||
this.scripts = this.scripts.filter(x => x !== script)
|
if (dataString.match(re)) {
|
||||||
found = true
|
let cmd = dataString.replace(re, script.send);
|
||||||
} else {
|
console.log('Executing script:', cmd)
|
||||||
break
|
this.shell.write(cmd + '\n')
|
||||||
|
this.scripts = this.scripts.filter(x => x !== script)
|
||||||
|
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)
|
||||||
|
found = true
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -94,18 +94,23 @@
|
|||||||
tr
|
tr
|
||||||
th String to expect
|
th String to expect
|
||||||
th String to be sent
|
th String to be sent
|
||||||
|
th Regex
|
||||||
th Actions
|
th Actions
|
||||||
tr(*ngFor='let script of connection.scripts')
|
tr(*ngFor='let script of connection.scripts')
|
||||||
td
|
td
|
||||||
input.form-control(
|
input.form-control(
|
||||||
type='text',
|
type='text',
|
||||||
[(ngModel)]='script.expect'
|
[(ngModel)]='script.expect'
|
||||||
)
|
)
|
||||||
td
|
td
|
||||||
input.form-control(
|
input.form-control(
|
||||||
type='text',
|
type='text',
|
||||||
[(ngModel)]='script.send'
|
[(ngModel)]='script.send'
|
||||||
)
|
)
|
||||||
|
td
|
||||||
|
toggle(
|
||||||
|
[(ngModel)]='script.isRegex',
|
||||||
|
)
|
||||||
td
|
td
|
||||||
.input-group.flex-nowrap
|
.input-group.flex-nowrap
|
||||||
button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)')
|
button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)')
|
||||||
@@ -127,6 +132,10 @@
|
|||||||
placeholder='Enter a string to be sent',
|
placeholder='Enter a string to be sent',
|
||||||
[(ngModel)]='newScript.send'
|
[(ngModel)]='newScript.send'
|
||||||
)
|
)
|
||||||
|
td
|
||||||
|
toggle(
|
||||||
|
[(ngModel)]='newScript.isRegex',
|
||||||
|
)
|
||||||
td
|
td
|
||||||
.input-group.flex-nowrap
|
.input-group.flex-nowrap
|
||||||
button.btn.btn-outline-info.ml-0((click)='addScript()')
|
button.btn.btn-outline-info.ml-0((click)='addScript()')
|
||||||
|
Reference in New Issue
Block a user