* `is_port_unused` takes a port like "4000" as its first argument and exits 0 if it's available, or 1 if it's not. * `find_unused_port` checks ports 4000/5000/6000/7000/8000/9000 and echoes the first one that's unused. If all of them are in use, it exits 1. * `start_foreman_on_unused_port` uses the above scripts to find an unused port. It first tries the port in the `.foreman` file (if available), then uses `find_unused_port` to find an unused port. It uses `forego`, the Go port of foreman, if it's available, and falls back to plain old `foreman` otherwise. `f` is a convenient alias for `start_foreman_on_unused_port`.
`cd` doesn't work in shell scripts because each one runs in its own subshell. The `cd` successfully changes the directory *in the subshell*, then the subshell dies because the shell script has finished, and nothing happens in your shell. So `superclone` now returns the name of the directory to `cd` into and we run `cd` as a function in *this* shell. It's all very silly.