{"id":22901255,"url":"https://github.com/mooerslab/tmux-rocks","last_synced_at":"2025-04-01T05:41:55.655Z","repository":{"id":262432153,"uuid":"887217688","full_name":"MooersLab/tmux-rocks","owner":"MooersLab","description":"tmux cheet sheet","archived":false,"fork":false,"pushed_at":"2025-02-25T21:02:14.000Z","size":131,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T21:35:37.764Z","etag":null,"topics":["enhanced-terminal-workflow","panes-inside-terminal","tmux-cheat-sheet"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MooersLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-12T11:18:52.000Z","updated_at":"2025-02-25T21:02:17.000Z","dependencies_parsed_at":"2025-02-07T03:41:35.153Z","dependency_job_id":"01fcf729-44dc-40a6-9ca3-2c8b070b9756","html_url":"https://github.com/MooersLab/tmux-rocks","commit_stats":null,"previous_names":["mooerslab/tmux-rocks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MooersLab%2Ftmux-rocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MooersLab%2Ftmux-rocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MooersLab%2Ftmux-rocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MooersLab%2Ftmux-rocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MooersLab","download_url":"https://codeload.github.com/MooersLab/tmux-rocks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246591782,"owners_count":20801984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["enhanced-terminal-workflow","panes-inside-terminal","tmux-cheat-sheet"],"created_at":"2024-12-14T01:32:32.036Z","updated_at":"2025-04-01T05:41:55.640Z","avatar_url":"https://github.com/MooersLab.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Version](https://img.shields.io/static/v1?label=tmux-rocks\u0026message=0.3\u0026color=brightcolor)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n\n# tmux is easier than it looks\n\nTmux is a terminal multiplexer.\n(If you use *iTerm2*, it also supports terminal multiplexing. See [Mac OS Terminal Tips with *iTerm2*](https://www.youtube.com/watch?v=LcelO7XErdA). \nRegardless, this six-minute video is worth watching; it also revealed some bash functions I did not know about.)\nTmux supports easy navigation between windows and splits a window into multiple panes.\nYour multipaned terminal window gives on-lookers the illusion that you know something about computers.\nA desirable feature is that it is highly programmable using Bash.\n\nI have been aware of `tmux` since my Vim year before switching to Emacs several years ago. \n`tmux` looked confusing to me at the time.\nIt no longer is because Emacs mimics multiplexing with its support for easy splitting of buffers.\nAs a result, I might have been better prepared to pick it up quite quickly.\n\n\n\u003cimg width=\"1711\" alt=\"Screenshot 2024-11-12 at 4 42 51 AM\" src=\"https://github.com/user-attachments/assets/c1bda3ed-2f25-4d84-9256-704d519afc79\"\u003e\n\nI can see how splitting a terminal horizontally and vertically into several panes can be very useful when working on a remote computer.\nIn one pane, you could monitor running jobs; in another, you could edit a script file to prepare the next job or an unrelated job.\n\nWatch this 3-minute video [video](https://www.youtube.com/watch?v=vtB1J_zCv8I) to understand what is possible.\nThe pace is adequate to get a complete picture of what is possible.\nI used Copilot to explore the basics.\nI made this cheat sheet after learning about the features of this plugin because I want to use it in the future.\n\n## Requirements\n\n- git\n- package manager like homebrew\n\n\n\n## Installation\n\n0. If tmux is not installed already, install it with a package manager. It is available in homebrew and Macports on macOS.\n1. Download the tmux.conf file.\n2. Store in the home directory as a hidden file: `~/.tmux.conf`\n3. Install the tmux plugin manager: `git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm`\n4. `brew install reattach-to-user-namespace`\n5. Activate it by entering `tmux source-file ~/.tmux.conf`.\n6. Enter `tmux`  to start.\n7. Enter `C-z c` several times to create new windows. Note the numbered windows in the status bar at the bottom. You can click on a number to switch to the corresponding window.\n\n## The hierarchy: sessions, windows, and panes.\n\n1. *Sessions* are at the same level as a terminal session. Each tab in *iTerm2* could be mapped to a different session. \n2. A *Window* corresponds to a terminal window or a single tab. Windows are numbered and can be renamed. Your single tab in *iTerm2* can be split into ten tmux windows.\n3. A *pane* corresponds to the panes of a split window. The numbering of panes starts at 0; this, too, can be reset. Panes can also be named. The terminal sessions in each pane are independent.\n\nThe coordinates of a pane are \u003csession-name\u003e:#.# \nThe first hashmark is the index number of the window. \nThis number can be substituted with the name of the window.\nThe second hashmark sign is the index number of the pane.\nOnly panes are referred to by their number in this coordinate system.\n\n## Cheatsheet\n\nStart a tmux session by entering `tmux` at the prompt in the terminal.\n\nThe prefix key, by default, is `Crtl + b`. \nThis is not Emacs friendly.\nI remapped this `Contrl-z` (or `C-z` in Emacs shorthand) in the configuration above because I rarely use `C-z` in Emacs.\n\nYou enter `Ctrl + z c` to open a new tmux window.\nThe windows are numbered 0 onward.\nThe numbered sessions are shown in a panel at the bottom of the terminal.\n\nTo navigate to a specific terminal, enter `Ctrl + z` and then the terminal number.\nTo navigate to the next terminal, enter `Ctrl + z` and `n`.\nTo navigate to the previous terminal, enter `Ctrl + z` and `p`.\n\nThe above configuration enables the Shift key + right or left arrow to move between sessions.\n\nA given terminal window can be split into panels.\nEach panel is like an independent terminal session but not numbered.\nTo split the terminal vertically, enter `Ctrl + z` and then `%`.\nTo split the terminal horizontally, enter `Ctrl + z` and then `\"`.\n\nTo kill a pane, enter `Ctrl + z` and then `x`. \nTo kill a window, enter `Ctrl + z` and then `\u0026`. \n\nTo rename a window, enter `Ctrl + z` and a comma.\nTo rename a pane, enter `printf '\\033]2;%s\\033\\\\' \"My Pane\"`\nI made this into a bash function that takes the pane name as an argument.\nThis bash function works (easy-peasy):\n\n```bash\nfunction namePane {\necho \"Name a tmux pane. Takes the name as a string in double-quotes.\"\nif [ $# -lt 1 ]; then\n  echo 1\u003e\u00262 \"$0: not enough arguments\"\n  echo 'Usage1: namePane \"My Pane\"'\n  return 2\nelif [ $# -gt 1 ]; then\n  echo 1\u003e\u00262 \"$0: too many arguments\"\n  echo 'Usage1: namePane \"My Pane\"'\n  return 2\nfi\nprintf '\\033]2;%s\\033\\\\' $1\n}\n```\n\n## Session management\n\n`tmux ls` will list running sessions.\n`tmux attach` will bring a session to the foreground.\n`tmux attach-session \u003csession-name\u003e` will attach a specific session. \n`tmux kill-servers` will kill all sessions.\n\n## Enable Mouse Mode to click and drag the pane borders to resize them\nAdd the following line to your `~/.tmux.conf` file to enable mouse support:\n\n```bash\nset-option -g mouse on\n```\n\nReload the tmux configuration with:\n```bash\ntmux source-file ~/.tmux.conf\n```\nThis works very well!\n\n## Commands in ~/.tmux.conf to resize the pane without using the mouse\n\nEnter Alt (= Meta) and the arrow key repeatedly to change the size of the current pane.\n\n```bash\nbind -n M-Left resize-pane -L 5\nbind -n M-Right resize-pane -R 5\nbind -n M-Up resize-pane -U 5\nbind -n M-Down resize-pane -D 5\n```\n\n## Command in ~/.tmux.conf to ease reloading the .tmux.conf file\n\nAdd the following:\n\n```bash\n# rebind r to ease reloading the config file after editing it\nunbind r\nbind r source-file ~/.tmux.conf\n```\n\nEnter `C-z r` to reload the `~/.tmux.conf` file after editing it.\n\nIf you have https://ohmyz.sh/ installed on macOS with the autocomplete plugin, the autocompletions work in tmux.\nHit the right arrow to accept an autocompletion in the terminal.\nThis makes navigation in the terminal faster than using the Finder.\n\n## Getting help\n\n1. Enter `C-z ?` to get a list of current keybindings.\n2. Enter 'man tmux` to read the manual.\n3. There are books about tmux, but this cheat sheet is a faster way to get started.\n\nYour computer use will be transformed in an hour.\nThere will be no going back to a plain old terminal.\n\n## More advanced config\n![10windowsWeather](https://github.com/user-attachments/assets/adca220d-cf5f-4399-bf3c-526673ac6d7e)\n\nThe above image shows the application of a popular thematic tmux plugin, catppuccin.\nThe status bar had been moved to the top of the window.\nThe ten tmux tabs (one per tmux window) inside one *iTerm2* tab represent ten tmux windows opened in one session.\nThe highlighted tab corresponds to the current window.\nThe four-digit numbers are at the heart of my project management system.\n\n\nThe percentage by the heart is the charge of my failing battery.\nI am not sure what `offline` refers to.\nThe temperature is the outside ambient air temperature.\nPresumably, the location updates as you move from city to city.\n\nTen windows in an *iTerm2* tab is the limit.\nThe numbering scheme is the default that starts from 0.\nThis can be changed to start at one.\nStarting at one is more ergonomic.\nA bash script mentioned below automated the creation of the windows.\n\nThe thematic plugins are complex and do not always work as expected.\nFor example, the `advanced-tmux.conf` (rename .tmux.conf) file is configured to display the session name in the left end of the status bar.\nIt requires the installation of the t`mux-plugin-manager`.\nInstead, we get a smiley face.\nI thought I had installed all the Nerd Font files.\nEnter `C-z r` to get a brief display of the session name while reloading the configuration file.\n\n## Runaway sessions\nSome configs persist despite edits to the `tmux.conf` file and its reloading.\nYou probably have a runaway session.\nEnter this command to kill all tmux servers: `tmux kill-server` and try again with a clean slate.\n\n## Moving between tmux panes and text editor panes\n\nNano, vi, Vim, Neovim, and Emacs (-nw option) run in the terminal.\nPlugins on the tmux side and the editor side are required to switch seamlessly between a pane running a terminal session and a pane occupied by an editor session.\nFor example, the Emacs [tmux-pane package](https://github.com/laishulu/emacs-tmux-pane) enables jumping from the Emacs session in the top tmux pane below to the remote session on the schooner supercomputer in the tmux pane in the figure below by entering C + j (C-j in Emacs convention) or vice versa with C-k.\n\nThe thin gray line is the boundary between the two panes in the image below.\nThe top pane with the Emacs session was enlarged in height compared to the terminal session in the pane at the bottom.\nThe enlargement was made by clicking on the boundary line and dragging it downward with the mouse.\n\n![EmacsSchooner](https://github.com/user-attachments/assets/73035254-ef05-49af-8903-27c74c579d78)\n\n## bashed-tmux  \nThe repo [bashed-tmux](https://github.com/MooersLab/tmux-bashed) has a bash script demonstrating how to automate the launching of about twenty customized tmux panes in five tabs of *iTerm2* and the opening of several files, applications, and a webpage.\nThis can ease the start of your daily routine after you have customized this template file.\n\n## Tab titles\nThe default tab title in *iTerm2* will be tmux. If you have ten *iTerm2* tabs open, this row of `tmux` is not helpful.\nAfter pasting the following code in your .zshrc file, you can change the title of an *iTerm2* tab by entering `tt`. \n\n```zsh\nDISABLE_AUTO_TITLE=\"true\"\ntt () {\n    echo -e \"\\033];$@\\007\"\n}\n```\n\nNow, the bash script mentioned above can be modified to name *iTerm2* tabs.\n\n## Coloring the *iTerm2* tabs\n\nColoring the *iTerm2* tab can also enhance your identification of the tab of interest.\nThe following code assigns a random color for the tab each time a new tab is opened.\nAdd this code to your zshrc file.\n\n```zsh\n# randomly color new tabs.\nPRELINE=\"\\r\\033[A\"\n\nfunction random {\n    echo -e \"\\033]6;1;bg;red;brightness;$((1 + $RANDOM % 255))\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;green;brightness;$((1 + $RANDOM % 255))\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;blue;brightness;$((1 + $RANDOM % 255))\\a\"$PRELINE\n}\n\nfunction color {\n    case $1 in\n    green)\n    echo -e \"\\033]6;1;bg;red;brightness;57\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;green;brightness;197\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;blue;brightness;77\\a\"$PRELINE\n    ;;\n    red)\n    echo -e \"\\033]6;1;bg;red;brightness;270\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;green;brightness;60\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;blue;brightness;83\\a\"$PRELINE\n    ;;\n    orange)\n    echo -e \"\\033]6;1;bg;red;brightness;227\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;green;brightness;143\\a\"$PRELINE\n    echo -e \"\\033]6;1;bg;blue;brightness;10\\a\"$PRELINE\n    ;;\n    *)\n    random\n    esac\n}\n\ncolor\n```\n\nWith `tt` and random coloring enabled, my *iTerm2* terminal appears in the figure below.\nThe tabs labeled zsh are not tmux sessions or were intended tmux sessions,\nbut a bug in my bash function failed to launch a tmux session in the *iTerm2* tab.\n\n\u003cimg width=\"1363\" alt=\"Screenshot 2024-11-30 at 8 12 46 AM\" src=\"https://github.com/user-attachments/assets/569a5ba2-bc12-4d54-80bb-867f6b3fe76e\"\u003e\n\n## Update history\n|Version       |Changes                                                                                               |Date                  |\n|:-------------|:-----------------------------------------------------------------------------------------------------|:--------------------:|\n| Version 0.1  | Initiate project. Added badges, funding, and update table.                                           | 2024 November 12    |\n| Version 0.2  | Added tmux.conf. Changed the prefix key binding.                                                      | 2024 November 13    |\n| Version 0.3  | Added advanced-tmux.conf. Added blurb about rebinding r to ease reloading the config file. Added advanced image. | 2024 November 19    |\n| Version 0.4  | Added notes about multiplexing in *iTerm2*, tab titles, and tab coloring.                                |2024 November 30   |\n| Version 0.4  | Fixed some typos.                                                                                     |2025 February 25   |\n\n## Sources of funding\n\n- NIH: R01 CA242845\n- NIH: R01 AI088011\n- NIH: P30 CA225520 (PI: R. Mannel)\n- NIH: P20 GM103640 and P30 GM145423 (PI: A. West)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooerslab%2Ftmux-rocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmooerslab%2Ftmux-rocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooerslab%2Ftmux-rocks/lists"}