News for hackers. Stuff that matters.
Re:How to move a running process into a tmux session (2020) by leni536 on Wednesday October 05, 2022 @02:26AM (#33091979)
> It’s rare, but sometimes it still happens that I forget to open a tmux or screen session when working with something that is supposed to be quickly done.

There are various ways to get ahead of this problem too if you ssh into a tmux session automatically. There are various ways to achieve this.

I didn't know about reptyr, it's very cool. There were times I wished this was possible, but whenever I searched for a solution I got "It's not possible". Oh well...

Re:How to move a running process into a tmux session (2020) by susam on Wednesday October 05, 2022 @03:36AM (#33092436)
Yes! I have a shell function that automatically attaches to an existing tmux session or creates a new tmux session if none exists already, after logging into the remote system via SSH:

  ssht() {
      ssh -t $1 'tmux a || tmux'
  }
Re:How to move a running process into a tmux session (2020) by skhm on Wednesday October 05, 2022 @05:30AM (#33093156)
Don't you find it painful having your tmux session rooted in your homedir (e.g. for all new windows)? I nearly always need to have it anchored some project working directory.
Re:How to move a running process into a tmux session (2020) by mathstuf on Wednesday October 05, 2022 @06:24AM (#33093533)
I have tmux anchored to ~ because I hated new shells inheriting random cwd states. Instead I have a function to cd to "bookmarks" with an easy way to add to it and completion.
Re:How to move a running process into a tmux session (2020) by susam on Wednesday October 05, 2022 @03:23PM (#33100146)
I have the following in my ~/.tmux.conf so that whenever I split pane or create a new tmux window, it sets the current working directory of the new pane or window to the same directory in which I was before:

  # Open new pane or window with the current directory
  bind '"' split-window -c "#{pane_current_path}"
  bind % split-window -h -c "#{pane_current_path}"
  bind c new-window -c "#{pane_current_path}"
So although the tmux session is run in my home directory, I only need to change the current working directory to my project directory once and then when I create new panes and windows, they have the project directory as the current working directory.
Re:How to move a running process into a tmux session (2020) by planede on Wednesday October 05, 2022 @04:17AM (#33092705)
I have an autossh + tmux setup. It's along the lines of

  autossh -M 0 -t remote "tmux new-session -A -D -s $RANDOM$RANDOM$RANDOM$RANDOM"
with appropriate ServerAliveInterval and ServerAliveCountMax settings. It works somewhat nicely with dodgy ssh conncetions too. I'm aware of mosh, but this one even outlives when I put the laptop to sleep. Also mosh doesn't allow X forwarding, and I enable that for sharing the clipboard (yes, I'm aware of the security implications). And if I want to leave something long-running, I can just close the window and reattach later.
Re:How to move a running process into a tmux session (2020) by skhm on Wednesday October 05, 2022 @05:29AM (#33093149)
Mosh should survive a laptop sleep no problem - if it doesn't, something is misconfigured. X forwarding is a dealbreaker though.