summaryrefslogtreecommitdiff
path: root/tabby-runner/index.js
diff options
context:
space:
mode:
authornavewindre <boneyaard@gmail.com>2024-09-30 17:40:15 +0200
committernavewindre <boneyaard@gmail.com>2024-09-30 17:40:15 +0200
commit5488c375f8e545158029e32085cb5f62dfe48819 (patch)
tree394d5f4c2eb70dd05d2dafc8ae766f92240b8ed4 /tabby-runner/index.js
parentb73fc066ba163c3f04fc7e225464e958ca9c05a8 (diff)
add tabby runner
Diffstat (limited to 'tabby-runner/index.js')
-rwxr-xr-xtabby-runner/index.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/tabby-runner/index.js b/tabby-runner/index.js
new file mode 100755
index 0000000..93eb768
--- /dev/null
+++ b/tabby-runner/index.js
@@ -0,0 +1,62 @@
+const cp = require('child_process');
+const exec = cp.exec;
+let child;
+
+let killTabby = () => {
+ exec( "ps aux | grep -E 'tabby'", ( error, stdout, stderr ) => {
+ if( stdout ) {
+ console.log( stdout );
+ let lines = stdout.split( '\n' );
+ for( let line of lines ) {
+ let parts = line.split( /\s+/ );
+ if( ( parts[10] === './tabby' || parts[10] == 'tabby' ) && parts[11] == 'serve' ) {
+ cp.spawnSync( 'pkill', ['-P', parts[1]], { stdio: 'inherit' } );
+ cp.spawnSync( 'kill', [parts[1]], { stdio: 'inherit' } );
+ break;
+ }
+ }
+ }
+ } );
+}
+
+
+let loop = () => {
+ exec( "ps aux | grep -E 'vim|nvim'", ( error, stdout, stderr ) => {
+ if( stdout ) {
+ console.log( stdout );
+ let lines = stdout.split( '\n' );
+ let vimOpen = false;
+ for( let line of lines ) {
+ let parts = line.split( /\s+/ );
+ if( parts[10] === 'vim' || parts[10] === 'nvim' ) {
+ vimOpen = true;
+ break;
+ }
+ }
+ if( vimOpen ) {
+ if( child ) return setTimeout( loop, 120000 );
+ child = cp.exec( `./run-client.sh` );
+ return setTimeout( loop, 5000 );
+ }
+
+ if( child ) {
+ killTabby();
+ child.kill();
+ }
+
+ child = null;
+ setTimeout( loop, 5000 );
+ } else {
+ if( child ) {
+ killTabby();
+ child.kill();
+ child = null;
+ }
+
+ setTimeout( loop, 5000 );
+ }
+ });
+
+};
+
+loop();