2016 nov-16 grenoble-floss_tmux

22
Tmux + TMuxinator Grenoble FLOSS Meetup, 16 Nov 2016 Mike Bright, @mjbright @mjbright

Upload: michael-bright

Post on 24-Jan-2018

66 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: 2016 nov-16 grenoble-floss_tmux

Tmux+TMuxinator

GrenobleFLOSSMeetup,16Nov2016

MikeBright, @mjbright

@mjbright

Page 2: 2016 nov-16 grenoble-floss_tmux

TMux+TMuxinatorWhatisTmuxRelatedtoolsUsingtmux

invokingfromcommand-linekey-bindingstheStatusbartmuxcommandpromptConfiguration

ExtensionsPluginsToolsandsessionmanagement:Tmuxinator

GNUScreenByobuResources

@mjbright

Page 3: 2016 nov-16 grenoble-floss_tmux

Tmux:AterminalmultiplexerThismeans

youcandetachfromatmuxterminalsessionyoucanreattach,orattachfrommultipleplaces

LikeVNCorRemoteDesktopforterminalsessions

Lostconnectiontoaremoteserverrunningyourtmuxsession?

Yourworkisnotlost,programscontinuetorun

justreconnectsshtotheservertoseerunningtmuxsessions:tmuxlsattachtoasession:tmuxa-t<session>

@mjbright

Page 4: 2016 nov-16 grenoble-floss_tmux

Buttmuxissomuchmore...

Usetmuxlstoseecurrentlyrunningsessions

@mjbright

Page 5: 2016 nov-16 grenoble-floss_tmux

Relatedtools...

-tmux : startedin2011,veryactive

-GNUscreen : mucholder,hasmanysimilarfeatures

Byobu|:|Orginallyawrapperaroundscreen,nowtmuxisitsdefaulttmuxinator|:|Rubygemforcomplextmuxlayouts

@mjbright

Page 6: 2016 nov-16 grenoble-floss_tmux

Basics-Invokingtmuxfromcommand-lineSometmuxcommands

Command

tmuxls : Listcurrentlyrunningsessionstmuxnew : Createanewsessiontmuxnew-n<session> : Createanamedsessiontmuxattach : Attachedtolastactivesessiontmuxattach-t<session> : Attachedtoselectedtarget(e.g.session)tmuxkill-session-t<session> : Deletedselectedsession(careful!)

Sometmuxoptions

Option

-f<conf> : Specifyalternativeuserconffile(else~/.tmux.conf)-L<socket-name> : filenameofserversocketunderTMUX_TMPDIR-S<socket-path> : filepathofserversocket-v : Verboseloggingtotmux-client-PID.log-V : Showtmuxversion@mjbright

Page 7: 2016 nov-16 grenoble-floss_tmux

Basics-Keybindingswithintmux:SessionsOnceattachedtoatmuxsession,thesessioncanbecontrolledbykeycombinationsstartingwithaprefix'C-b'(ctrl-B)bydefault.

Binding(C-b+...)

? : Help!!$ : Renamethecurrentsession(asseenby'tmuxls')d : DetachfromthecurrentsessionC-z : Suspendthetmuxclientf : Searchforwindowcontainingtext!<Space> : Applynextlayout

@mjbright

Page 8: 2016 nov-16 grenoble-floss_tmux

Basics-Keybindingswithintmux:WindowsOnceattachedtoatmuxsession,thesessioncanbecontrolledbykeycombinationsstartingwithaprefix'C-b'(ctrl-B)bydefault.

Binding(C-b+...)

, : Renamethecurrentwindowc : Createandmovetoanewwindown : movetothenextwindowp : movetothepreviouswindowl : movetothelastvisitedwindowi : showinfoaboutthecurrentwindow[0-9a-z] : Gotospecfiedwindow

@mjbright

Page 9: 2016 nov-16 grenoble-floss_tmux

Basics-MoreKeybindingswithintmux:PanesBinding(C-b+...)

z : Showcurrentpaneasfull-screen(C-ztoexit)" : Splitthecurrentpanevertically% : Splitthecurrentpanehorizontally[ : Gointocopymode,allowstoscrollinpane(C-ctoexit)o : Cyclethroughpanesincurrentwindowq : Brieflydisplaypanenumbersx : Killthecurrentpane! : Breakcurrentpaneoutofwindowintoanewone

@mjbright

Page 10: 2016 nov-16 grenoble-floss_tmux

Basics-ThetmuxstatusbarThestatusbarshowscustomizableinformationaboutthecurrentsession

Bydefaultthisdisplays

currentuser,ipaddress,session-name('0'below)Alistofwindow-names(current-*,withcurrentcommand)

Throughtmux.conf(seelater)wecancustomizeaswewish,forexample:

Notethatifawindowisinfull-screenmodethen'Z'isappendedtothatwindowname

@mjbright

Page 11: 2016 nov-16 grenoble-floss_tmux

More-KeybindingswithintmuxBinding(C-b+...)

s : Selectanewsessionforthecurrentclient(changesession)t : Showthecurrenttimew : Chooseawindowm :Markthecurrentpane(select-pane-m)M : Unmarkthecurrentpane{ : Swapthecurrentpanewiththepreviouspane} : Swapthecurrentpanewiththenextpane

@mjbright

Page 12: 2016 nov-16 grenoble-floss_tmux

More-UsingthetmuxcommandpromptBinding(C-b+...)

:setwsynchronize-panes

:Sendkeyboardinputsimultaneoustoallpanesofcurrentwindow

@mjbright

Page 13: 2016 nov-16 grenoble-floss_tmux

Configuration-Thetmux.conffile(1)Thereareasetoftmuxcommandsaccessiblethroughctrl-B:whichcanalsobeusedinaconfigfile(default~/.tmux.conf)tosettmuxdefaultbehavioursasyouwish.

#SetCtrl-brasshortcuttoreloadthisconfig:bindrsource-file~/.tmux.conf

#Renameterminals:set-gset-titlesonset-gset-titles-string'^#(whoami::#h::#(curlipecho.net/plain;echo)'

#Statusbarcusto:#set-gstatus-utf8onset-gstatus-bgblueset-gstatus-fgwhiteset-gstatus-interval5set-gstatus-left-length90set-gstatus-right-length60set-gstatus-left"#[fg=Green]#(whoami)#[fg=white]::#[fg=blue]\#(hostname-s)#[fg=white]::##[fg=yellow]#(curlipecho.net/plain;echo)"

set-gstatus-justifyleftset-gstatus-right'#[fg=Cyan]#S#[fg=white]%a%d%b%R'

@mjbright

Page 14: 2016 nov-16 grenoble-floss_tmux

Configuration-Thetmux.conffile(2)usectrl-barrows-Panenavigationwithvim-bindings:

unbind-keyj;bind-keyjselect-pane-Dunbind-keyk;bind-keykselect-pane-Uunbind-keyh;bind-keyhselect-pane-Lunbind-keyl;bind-keylselect-pane-R

@mjbright

Page 15: 2016 nov-16 grenoble-floss_tmux

Pluginstmux-pluginsOfficialtmuxplugins

@mjbright

Page 16: 2016 nov-16 grenoble-floss_tmux

ToolsandsessionmanagementTools

powerlineStatuslinepluginforvim,andprovidesstatuslinesandpromptsforseveralotherapplicationsincludingtmux

tmux-cssh TMUXwitha"ClusterSSH"-likebehaviour

tmuxifierTmuxifyyourTmux.Powerfulsession,window&panemanagementforTmux.

tmuxinator Managecomplextmuxsessionseasilytmuxomatic Intelligenttmuxsessionmanagementtmuxp tmuxsessionmanagerandpythonlibrary

@mjbright

Page 17: 2016 nov-16 grenoble-floss_tmux

Toolsandsessionmanagement:TmuxinatorTmuxinatorallowstoeasilymanagecomplextmuxsessionswithmultiplewindows,paneswithaspecifiedlayoutallspecifiedinaYAMLfile:

project_name:8paneswindows:

shell:layout:a506,379x84,0,0{125x84,0,0[125x26,0,0,4,125x31,0,27,83,125x25,0,59,82],125x84,126,0[125x42,126,0,79,125x41,126,43,86],127x84,252,0[127x27,252,0,80,127x30,252,28,84,127x25,252,59,85]}panes:

-bannerpane1-bannerpane2-bannerpane3-bannerpane4-bannerpane5-bannerpane6-bannerpane7-bannerpane8

@mjbright

Page 18: 2016 nov-16 grenoble-floss_tmux

Toolsandsessionmanagement:Tmuxinator-2windows:

work:layout:tiledpanes:

-messages:-exec~/z/bin/Deployed/ssh_tunnel_b10.shwork-sudotail-f/var/log/messages-shell:-exec~/z/bin/Deployed/ssh_tunnel_b10.shwork-exec~/z/bin/Deployed/ssh_tunnel_b10.shwork

b1machines:layout:tiledpanes:

-b0g1_logs:-exec~/z/bin/Deployed/ssh_tunnel_b10.shb0g1-banner$(hostname)-uptime;ipa|grep10.3.222-cd/var/log-sudotail-fsyslog-b1g1_logs:-exec~/z/bin/Deployed/ssh_tunnel_b10.shb1g1-banner$(hostname)

@mjbright

Page 19: 2016 nov-16 grenoble-floss_tmux

Toolsandsessionmanagement:Tmuxinator-3name:perfsroot:~/windows:

perfs:layout:main-horizontalroot:~/tmppanes:

-htop:htop-sensors:~/z/bin/Deployed/perf_monitor_CPUtrend.sh

@mjbright

Page 20: 2016 nov-16 grenoble-floss_tmux

GNUScreen

https://www.gnu.org/software/screen/

Screenisafull-screenwindowmanagerthatmultiplexesaphysicalterminalbetweenseveralprocesses,typicallyinteractiveshells.

WhilsttmuxisamoreactiveprojectScreenalreadyhasmanyofthesamefeatures,suchas:

sessioncontinuesindetachedmodewhennoclientisconnectedhasaprefixkeyforenteringcommands

ItusesCtrl+Athough(tmuxchosetobedifferent)multiplewindowsabilitytolistwindowsorcreatethemonthefly,switchwindowsabilitytosplitwindowshorizontallyorvertically...

IfGNUScreenworksforyou...keepit...@mjbright

Page 21: 2016 nov-16 grenoble-floss_tmux

Byobu

http://byobu.co/

ByobuisaGPLv3opensourcetext-basedwindowmanagerandterminalmultiplexer.

Itwasoriginallydesignedtoprovideelegantenhancementstotheotherwisefunctional,plain,practicalGNUScreen,fortheUbuntuserverdistribution.

Byobunowincludesanenhancedprofiles,convenientkeybindings,configurationutilities,andtoggle-ablesystemstatusnotificationsforboththeGNUScreenwindowmanagerandthemoremodernTmuxterminalmultiplexer,andworksonmostLinux,BSD,andMacdistributions.

@mjbright

Page 22: 2016 nov-16 grenoble-floss_tmux

ResourcesTmux

homepagehttps://tmux.github.io/sourcehttps://github.com/tmux/tmuxawesome-tmux:awesome-tmuxOfficialtmux-plugins:tmux-plugins

TMuxinator:https://github.com/tmuxinator/tmuxinator

GNUScreen:https://www.gnu.org/software/screen/

Byobu:http://byobu.co/

@mjbright