تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Why Use Screen0:00

You may recognize this situation. You have half a dozen tabs open in your terminal with a dev server, maybe a coding agent or two. A relfloop is running, we have lazy get going. And at this point you may want to clean up your windows and you accidentally close the terminal. If you close the terminal window, every process stops, including a relfloop. And depending on timing, you might lose progress, which is not great. Looking for us, there are a few tools available to mitigate this. The first tool I'll show you is screen.

Starting a Screen Session0:25

Looking for us, there are a few tools available to mitigate this. The first tool I'll show you is screen. This probably comes pre-installed on your machine and we can verify this by using screen -version. And if we were to get an error here that the command is not found, we can install it by saying brew install screen on a Mac or apt get install screen on Linux. Once it's installed, let's run screen and at first it may feel like nothing happened. Your terminal just clears and you're looking at what seems to be an empty shell

happened. Your terminal just clears and you're looking at what seems to be an empty shell . But what actually happened is much cooler, you are now inside a virtual terminal session managed by screen. Anything you run right now is running inside that screen session and not your original terminal window. For example, we can start a clot, we'll give it a prompt. And now we can detach from this session by pressing ctrl A and then D. And now we're back in our original shell and we see a message that the screen

And now we can detach from this session by pressing ctrl A and then D. And now we're back in our original shell and we see a message that the screen detached. However, it's still running in the background and we can reattach to it as follows. We can say screen -r for reattach and now we can see our cloud session from before again. We can exit out of the cloud code session by pressing ctrl C, ctrl C again. And now we can terminate the screen session by pressing ctrl D. And here we can see the message that screen is terminatingating.

Named Screen Sessions1:47

And now we can terminate the screen session by pressing ctrl D. And here we can see the message that screen is terminatingating. Now instead of using an unnamed session, I like to name my sessions and let's create one named Ralph. And we can do that as follows. We can say screen -s for session, it needs to be capitalized and we can say Ralph. And in here, let's start our new Ralph loop. I prepared a PRD in which we will add a pop-up with upselling items when we add something to the card. Let's run node Ralph.js and Ralph will start working.

something to the card. Let's run node Ralph.js and Ralph will start working. And while it's running, we can now safely detach from this session by saying c trl A, D. And now when we run screen list, we get a list of all of our detached screens and here we'll see our Ralph screen. If we quickly want to check in on our loop, we can say screen -r for reattach, we can say Ralph and we can see it's still running. The loop will even continue running

Introducing Tmux2:37

we can say Ralph and we can see it's still running. The loop will even continue running if we close our terminal window. And when we reopen our terminal and we re attach to the screen session, we can see Ralph is still working, which is great. There's another tool that solves the same problem and it's called teamux. Teamux is a modern brother of screen and it's much more flexible. Teamux can feel a bit overwhelming at first. If you start reading about it online, you'll quickly run into massive configuration files, plugin managers and people

online, you'll quickly run into massive configuration files, plugin managers and people who have spent the years perfecting their setup. But the good news is you don't need most of that. Let's take a look at the basics. And by the way, I'm using ghosty as my terminal app, because it has great performance and great support for things like teamux. Alright, let's first check if teamux is installed. We can say teamux -h. And if it's not installed, we have to install it by saying brew install teamux.

Alright, let's first check if teamux is installed. We can say teamux -h. And if it's not installed, we have to install it by saying brew install teamux. Or on Ubuntu, we have to say sudo apt-get install teamux. To start, let's just run teamux. And now we can already visually see the difference between screen because the yellow bar at the bottom will say we are in a teamux session . To detach from a teamux session, instead of saying control AD, we have to say control B and then D. And to reattach, we just say teamux attach .

we have to say control B and then D. And to reattach, we just say teamux attach . Control D kills the session like with screen. Alright, so far nothing special. We can also name our session with teamux new -s Ralph. And now at the bottom, you can see that the session is named Ralph. If we detach from it using control B, D and we want to reattach to it, we can say teamux attach -t Ralph. And now we're attached to our Ralph session again. So far this looks very similar to screen, but here's where teamux starts to

Splitting Tmux Panes4:14

-t Ralph. And now we're attached to our Ralph session again. So far this looks very similar to screen, but here's where teamux starts to shine. Inside the teamux session, I can split my terminal. For example, let's say we have a cloud session, we can now press control B percent. And this adds a second pane in our teamux session. In here, we can run codecs, for example, and if we say control B double quote, the pane splits vertically. If we say control D, the pane gets killed again. I find myself using this all the time during development. I usually have a

the pane splits vertically. If we say control D, the pane gets killed again. I find myself using this all the time during development. I usually have a session like this, where we have lazy get on the left, control B percent, we will split horizontally, I have cloud running, control B percent, and I may have cloud running again, or codecs if I'm feeling adventurous. To jump between panes, we can either do control B and the arrow key. Now I am here, control B right arrow key. Now I am here, or we can enter a teamux command by saying control B colon. Now we will be

and the arrow key. Now I am here, control B right arrow key. Now I am here, or we can enter a teamux command by saying control B colon. Now we will be focused at the bottom, and we can say set G mouse on. And now when I click on the pane, it will be focused. So now lazy get is selected, now cloud is selected, and now codecs is selected. If I press control B D, I will detach from that session. I can attach back to it, and my panes will still be there. To make your life easier, I recommend you add this in your teamux conf,

will still be there. To make your life easier, I recommend you add this in your teamux conf, so control B D to detach, then we say nano teamux conf. And I like to add set G mouse on in that teamux configuration file. So every teamux session has mouse interaction enabled by default. One small recommendation, it's tempting to heavily remap keys and customize everything in this configuration file. Just try not to overdo it. If you work on servers or jump

in this configuration file. Just try not to overdo it. If you work on servers or jump between machines, sticking close to the defaults makes your life much easier. It's a matter of muscle memory to learn the commands by heart, and after a day or two, you won't think twice about them. Let me show you a cool trick you can do in teamux. Let's reattach to a Ralph session and clean it up a bit. Let's start Claude, control B percent codecs, control B colon to jump to the command entry,

Synchronizing Tmux Panes6:25

it up a bit. Let's start Claude, control B percent codecs, control B colon to jump to the command entry, and let's enter a command, we can say set a window option synchronize pains. And let's say on. Now everything we type is synchronized between the sessions. And this is actually a pretty cool way to run the same prompt in multiple agents at the same time. To disable this again, we can say control B colon, we press the arrow up and instead of on we say off. And now the syncing stopped,

control B colon, we press the arrow up and instead of on we say off. And now the syncing stopped, and we can jump between the pains by pressing control B and the arrow keys, or by clicking on them with our mouse. There are a whole lot of crazy things you can do with team ux, but I like to keep my setup simple. I usually run a single team accession with multiple Ralph loops going at the same time as follows. Let me first clean this up. Let's reattach to a Ralph session.

at the same time as follows. Let me first clean this up. Let's reattach to a Ralph session. Then I'll say note Ralph, control B percent, note Ralph, control B percent, note Ralph, control B left, control B percent, note Ralph. And as we saw in the previous lesson, if you have multiple PRDs, the node script will prompt us to select one. But because we only have one, it will start directly. And by the looks of it, it actually already completed in our screen

one, it will start directly. And by the looks of it, it actually already completed in our screen session we started before. And the thing is, I never find myself running more than four to six loops at the same time. So this setup works great for me. And this is actually all you really need to get started with teamux. Before we move on to the next lesson, let's detach from this teamux session. And let's reattach to the screen session. And we can see it is in fact done. Let's

Testing the Popup8:11

teamux session. And let's reattach to the screen session. And we can see it is in fact done. Let's test our pop up. Alright, let's take a look at our webshop. And if we add a burger, we should be prompted with an upselling model, which we see here, we have some new drinks at it. Let's add some water with it. And if I'm not mistaken, when we add a drink to the cart, the pop up should not show this is looking great. And let's add some nuggets and the pop up will show again. That's great.

show this is looking great. And let's add some nuggets and the pop up will show again. That's great. So while I was showing you all the teamwork goodness, the loop in the background in the screen session was still running and finished working. My recommendation to you is that you use teamux where possible. And if you're in an environment that for some reason cannot have teamux installed, screen is a great fallback as well. Join me in the next lesson where we'll talk about permissions

screen is a great fallback as well. Join me in the next lesson where we'll talk about permissions and sandboxing. I'll see you there.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟