Getting Starting With Tmux Isn't That Scary

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
t bux so I get quite a few questions on stream about hey what's that thing you're doing with all those different windows right there it was that vim is that your terminal emulator but it's actually T MUX so I use T MUX pretty heavily for my whole life I can't I can't I can't work a day without it so I make a quick video breaking down my personal use of T MUX some tips I think that might help you adopt T MUX will break down my configuration 40 MUX and finally I'll show you some of the scripting capabilities of T mugs so first things first if you want to know about tea mugs we must know what it is so man T MUX T MUX is a terminal multiplexer it enables a number of terminals to be created access and controlled from a single screen it may be detach from a screen and continue running in the background and later reattach so what does it all mean for me it's a lot easier just to actually see things in action so let's do that so first things first since T MUX is a terminal multiplexer it kind of goes around your terminal emulator so when you're typing regular commands right T MUX isn't doing anything here how do you tell hey debug there's a command for you actually well you have to send a special command first called a prefix here so you would say prefix and then some command then team X says whoa you're trying to talk to team ox now everyone might have a different prefix the default is controlled B I use controlled backslash so here let me show you what the keys all be typing are so first let's start a brand new team ox team MUX new now we're gonna do is we're gonna just take a look at all the windows so you can say prefix W so at the bottom they can see with control backslash that's my personal prefix key and then W and that just shows me all the windows so we only have one window right now in our main session here so this window right here it's zero and it's unlabeled so let's label this thing how do you label things well simply prefix comma now down here you can see at the bottom it says rename window so I might name this thing called notes lovely now I can open up some notes beautiful there's some notes well maybe I want a different window so if you do prefix e brand new window now if I go prefix W I can look between the two windows and you can always go up and down between the windows with a J and K just vim style here's my notes here's my new window so let's name this new window we already know what that is it's prefix comma so let's name this wind cold open up some code here tap Ewok beautiful so now up here we've got some code and then up here we've got some notes beautiful I keep myself separate but what do you say if what if you want another screen split in this exact place well you could do that as well so T MUX allows you to split your screens similar to how famous the only difference is in vim you're splitting screens in continue to edit T MUX I can split the screen and I can do a totally different action I could be running you know shell commands over here I can be running a server whatever I want so the way you split is the default way you split is prefix percent to do a vertical split prefix double quote and we do a horizontal split see see now we've got these three beautiful little split so you know right here I could do whatever I want right I could just be doing you know a little Cal say ello beautiful okay what I want to do down here on one little aquarium we're living the dream now okay so that's a base my basic usage for it here let me kind of break down I would suggest looking up some sort of like team hooks shortcut key I mean for me truthfully all you really need to know to how to do is just you know you can exit a window kill a pain oh I think you really know how to do is make new windows make new panes move around the panes exit so let's move on to the next thing here so if you're gonna be using T MUX I think there's a couple things that can help you in the beginning making your life a little bit easier so here's three shortcuts that I've added for myself there TNT a and T T so one thing that I personally done is I've actually moved my team of configuration from the default location the default location is just the route your home folder T MUX calm however I don't want anything in my home folder typically so I just put my inside of a dot config folder inside of a t-box folder and then inside dot T Mach stop config so because of this what I call t mocks new or T MUX attached I actually want to point that that's what this F is right here you might not need that and then this you right here is an extra option saying hey yo what's running utf-8 mode I don't want to remember to type these commands the whole time so with alias these first of all T MUX new is already too long team Oaks - you - F tilde slash comma T McTeague Markoff that's way too long so I just alias these two so it's a simple T n for a new session T a to attach an existing one and then I also have a little shortcut to Mighty Mouse config so I can do a little bit faster editing of my config this makes my life I think easier so right now we're not inside of a tea mug so I'll hit TN boom I'm instead of a new team luxe window here watch this I could detach right here I escaped there's no more there's no more window here I can I attached there's no sessions okay this time I really our model guess what though my team accession is still there ta we're back in business here lovely so that's that the ability we were talking about one of the big bonuses of team ox is that if your terminal ever you accidentally exited or it crashes is you can just reattach to it and you'll have all of your different windows and sessions there so with those three little shortcuts in mind let's take a look at my team of configs we can use TT as we just showed before to show it now my config is not crazy it's not too long and truthfully I only made it longer for this video so the first things first we were talking about that prefix key so I a leus my prefix key to control backslash like I said right here so that's what we're doing right here we're saying set globally the prefix to control backslash we also need to make sure that we bind that controlled backslash to the send prefix command this way if we're doing any scripting it'll also know that hit control backslash is for that next we're gonna unbind the default I said the default was control B here is us unbinding that default here so you can do whatever you want I see people do I've seen ctrl a ctrl W whatever feels natural for you me I chose controlled backslash because my then leader key is back slash so I thought it's nice to be like vim backslash team-up control backslash the same way to trigger you know my typical shortcuts or whatever is both on the backslash here now another really helpful thing I find is a quick way to reload your team must config I don't want to have to remember to type T MUX source file and pointing to my T most configuration here so all I did was buying the r2 running source file and we kept ourselves a nice little message saying fresh config so right here if I was to say prefix are you'll see that the bottom it said fresh T MUX config right there now one thing to note about your reloading your T most configuration is that it's not gonna always reload exactly how you expect for instance if you set a color for something with a variable and you remove that variable you're not gonna see that color go back to the default you actually need to restart a new team accession to see that here so sometimes if you noticed settings aren't taking and you've already some resourced your team ox conference probably good they just restart a new session here we need to look at an example of that now another thing for all of the VI users out there is when you're doing when you're in copy mode and T MUX because look at here's copy mode here it's just leader open square bracket I can copy all of this stuff here I want the same key bindings as vim now you can do them I think there's an Emacs ones here too so whatever personal editor using I would explore this another nice thing that I personally like for my vim life is the ability to move around all of my split panes with vim like actions here so let's say I split these windows up right here you know I'm gonna go over here and boom I've got these four windows and now you could always rotate through panes with prefix o see I'm just rotating around but what if I don't want to rotate all the way back around you can always just do prefix and then the vim direction here so you see I'm on this window right here I want to go to this side so all I'm gonna do is just prefix H I want to go down prefix J whoops prefix J there you go so something that I like to use if you know o works pretty okay as well now another thing that you need to have I think is whenever you have multiple panes it's nice to know what pain you're on so if you open it right now you'll notice it's red look when I go to the other side now Green is at the top and red is at the bottom now I want to go to the side Reds at the top greens at the bottom this is just telling me which pane is active so the Reds over here I know it's on this side right now I know it's over here it's down here so I change the personal color of this to just this red color a nice red you can make it whatever you like now this is a good example of something that if you update this configuration let's say I wanted to go back to the default I don't like the red let's go to the default here this is where reloading and configuration will not result with what you expect here so watch this reload the configuration going back and forth we're getting nothing here you know why we set a variable sync here's the pain border style then we removed it we didn't specifically unset that variable the only way to get this actually to work would be we would actually have to kill our session and then restart here so let's open a new team ox window let's split now and now you'll see it's white and green on the default now that only happens when you're actually removing values from your configuration it doesn't happen if you're changing a value so for instance if I was to open that thing back up here and reset it to red this actually should pick up here so boom split it's red I could go over here change this color right here - I don't know it's a nice color for me I might like a nice like I don't know a teal boom let's reload this and I have to first exit the split here but then split Walmart nope nope didn't work let me try again fresh team US config nope not working how I expect depressed depressed here uhm there you go you get it loaded on the split side there we go nice nice yeah so that's that's a nice little thing for your border pain you can control a lot of the style you can change the thickness of it you know I could change this I could change the back I can make us the background instead you know there you go now it's a big thick blue line here I'm gonna keep it with the foreground though okay next is the status bar so I typically don't like a status bar 40 bucks I don't like really a vim status bar I just want a more minimal screen here so I keep mine off however that sounds kind of boring you know for a video here so I added a couple of other settings to show people some things you could do with the status bar here so truthfully if this was a real life that's where my team of config ants we're done that's all I've really typically used right now on my current life I've had more ever move things but that works pretty good for me but here's some extra stuff we added around the status bar for just a little bit of fun so first if I'm gonna have a status bar I gotta be able to toggle it on and off so here I am saying let's bind the key capitalist setting the option of the status on lowercase s set the option for status off so now I can dot trigger it on and off so here we go if I was to say prefix capital let's boom you can see my status bar now my status bar does not looking normal people's status bars because you know I can't do anything normal okay I've got to do things my own way here so I've actually hooked up my status bar to my own personal twitch chat so it always pulls in the last chap message I could actually just add a new fake message over here so watch this off-screen I'm gonna pretend that someone is sending a message here here's how here's a message that someone sent and you should see this update there you go Tommy to toes put up put a P there you go you know mister our week this far beautiful gorgeous so I'll kind of break down how we've done that here so the first two things was just turning the status on and off right you know capital S for off capital S for on gorgeous now I can also move my status bar up and down now I mapped this to I and you I kind of wanted to be J and K however J in case how I move between splits so I just did it I and you above it so it's kind of close to J and K it feels kind of natural to me I'll show you what I'm talking about let's say one with the status bar up sorry wrong key there you go now it's at the top let's move to the bottom there you go lovely okay so how did I get this custom status bar here well you can really customize any part of the status bar there's three sections there's a left side or right side and there's like a current window status section so I turn off the current window status I don't want to know anything about the current window don't show me the current window that bothers me I made the background blue I made the foreground blue if you do try and show me that current window it's gonna be blue on blue and I'm not even bill to see it that's just a personal thing for me now here's the fun stuff right here which is here actually I'll separate these a little bit is first I turn off the right side so you'll notice over here there's nothing on the right side of my ball or below me I only have stuff on the left side so I say hey take the right status make it length zero take its actual value and just make it a blank string this kind of just essentially gets rid of the right status next over here I'm building a let's bless status now the less status can be updated at a regular interval T MUX will continue to call whatever you told to assign that left status and the default interval I believe is 15 I want it to be one because if someone's messaging me a new message I don't want to wait 15 seconds I want to get that and within that second so I changed the status interval of one here and then I said hey take that left length and make it 200 here just extend it out a little bit longer for longer messages here now here's the actual code to set it's really not that crazy at all so this reads the most recent twitch viewer message and displays in the status bar so for me I save all of my twitch chat into a little log file locally called user messages dot log so I've put that right here as a variable I have green as a variable too because you know I just wanted to do that and we have two very basic scripts right here all I'm doing is tail - one on message log right here and then I'm setting out everything after the colon and then right here I'm doing everything before the colon so I'm just replacing I'm saying hey hey find the colon everything after that colon replace that with just a coal hey anything up to the : take that get rid of it so what this does is this grabs the last user this grabs the last message if you look down at our status bar at the bottom this allows us to color the user different from the actual message right here so now here's the actual calling of the script it's actually not too crazy so we're saying let's set globally the status left and first we're saying the foreground is going to be white and then just pass in the valuable of that last message right here so right here this last user is gonna be white and then over here we're saying hey the foreground let's make this part green and then save make that last message right here so you can learn more about this syntax inside the T MUX config whoa inside the T MUX man page but it's it's it's tough it's a pretty it's not the most intuitive syntax but it's not too hard to get around so that's what gives us the ability right here to see these messages let's simulate what it was like if some other people chatted to us for instance right here's just a new message here sheep mine there you go you've said sheep mine and put a little email and boom I can see that at the bottom being pulled in every second lovely so that's kind of the basics that's Mighty Mouse configuration my basic way use it and you know a couple shortcuts let me show you now some fun stuff let's actually write a script in team ox to you know do something fun so what we first should do is over here let's just make a new script so I'm gonna call this first let me hide my status bar whoo so first let's call this fun okay let's make a little shell script here so I'll make a little shebang first I'll say bin duck and then we're gonna build a whole team up session with a bunch of team ox windows and then split some panes and run some programs I use this four times win you know I keep opening up the same setup every day I want notes over here I want some code right here I want some Doc's right here and I want this other shell script running over here well I don't want to every day go new window name it this new window name at this split the window run the scripts you can actually just write a script that does that for you every day so first let's save T MUX new window and what I'm gonna do here is the session that we're gonna create is gonna be called fun right that sounds good to me and let's name our first window ASCII aquarium cuz that's fun can i smoke where iam I think I did it and we're gonna say dash D we're gonna detail this for now or saying don't don't actually make this the main window for now might be able to remove this deep we'll find out next let's make a another brand new window Oh actually let's do let's do some fun stuff here I'm gonna make this one detach it do a bunch of other work and then reattach to it so here let's do that reattaching right now to show you what that's like so over here we'll just save T MUX select window which one we're gonna select well to me the target the target the target window I'm looking for is inside the fun session the ascii query 'm beautiful now what do you wanna do when it's take that team ox window we want to use always utf-8 mode for me I'm going to attach and then the target is fun great so what this does creates a new ASCII aquarium detaches it didn't Reese elects it and then reattach this to it great let's look at what this thing does so first of all I'm in T mantra now let me exit I'm not in team ox try to it attached to a session no sessions here I need to make this script executable so we'll do a quick little you know Plus sex fun and let's run this right now is it fun to or fun that Sh I think it's just fun nope we are making one called fun and I messed up on something here because I know I said new window here's needs to be new session you fool new session s not fun name a window ASCII query MD chats very government's try this one more time dot slash fun now what happened here something happened I'm actually in T MUX right now you can see it's called ASCII Quarian we've done it we've had T MUX create a new session name the window reattach to it very fancy well let's add some more things to it so inside of here let's have some more windows here so I can say T MUX new window and which one do I want to attach to well I'm gonna target the fun window and then what's the name of this window gonna be well first let's say - D - D here says don't don't target don't select this window okay we're creating a new window don't select it don't worry about it right now - D and then let's name it and we'll name one called whether I like to pull up the weather every day you know what I mean not really but let's pretend in this case I do let's make one more here I'll get attached to fun this time let's call this one matrix here so now if I ran that same script again you should see three windows now ask aquarium weather in matrix gorgeous let's keep adding some fun stuff so what happens if you actually wanted to run a script inside one of these well you got to say T MUX sendkeys who do you want sent sendkeys to well I would like to send keys to well inside a fun ask aquarium and what do you want to send to it well let me send ask aquarium and let me just say enter you got to enter in okay so when we open up we're gonna say send keys to fun ask aquarium and then we're actually to reattach that ask aquarium so here let's check this out now dot slash fun boom-boom ask aquarium burnings here are two other windows are doing nothing gorgeous and we're out of team ox again let's add some more things so for the weather one we're gonna target inside a fun ascii query and will target fun weather and we'll just curl wtt rin get that sick way they're going let's do some matrix too so on the matrix one we're gonna run the classic command T matrix you know C matrix times ten let's line up our enters just to be a little OCD so there we go let's run this now dot slash fun boom and we've got three windows running three separate scripts right here okay we got the ask aquarium right here I go to the next window the weather I've got some gorgeous weather here and then BOOM over here we've got a gorgeous T matrix rain raining down on us but we want to take it a step further so let's keep going now remember you can always do prefix : and then run T MUX commands kind of similar to VIMS you know execute mode here so I'm gonna say kill session and let's keep going so what I want to do now in this T matrix window I want to do some more fun stuff right we can have windows but I want to have split panes there okay I want to show people that I'm a real hardcore hacker so we're gonna do is we're gonna say T muck T muck T MUX we're gonna say select window which when they're gonna select we're going to target that fund matrix what are you gonna do to it well I would personally like to say team ox dot split window - eh let's split it horizontally then in that split window notice how he said split window we didn't say dash D here we're actually going to visit this split window run a command but if I did - D here I'm pretty sure you will stay on the same team matrix window so then we're gonna take T MUX San keys who are ascending keys - obviously we're sending keys over to fund matrix similar to before on a specific window and the message we're in ascent is gonna be T matrix but this time let's give it a nice read make sure we enter let's keep our splitting now instead of splitting horizontally let's split vertically this time that sounds nice and let's do something similar here instead of red maybe we'll do it yellow finally let's split one more time cuz I can't stop I need all four windows and yellow we gotta have two blue in here I guess blue feels like the final one gorgeous now with splitting these windows we take a window we split it we split it we split it I want all the windows to be lined up in a 4/4 piece great so I'm gonna say T MUX select layout tile and this will put it in that for grade right here and we're done right now remember cuz the rest of it says grabbed ask aquarium reattach that so let's run this script now and see what we've done I say fun and boom I've got my ASCII query 'm that looks pretty good let's go look at our weather gorgeous weather and then finally ah look at that gorgeousness look at that team looks T matrix beautiful here so that's my personal break that of how I used T MUX maybe I'll make some more videos breaking down some other features but really T MUX it's not that crazy to get started here truthfully I mean I learned like six commands and I used it for three years probably got six commands alone I found it very useful but there's quite a few powerful things you can do so hopefully that helps and we will do more of this in the future later
Info
Channel: Beginbot
Views: 4,247
Rating: 4.9808612 out of 5
Keywords: code, software, linux, vim
Id: Z5sEEbwngd0
Channel Id: undefined
Length: 21min 34sec (1294 seconds)
Published: Wed Jul 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.