elisescu / tty-share

Share your linux or osx terminal over the Internet.
https://tty-share.com/
MIT License
816 stars 87 forks source link

Feature request: Set env vars #22

Closed pschmitt closed 3 years ago

pschmitt commented 3 years ago

Hey, great piece of software - I'll 100% use this for my next online meeting.

I couldn't find an easy way to set env vars in the command executed by tty-share though. Here's what I would like to be able to do:

You can right now already get around the first "issue" by using a custom shell function (see below), but I couldn't find a way to get the urls after the initial launch.

tty-share () {
  TTY_SHARE=1 command tty-share "$@"
}

Thanks for this epic alternative to tmate!

EDIT: Having an env var such as TTY_SHARE would also make it pretty easy to avoid running nested tty-share sessions (same as tmux)

pschmitt commented 3 years ago

So it turns out you can fetch the public from the log file if you enable verbose logging. Here's what I ended up with:

TTY_SHARE_LOGFILE="${TMPDIR:-/tmp}/tty-share.log"

tty-share() {
  if [[ -n "$TTY_SHARE" ]]
  then
    echo "TTY_SHARE is set. You are already running tty-share. Unset TTY_SHARE to force."
    return 1
  fi
  tmux set-env -g TTY_SHARE 1

  TTY_SHARE=1 command tty-share \
    --logfile "$TTY_SHARE_LOGFILE" --verbose \
    "$@"

  tmux set-env -gu TTY_SHARE
}

if [[ -n "$TTY_SHARE" ]]
then
  export TTY_SHARE=1

  if [[ -r "$TTY_SHARE_LOGFILE" ]]
  then
    export TTY_SHARE_URL="$(head -n 1 "$TTY_SHARE_LOGFILE" | sed -nr 's/.*Connected to (http[^ ]+).*/\1/p')"
  fi
fi

# vim: set ft=zsh et ts=2 sw=2 :
elisescu commented 3 years ago

Hey @pschmitt!

I thought about the same, inspired by tmux, but unfortunately I didn't get to do it. I'll add it to my TODO list, and hopefully add it soon, as it probably should be very simple. Sorry you had to go through that pain of parsing the logs for this.

And thanks for using tty-share, it's motivating to read that :)

elisescu commented 3 years ago

FYI, I added the environmental variables in the latest commit, @pschmitt. https://github.com/elisescu/tty-share/pull/27

pschmitt commented 3 years ago

Cheers 🥳