This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/bin/remote

18 lines
511 B
Plaintext
Raw Normal View History

#!/usr/bin/env moon
require('fun')!
garg = (v, i) -> os.getenv(v[1]) or arg[i] or v[2]
target, fwd, mpr, sargs, margs = unpack totable map garg, iter {
{"REMOTE_MACHINE", "remote"}
{"SSH_FORWARD_PORTS", "1313,3000,8000,8080,1234,40080:80,40443:443"}
{"MOSH_PORT_RANGE", "60000:61000"}
{"SSH_ARGS", "-XY"}
{"MOSH_ARGS", ""}
}
sfwd = fwd\gsub "(%d+):?(%d*),?", (p, mp) ->
"-L #{p}:localhost:#{if mp == "" then p else mp} "
os.execute "mosh -p '#{mpr}' '#{target}' --ssh='ssh #{sfwd} #{sargs}' #{margs}"