38 lines
1.1 KiB
Fish
38 lines
1.1 KiB
Fish
function split_run
|
|
argparse mask r/restart -- $argv
|
|
or return
|
|
|
|
if not set -qg MPROCS_PORT
|
|
set -gx MPROCS_PORT $(random 1024 2048)
|
|
kitten @ env "MPROCS_PORT=$MPROCS_PORT"
|
|
end
|
|
|
|
if set -ql _flag_restart
|
|
# Send commands to server
|
|
mprocs --server "127.0.0.1:$MPROCS_PORT" --ctl "{c: restart-proc}"
|
|
return 0
|
|
end
|
|
|
|
|
|
if set -ql _flag_mask
|
|
set -l cmd "$(mask --introspect | jq ".commands[] | [.name, .description] | @tsv" -r | fzf --accept-nth=1)"
|
|
|
|
if test -z $cmd
|
|
return 1
|
|
end
|
|
|
|
set -l cmd "mask $cmd"
|
|
|
|
# check if server is running
|
|
if nc -w 1 -zv 127.0.0.1 $MPROCS_PORT &>/dev/null
|
|
mprocs --server "127.0.0.1:$MPROCS_PORT" --ctl "{c: add-proc, cmd: \"$cmd\"}"
|
|
mprocs --server "127.0.0.1:$MPROCS_PORT" --ctl "{c: select-proc, index: 0}"
|
|
mprocs --server "127.0.0.1:$MPROCS_PORT" --ctl "{c: prev-proc}"
|
|
else
|
|
# Start server
|
|
kitten @ launch --cwd=current --location last --dont-take-focus mprocs --server "127.0.0.1:$MPROCS_PORT" "$cmd"
|
|
end
|
|
end
|
|
|
|
|
|
end
|