TMux: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
 
(34 intermediate revisions by the same user not shown)
Line 1: Line 1:
{|class='wikitable' style='width:100%;margin:-11px 0 6px 0'
|valign='top'|
<code>tmux</code> is an open-source terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time.
<code>tmux</code> is an open-source terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time.
|}
==Shortcuts==
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
Shortcuts
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='text'>
tmux ls                    » Session list
tmux a      -t 0…9        » Session attach to
tmux attach -t 0…9        » Session attach to
Ctrl + a →  d              » Session detach from
Ctrl + a →  r              » Session reload config
</syntaxhighlight>


==Cheat Sheet==
|valign='top' style='width:50%'|
{|
<syntaxhighlight style='margin:3px 0' lang='text'>
| valign="top" |
Ctrl + a →  Ctrl + s      » Session save
'''misc:'''
Ctrl + a →  Ctrl + r      » Session restore
───────────────────────────────────────────────────────
Ctrl + z                  » Send job background
'''Ctrl + a''' :       » Enter command mode
bg/jobs                    » Background job list
bg 0…9                    » Bring to foreground
</syntaxhighlight>
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='text'>
Ctrl + a :             » Enter command mode
Win  + Nav                » Move  to Monitor
Win  + Tab                » Focus to Monitor
</syntaxhighlight>


| valign="top" |
|valign='top'|
'''misc:'''
<syntaxhighlight style='margin:3px 0' lang='text'>
  ───────────────────────────────────────────────────────
Ctrl + a → ?             » List key bindings
'''Ctrl + a''' ?       » List key bindings


~    + .                  » Kill SSH Session
</syntaxhighlight>
|-
|-
| colspan="2" |
!scope='col' style='text-align:left'|session
----
!scope='col' style='text-align:left'|window
|-
|-
| valign="top" |
|valign='top'|
'''session:'''
<syntaxhighlight style='margin:3px 0' lang='text'>
───────────────────────────────────────────────────────
Ctrl + a → w              » Session and Window Preview
'''Ctrl + a''' ‎w        » Session and Window Preview
Ctrl + a → (             » Move to previous session
'''Ctrl + a''' (       » Move to previous session
Ctrl + a → )             » Move to next session
'''Ctrl + a''' )       » Move to next session
Ctrl + a → d              » Detach from session
'''Ctrl + a''' ‎d        » Detach from session
Ctrl + a → s              » Show all sessions
'''Ctrl + a''' ‎s        » Show all sessions
Ctrl + a → $             » Rename session
'''Ctrl + a''' $       » Rename session
Ctrl + a →  ʘ             »  
'''Ctrl + a''' ‎ʘ        »
Ctrl + a →  ʘ              »  
  '''Ctrl + a''' → ʘ       »
</syntaxhighlight>
 
| valign="top" |
'''window:'''
───────────────────────────────────────────────────────
'''Ctrl + a''' → ‎n        » Next window
'''Ctrl + a''' ‎w        » List windows
  '''Ctrl + a''' → ‎p        » Previous window
'''Ctrl + a''' → ‎c        » Create a new window
'''Ctrl + a''' → ‎&        » Close active window
'''Ctrl + a''' → ‎,        » Rename active window
'''Ctrl + a''' → ‎1        » Toggle last active window
'''Ctrl + a''' → 0…9      » Switch to window by number


|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='text'>
Ctrl + a →  n              » Next window
Ctrl + a →  w              » List windows
Ctrl + a →  p              » Previous window
Ctrl + a →  c              » Create a new window
Ctrl + a →  &              » Close active window
Ctrl + a →  ,              » Rename active window
Ctrl + a →  1              » Toggle last active window
Ctrl + a → 0…9            » Switch to window by number
</syntaxhighlight>
|-
|-
| colspan="2" |
!scope='col' style='text-align:left'|pane
----
!scope='col' style='text-align:left'|pane
|-
|-
| valign="top" |
|valign='top'|
'''pane:'''
<syntaxhighlight style='margin:3px 0' lang='text'>
───────────────────────────────────────────────────────
Ctrl + a → x              » Close active pane
'''Ctrl + a''' ‎x        » Close active pane
Ctrl + a → q              » Show pane numbers
'''Ctrl + a''' ‎q        » Show pane numbers
Ctrl + a → q + 0…9       » Switch pane by number
'''Ctrl + a''' ‎q + 0…9 » Switch pane by number
Ctrl + a → |             » Split pane vertically
'''Ctrl + a''' |       » Split pane vertically
Ctrl + a → -             » Split pane horizontally
'''Ctrl + a''' -       » Split pane horizontally
Ctrl + a → ;               » Toggle last active pane
'''Ctrl + a''' → ;       » Toggle last active pane
Ctrl + a → z               » Toggle active pane zoom
'''Ctrl + a''' → z       » Toggle active pane zoom
Ctrl + a → {               » Move the active pane left
'''Ctrl + a''' → {       » Move the active pane left
Ctrl + a → }               » Move the active pane right
'''Ctrl + a''' }       » Move the active pane right
Ctrl + a → !               » Convert pane into a window
'''Ctrl + a''' → !       » Convert pane into a window
</syntaxhighlight>
 
| valign="top" |
'''pane:'''
───────────────────────────────────────────────────────
'''Ctrl + a''' → ‎Ctrl + ← » Pane width  resize
'''Ctrl + a''' → ‎Ctrl + → » Pane width  resize
'''Ctrl + a''' → ‎Ctrl + ↑ » Pane height resize
'''Ctrl + a''' → ‎Ctrl + ↓ » Pane height resize
'''Ctrl + a''' → ‎↑        » Switch to pane up
'''Ctrl + a''' → ↓        » Switch to pane down
'''Ctrl + a''' → o        » Switch to next pane
'''Ctrl + a''' → ←        » Switch to pane left
'''Ctrl + a''' → →        » Switch to pane right
'''Ctrl + a''' → '''‎Spacebar''' » Toggle between pane layouts


|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='text'>
Ctrl + a →  Ctrl + ←      » Pane width  resize
Ctrl + a →  Ctrl + →      » Pane width  resize
Ctrl + a →  Ctrl + ↑      » Pane height resize
Ctrl + a →  Ctrl + ↓      » Pane height resize
Ctrl + a → ↑              » Switch to pane up
Ctrl + a → ↓              » Switch to pane down
Ctrl + a → o              » Switch to next pane
Ctrl + a → ←              » Switch to pane left
Ctrl + a → →              » Switch to pane right
Ctrl + a → Spacebar        » Toggle between pane layouts
</syntaxhighlight>
|-
|-
| colspan="2" |
!scope='col' style='text-align:left'|vi copy
----
!scope='col' style='text-align:left'|vi copy
|-
|-
| valign="top" |
|valign='top'|
'''vi copy:'''
<syntaxhighlight style='margin:3px 0' lang='text'>
───────────────────────────────────────────────────────
Ctrl + a → [               » Enter copy mode
'''Ctrl + a''' [       » Enter copy mode
Ctrl + a → PgUp            » Copy mode & scroll one page up
'''Ctrl + a''' '''‎PgUp'''    » Copy mode & scroll one page up
        → g               » Go to top line
          → g       » Go to top line
        → G               » Go to bottom line
          → G       » Go to bottom line
        → h               » Move cursor left
          → h       » Move cursor left
        → j               » Move cursor down
          → j       » Move cursor down
        → k               » Move cursor up
          → k       » Move cursor up
        → l               » Move cursor right
          → l       » Move cursor right
        → w               » Move cursor forward one word
          → w       » Move cursor forward one word
        → b               » Move cursor backward one word
          → b       » Move cursor backward one word
</syntaxhighlight>
 
|valign='top'|
| valign="top" |
<syntaxhighlight style='margin:3px 0' lang='text'>
'''vi copy:'''
        → q               » Quit mode
───────────────────────────────────────────────────────
        ↑              » Scroll up
          → q       » Quit mode
        → ↓               » Scroll down
          ‎↑        » Scroll up
        → /               » Search forward
          → ↓       » Scroll down
        → ?               » Search backward
          → /       » Search forward
        → Spacebar       » Start selection
          → ?       » Search backward
        → Esc             » Clear selection
          '''Spacebar''' » Start selection
        → n               » Next keyword occurrence
          '''Esc'''      » Clear selection
        → N               » Previous keyword occurrence
          → n       » Next keyword occurrence
Ctrl + a → ]               » Paste contents of buffer_0
          → N       » Previous keyword occurrence
</syntaxhighlight>
'''Ctrl + a''' ]       » Paste contents of buffer_0
 
|}
|}


==Installation==
==Installation==
<source lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Installation
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
sudo apt install tmux
sudo apt install tmux
sudo apt install powerline
sudo apt install powerline
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
git clone https://github.com/tmux-plugins/tmux-yank ~/.tmux/plugins/tmux-yank
git clone https://github.com/tmux-plugins/tmux-battery ~/.tmux/plugins/tmux-battery
git clone https://github.com/tmux-plugins/tmux-sensible ~/.tmux/plugins/tmux-sensible
git clone https://github.com/tmux-plugins/tmux-resurrect ~/.tmux/plugins/tmux-resurrect
git clone https://github.com/tmux-plugins/tmux-continuum ~/.tmux/plugins/tmux-continuum
git clone https://github.com/tmux-plugins/tmux-prefix-highlight ~/.tmux/plugins/tmux-prefix-highlight


cat << EOF | tee ${HOME}/.tmux.conf >/dev/null
cat << EOF | tee ${HOME}/.tmux.conf >/dev/null
Line 139: Line 173:
run '~/.tmux/plugins/tpm/tpm'
run '~/.tmux/plugins/tpm/tpm'
EOF
EOF
</source>
</syntaxhighlight>
|}


== Powerline ==
== Powerline ==
<source lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Powerline
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
sudo apt install build-essential libssl-dev libffi-dev libgmp3-dev libpq-dev
sudo apt install build-essential libssl-dev libffi-dev libgmp3-dev libpq-dev
sudo apt install python-is-python3 python3-dev python3-pip python3-venv
sudo apt install python-is-python3 python3-dev python3-pip python3-venv
Line 149: Line 189:
pip install wheel
pip install wheel
pip install powerline-status
pip install powerline-status
</source>
</syntaxhighlight>
----
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# powerline font installation:
# powerline font installation:
# ────────────────────────────
# ────────────────────────────
Line 157: Line 198:
./fonts/install.sh && rm -rf fonts/
./fonts/install.sh && rm -rf fonts/
ls -lah ${HOME}/.local/share/fonts/
ls -lah ${HOME}/.local/share/fonts/
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# powerline daemon config:
# powerline daemon config:
# ────────────────────────
# ────────────────────────
Line 165: Line 207:
cp -r ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/config_files/* ${HOME}/.config/powerline/
cp -r ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/config_files/* ${HOME}/.config/powerline/
powerline-daemon --replace
powerline-daemon --replace
</source>
</syntaxhighlight>
----
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
echo -E "$(jq '(.ext.shell|select(.theme=="default")).theme="default_leftonly"'\
echo -E "$(jq '(.ext.shell|select(.theme=="default")).theme="default_leftonly"'\
  ${HOME}/.config/powerline/config.json)">\
  ${HOME}/.config/powerline/config.json)">\
Line 175: Line 218:
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json)">\
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json)">\
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json
</source>
</syntaxhighlight>
 
|-
=== Powerline » Vim ===
!scope='col' style='text-align:left'|Powerline » Vim
----
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# ~/.vimrc
# ~/.vimrc
set rtp+=${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/vim/
set rtp+=${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/vim/


set laststatus=2
set laststatus=2
</source>
</syntaxhighlight>
 
|-
=== Powerline » Bash ===
!scope='col' style='text-align:left'|Powerline » Bash
----
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# powerline configuration
# powerline configuration
if [ -f ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/bash/powerline.sh ]; then
if [ -f ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/bash/powerline.sh ]; then
Line 196: Line 241:
   source ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/bash/powerline.sh
   source ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/bash/powerline.sh
fi
fi
</source>
</syntaxhighlight>
 
|-
=== Powerline » TMux ===
!scope='col' style='text-align:left'|Powerline » TMux
----
|-
<source lang="bash">
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# ~/.tmux.conf
# ~/.tmux.conf
set -g default-terminal "screen-256color"
set -g default-terminal "screen-256color"
source "${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/tmux/powerline.conf"
source "${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/tmux/powerline.conf"
</source>
</syntaxhighlight>
|-
!scope='col' style='text-align:left'|Powerline » Code
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
# Debian
echo -E "$(jq '."terminal.integrated.fontFamily"="Source Code Pro for Powerline"'\
${HOME}/.config/Code/User/settings.json)">\
${HOME}/.config/Code/User/settings.json
 
# MacOS
echo -E "$(jq '."terminal.integrated.fontFamily"="Source Code Pro for Powerline"'\
${HOME}/Library/Application Support/Code/User/settings.json)">\
${HOME}/Library/Application Support/Code/User/settings.json
</syntaxhighlight>
|}


==Knowledge==
==Knowledge==
{|
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
|valign="top"|
!scope='col' style='text-align:left' colspan='3'|
tmux ls
Knowledge
tmux new -s my_session
|-
tmux attach-session -t 0
|valign='top' style='width:33%'|
tmux attach-session -t my_session
<syntaxhighlight style='margin:3px 0' lang='bash'>
tmux ls
tmux new -s my_session
tmux attach-session -t 0
tmux attach-session -t my_session
   
   
'''Ctrl + a''' % » Split pane horizontally
Ctrl + a % » Split pane horizontally
'''Ctrl + a''' " » Split pane vertically
Ctrl + a " » Split pane vertically
'''Ctrl + a''' x » Close current pane
Ctrl + a x » Close current pane
</syntaxhighlight>


|valign="top"|
|valign='top' style='width:34%'|
'''Ctrl + a''' c » Create a new window
<syntaxhighlight style='margin:3px 0' lang='bash'>
'''Ctrl + a''' w » Choose window from a list
Ctrl + a c » Create a new window
'''Ctrl + a''' 0 » Switch to window by number
Ctrl + a w » Choose window from a list
'''Ctrl + a''' , » Rename the current window
Ctrl + a 0 » Switch to window by number
Ctrl + a , » Rename the current window
   
   
'''Ctrl + a''' o » Go to the next pane
Ctrl + a o » Go to the next pane
'''Ctrl + a''' ; » Toggle between pane
Ctrl + a ; » Toggle between pane
'''Ctrl + a''' d » Detach the session
Ctrl + a d » Detach the session
</syntaxhighlight>


|valign="top"|
|valign='top' style='width:33%'|
tmux ls
<syntaxhighlight style='margin:3px 0' lang='bash'>
tmux kill-server
tmux ls
tmux list-sessions
tmux kill-server
tmux kill-session -a
tmux list-sessions
tmux kill-session -t {index}
tmux kill-session -a
tmux kill-session -t {index}
   
   
pkill -f tmux
pkill -f tmux
ps aux | grep tmux
ps aux | grep tmux
 
</syntaxhighlight>
|-
|valign='top' colspan='3'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
python3 -V|perl -pe '($_)=/([0-9]+([.][0-9]+)+)/'
python3 -V|perl -pe '($_)=/([0-9]+[.][0-9]+)/'
python3 -V|perl -pe '($_)=/([0-9]+)/
</syntaxhighlight>
|-
|-
|colspan="3"|
|valign='top' colspan='3'|
----
<syntaxhighlight style='margin:3px 0' lang='bash'>
alias extractor=$'perl -pe \'if(($v)=/([0-9]+([.][0-9]+)+)/){print"$v\n";exit}$_=""\''
mvn --version|extractor|perl -pe '($_)=/([0-9]+[.][0-9]+)/'
mvn --version|extractor|perl -pe '($_)=/([0-9]+)/'
mvn --version|extractor
</syntaxhighlight>
|-
|-
|valign="top" colspan="3"|
|valign='top' colspan='3'|
<source lang='bash'>
<syntaxhighlight style='margin:3px 0' lang='bash'>
GIT_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'git' 2>&1)"
GIT_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'git' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${GIT_INSTALL_STATUS}" -eq 'installed' ]];then
if [[ ! $? -eq 0 ]]||[[ ! "${GIT_INSTALL_STATUS}" -eq 'installed' ]];then
Line 258: Line 340:
     printf 'sudo apt install --yes \033[0;31mpowerline \033[0m\n';exit 1
     printf 'sudo apt install --yes \033[0;31mpowerline \033[0m\n';exit 1
fi
fi
</source>
</syntaxhighlight>
 
|-
<source lang='bash'>
|valign='top' colspan='3'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
PYTHON3_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'python3' 2>&1)"
PYTHON3_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'python3' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${PYTHON3_INSTALL_STATUS}" -eq 'installed' ]];then
if [[ ! $? -eq 0 ]]||[[ ! "${PYTHON3_INSTALL_STATUS}" -eq 'installed' ]];then
Line 275: Line 358:
     printf 'sudo apt install --yes \033[0;31mpython3-venv \033[0m\n';exit 1
     printf 'sudo apt install --yes \033[0;31mpython3-venv \033[0m\n';exit 1
fi
fi
</source>
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|-
|valign="top"|
|valign='top'|
python3 -m site --user-site
<syntaxhighlight style='margin:3px 0' lang='PowerShell'>
python3 -m site | grep packages
python3 -m site --user-site
python3 -m sysconfig | grep packages
python3 -m site | grep packages
python3 -m sysconfig | grep packages
</syntaxhighlight>


|valign="top" colspan="2"|
|valign="top" colspan="2"|
'''windows 11'''
<syntaxhighlight style='margin:3px 0' lang='PowerShell'>
C:\> py -c "import sysconfig; print(sysconfig.get_path('purelib'))"
# windows 11
python3 -c "import sysconfig; print(sysconfig.get_path('purelib'))"
C:\> py -c "import sysconfig; print(sysconfig.get_path('purelib'))"
 
python3 -c "import sysconfig; print(sysconfig.get_path('purelib'))"
|-
</syntaxhighlight>
|colspan="3"|
----
|-
|-
|valign="top" colspan="3"|
|valign='top' colspan='3'|
<source lang="bash">
<syntaxhighlight style='margin:3px 0' lang='bash'>
python3 -m venv ~/.venv/powerline --prompt="Powerline"
python3 -m venv ~/.venv/powerline --prompt="Powerline"
# source .venv/bin/activate
# source .venv/bin/activate
# (Powerline) $
# (Powerline) $
</source>
</syntaxhighlight>
 
|-
|-
|colspan="3"|
|valign='top' colspan='3'|
----
<syntaxhighlight style='margin:3px 0' lang='PowerShell'>
|-
|valign="top" colspan="3"|
<source lang="PowerShell">
python -m venv ~/.venv/powerline --prompt="Powerline"
python -m venv ~/.venv/powerline --prompt="Powerline"
# .venv\Scripts\activate
# .venv\Scripts\activate
# (Powerline) PS>
# (Powerline) PS>
</source>
</syntaxhighlight>
 
|-
|-
|colspan="3"|
|valign='top' colspan='3'|
----
<syntaxhighlight style='margin:3px 0' lang='bash'>
uptime | cut -f 4-5 -d ' ' | cut -f 1 -d ','
</syntaxhighlight>
|-
|-
|valign="top" colspan="3"|
|valign='top' colspan='3'|
 
<syntaxhighlight style='margin:3px 0' lang='bash'>
uptime | cut -f 4-5 -d ' ' | cut -f 1 -d ','
 
|-
|colspan="3"|
----
|-
|valign="top" colspan="3"|
<source lang="bash">
cat ${HOME}/.config/powerline/config.json|jq '.ext.shell.theme'
cat ${HOME}/.config/powerline/config.json|jq '.ext.shell.theme'
cat ${HOME}/.config/powerline/themes/shell/default_leftonly.json|\
cat ${HOME}/.config/powerline/themes/shell/default_leftonly.json|\
jq '.segments.left[].function'
jq '.segments.left[].function'
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top' colspan='3'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
jq '.ext.shell|select(.theme=="default")' ${HOME}/.config/powerline/config.json
jq '.ext.shell|select(.theme=="default")' ${HOME}/.config/powerline/config.json
jq '.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")'\
jq '.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")'\
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json
</source>
</syntaxhighlight>
 
|-
|-
|colspan="3"|
|valign='top' colspan='3'|
----
<syntaxhighlight style='margin:3px 0' lang='bash'>
|-
|valign="top" colspan="3"|
<source lang="bash">
cat ${HOME}/.config/powerline/config.json |\
cat ${HOME}/.config/powerline/config.json |\
  jq '.ext.shell|select(.theme=="default")|.theme="default_leftonly"'
  jq '.ext.shell|select(.theme=="default")|.theme="default_leftonly"'
Line 349: Line 414:
cat ${HOME}/.config/powerline/themes/shell/default_leftonly.json |\
cat ${HOME}/.config/powerline/themes/shell/default_leftonly.json |\
  jq '.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")|.args={"status_colors":true}'
  jq '.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")|.args={"status_colors":true}'
</source>
</syntaxhighlight>
 
|-
<source lang="bash">
|valign='top' colspan='3'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
jq '(.ext.shell|select(.theme=="default")).theme="default_leftonly"'\
jq '(.ext.shell|select(.theme=="default")).theme="default_leftonly"'\
  ${HOME}/.config/powerline/config.json
  ${HOME}/.config/powerline/config.json
Line 357: Line 423:
jq '(.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")).args={"status_colors":true}'\
jq '(.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")).args={"status_colors":true}'\
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json
  ${HOME}/.config/powerline/themes/shell/default_leftonly.json
</source>
</syntaxhighlight>
 
|}
|}


==References==
==References==
{|
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
| valign="top" |
!scope='col' style='text-align:left' colspan='3'|
References
|-
|valign='top' style='width:33%'|
* [https://tmuxcheatsheet.com/ TMux » Cheat Sheet & Quick Reference]
* [https://tmuxcheatsheet.com/ TMux » Cheat Sheet & Quick Reference]
* [https://stackoverflow.com/questions/1298066/how-can-i-check-if-a-package-is-installed-and-install-it-if-not/54239534#54239534 Check if a package is installed or not]
* [https://stackoverflow.com/questions/1298066/how-can-i-check-if-a-package-is-installed-and-install-it-if-not/54239534#54239534 Check if a package is installed or not]
Line 375: Line 443:
* [[Bash]]
* [[Bash]]


| valign="top" |
|valign='top' style='width:34%'|
* [https://stackoverflow.com/questions/122327/ Find Out Python <code>site-packages</code> Directory]
* [https://stackoverflow.com/questions/122327/ Find Out Python <code>site-packages</code> Directory]
* [https://www.ricalo.com/blog/install-powerline-virtualenv/ Powerline in a Python virtual environment]
* [https://www.ricalo.com/blog/install-powerline-virtualenv/ Powerline in a Python virtual environment]
Line 387: Line 455:
* [[JQ Tool]]
* [[JQ Tool]]


| valign="top" |
|valign='top' style='width:33%'|
* [https://stackoverflow.com/questions/45017773/ TMux » <code>set -g</code>, <code>set -ga</code>, <code>setw -g</code> vs. <code>set-option -g</code>]
* [https://stackoverflow.com/questions/81272/ Move the cursor word by word in the OS X Terminal]
* [https://linuxhandbook.com/run-process-background/ Running Linux Process in Background & Foreground]
* [https://unix.stackexchange.com/questions/214192/ <code>rpm --querytags</code> & <code>rpm -q --queryformat</code>]
* [https://unix.stackexchange.com/questions/52144/ TMux » Eclipsed colorized output of ls]
* [https://towardsdatascience.com/how-to-boost-10x-productivity-with-tmux-ead3d3d452f9 Boost 10X Productivity with Tmux]
* [https://devguide.python.org/versions/ Status of Python Versions]
* [https://pkgs.alpinelinux.org/packages?name=powerline-*&branch=edge Alpine Linux Powerline]
* [https://pkgs.alpinelinux.org/packages?name=powerline-*&branch=edge Alpine Linux Powerline]
* [https://wiki.archlinux.org/title/Powerline ArchLinux Powerline]
* [https://wiki.archlinux.org/title/Powerline ArchLinux Powerline]
* [https://stackoverflow.com/questions/2032747/ <code>.vimrc</code> Comments]
|-
|valign='top'|
* [https://github.com/tmux/tmux/wiki TMux » Wiki]


|valign='top'|
|valign='top'|
|-
|-
| colspan="3" |
|valign='top'|
----
* [[Linux User Creation]]
|-
* [[AwesomeWM]]
| valign="top" |
* [[Neovim]]
* [[PyEnv]]
* [[7Zip]]
* [[Zsh]]
* [[Zip]]
* [[Tar]]


| valign="top" |
|valign='top'|


| valign="top" |
|valign='top'|


|}
|}

Latest revision as of 13:05, 16 January 2026

tmux is an open-source terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time.

Shortcuts

Shortcuts

tmux ls                    » Session list
tmux a      -t 0…9         » Session attach to
tmux attach -t 0…9         » Session attach to
Ctrl + a →  d              » Session detach from
Ctrl + a →  r              » Session reload config
Ctrl + a →  Ctrl + s       » Session save
Ctrl + a →  Ctrl + r       » Session restore
Ctrl + z                   » Send job background
bg/jobs                    » Background job list
bg 0…9                     » Bring to foreground
Ctrl + a  →  :             » Enter command mode
Win  + Nav                 » Move  to Monitor
Win  + Tab                 » Focus to Monitor
Ctrl  + a →  ?             » List key bindings

~     + .                  » Kill SSH Session
session window
Ctrl + a →  w              » Session and Window Preview
Ctrl + a →  (              » Move to previous session
Ctrl + a →  )              » Move to next session
Ctrl + a →  d              » Detach from session
Ctrl + a →  s              » Show all sessions
Ctrl + a →  $              » Rename session
Ctrl + a →  ʘ              » 
Ctrl + a →  ʘ              »
Ctrl + a →  n              » Next window
Ctrl + a →  w              » List windows
Ctrl + a →  p              » Previous window
Ctrl + a →  c              » Create a new window
Ctrl + a →  &              » Close active window
Ctrl + a →  ,              » Rename active window
Ctrl + a →  1              » Toggle last active window
Ctrl + a → 0…9             » Switch to window by number
pane pane
Ctrl + a →  x              » Close active pane
Ctrl + a →  q              » Show pane numbers
Ctrl + a →  q + 0…9        » Switch pane by number
Ctrl + a →  |              » Split pane vertically
Ctrl + a →  -              » Split pane horizontally
Ctrl + a → ;               » Toggle last active pane
Ctrl + a → z               » Toggle active pane zoom
Ctrl + a → {               » Move the active pane left
Ctrl + a → }               » Move the active pane right
Ctrl + a → !               » Convert pane into a window
Ctrl + a →  Ctrl + ←       » Pane width  resize
Ctrl + a →  Ctrl + →       » Pane width  resize
Ctrl + a →  Ctrl + ↑       » Pane height resize
Ctrl + a →  Ctrl + ↓       » Pane height resize
Ctrl + a → ↑               » Switch to pane up
Ctrl + a → ↓               » Switch to pane down
Ctrl + a → o               » Switch to next pane
Ctrl + a → ←               » Switch to pane left
Ctrl + a → →               » Switch to pane right
Ctrl + a → Spacebar        » Toggle between pane layouts
vi copy vi copy
Ctrl + a → [               » Enter copy mode
Ctrl + a → PgUp            » Copy mode & scroll one page up
         → g               » Go to top line
         → G               » Go to bottom line
         → h               » Move cursor left
         → j               » Move cursor down
         → k               » Move cursor up
         → l               » Move cursor right
         → w               » Move cursor forward one word
         → b               » Move cursor backward one word
         → q               » Quit mode
         → ↑               » Scroll up
         → ↓               » Scroll down
         → /               » Search forward
         → ?               » Search backward
         → Spacebar        » Start selection
         → Esc             » Clear selection
         → n               » Next keyword occurrence
         → N               » Previous keyword occurrence
Ctrl + a → ]               » Paste contents of buffer_0

Installation

Installation

sudo apt install tmux
sudo apt install powerline
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
git clone https://github.com/tmux-plugins/tmux-yank ~/.tmux/plugins/tmux-yank
git clone https://github.com/tmux-plugins/tmux-battery ~/.tmux/plugins/tmux-battery
git clone https://github.com/tmux-plugins/tmux-sensible ~/.tmux/plugins/tmux-sensible
git clone https://github.com/tmux-plugins/tmux-resurrect ~/.tmux/plugins/tmux-resurrect
git clone https://github.com/tmux-plugins/tmux-continuum ~/.tmux/plugins/tmux-continuum
git clone https://github.com/tmux-plugins/tmux-prefix-highlight ~/.tmux/plugins/tmux-prefix-highlight

cat << EOF | tee ${HOME}/.tmux.conf >/dev/null
set -g base-index 1
# remap prefix from 'c-b' to 'c-a'
unbind C-b
set-option -g prefix c-a
bind-key c-a send-prefix

set -g default-terminal 'screen-256color'
set -g history-limit 10000

# window/pane split
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# list of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'

# initialize tmux plugin manager
run '~/.tmux/plugins/tpm/tpm'
EOF

Powerline

Powerline

sudo apt install build-essential libssl-dev libffi-dev libgmp3-dev libpq-dev
sudo apt install python-is-python3 python3-dev python3-pip python3-venv
python3 -m venv ~/.venv/powerline --prompt="Powerline"
source ~/.venv/powerline/bin/activate
pip install wheel
pip install powerline-status
# powerline font installation:
# ────────────────────────────
git clone https://github.com/powerline/fonts.git --depth=1
./fonts/install.sh && rm -rf fonts/
ls -lah ${HOME}/.local/share/fonts/
# powerline daemon config:
# ────────────────────────
mkdir -p ${HOME}/.config/powerline
cp -r ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/config_files/* ${HOME}/.config/powerline/
powerline-daemon --replace
echo -E "$(jq '(.ext.shell|select(.theme=="default")).theme="default_leftonly"'\
 ${HOME}/.config/powerline/config.json)">\
 ${HOME}/.config/powerline/config.json

echo -E "$(jq '(.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")).args={"status_colors":true}'\
 ${HOME}/.config/powerline/themes/shell/default_leftonly.json)">\
 ${HOME}/.config/powerline/themes/shell/default_leftonly.json
Powerline » Vim
# ~/.vimrc
set rtp+=${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/vim/

set laststatus=2
Powerline » Bash
# powerline configuration
if [ -f ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/bash/powerline.sh ]; then
  powerline-daemon -q
  POWERLINE_BASH_CONTINUATION=1
  POWERLINE_BASH_SELECT=1
  source ${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/bash/powerline.sh
fi
Powerline » TMux
# ~/.tmux.conf
set -g default-terminal "screen-256color"
source "${HOME}/.venv/powerline/lib/python3.10/site-packages/powerline/bindings/tmux/powerline.conf"
Powerline » Code
# Debian
echo -E "$(jq '."terminal.integrated.fontFamily"="Source Code Pro for Powerline"'\
 ${HOME}/.config/Code/User/settings.json)">\
 ${HOME}/.config/Code/User/settings.json

# MacOS
echo -E "$(jq '."terminal.integrated.fontFamily"="Source Code Pro for Powerline"'\
 ${HOME}/Library/Application Support/Code/User/settings.json)">\
 ${HOME}/Library/Application Support/Code/User/settings.json

Knowledge

Knowledge

tmux ls
tmux new -s my_session
tmux attach-session -t 0
tmux attach-session -t my_session
 
Ctrl + a % » Split pane horizontally
Ctrl + a " » Split pane vertically
Ctrl + a x » Close current pane
Ctrl + a c » Create a new window
Ctrl + a w » Choose window from a list
Ctrl + a 0 » Switch to window by number
Ctrl + a , » Rename the current window
 
Ctrl + a o » Go to the next pane
Ctrl + a ; » Toggle between pane
Ctrl + a d » Detach the session
tmux ls
tmux kill-server
tmux list-sessions
tmux kill-session -a
tmux kill-session -t {index}
 
pkill -f tmux
ps aux | grep tmux
python3 -V|perl -pe '($_)=/([0-9]+([.][0-9]+)+)/'
python3 -V|perl -pe '($_)=/([0-9]+[.][0-9]+)/'
python3 -V|perl -pe '($_)=/([0-9]+)/
alias extractor=$'perl -pe \'if(($v)=/([0-9]+([.][0-9]+)+)/){print"$v\n";exit}$_=""\''
mvn --version|extractor|perl -pe '($_)=/([0-9]+[.][0-9]+)/'
mvn --version|extractor|perl -pe '($_)=/([0-9]+)/'
mvn --version|extractor
GIT_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'git' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${GIT_INSTALL_STATUS}" -eq 'installed' ]];then
    printf 'sudo apt install --yes \033[0;31mgit \033[0m\n';exit 1
fi

TMUX_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'tmux' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${TMUX_INSTALL_STATUS}" -eq 'installed' ]];then
    printf 'sudo apt install --yes \033[0;31mtmux \033[0m\n';exit 1
fi

POWERLINE_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'powerline' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${POWERLINE_INSTALL_STATUS}" -eq 'installed' ]];then
    printf 'sudo apt install --yes \033[0;31mpowerline \033[0m\n';exit 1
fi
PYTHON3_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'python3' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${PYTHON3_INSTALL_STATUS}" -eq 'installed' ]];then
    printf 'sudo apt install --yes \033[0;31mpython3 \033[0m\n';exit 1
fi

PYTHON3_PIP_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'python3-pip' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${PYTHON3_PIP_INSTALL_STATUS}" -eq 'installed' ]];then
    printf 'sudo apt install --yes \033[0;31mpython3-pip \033[0m\n';exit 1
fi

PYTHON3_VENV_INSTALL_STATUS="$(dpkg-query -W --showformat='${db:Status-Status}' 'python3-venv' 2>&1)"
if [[ ! $? -eq 0 ]]||[[ ! "${PYTHON3_VENV_INSTALL_STATUS}" -eq 'installed' ]];then
    printf 'sudo apt install --yes \033[0;31mpython3-venv \033[0m\n';exit 1
fi
python3 -m site --user-site
python3 -m site | grep packages
python3 -m sysconfig | grep packages
# windows 11
C:\> py -c "import sysconfig; print(sysconfig.get_path('purelib'))"
python3 -c "import sysconfig; print(sysconfig.get_path('purelib'))"
python3 -m venv ~/.venv/powerline --prompt="Powerline"
# source .venv/bin/activate
# (Powerline) $
python -m venv ~/.venv/powerline --prompt="Powerline"
# .venv\Scripts\activate
# (Powerline) PS>
uptime | cut -f 4-5 -d ' ' | cut -f 1 -d ','
cat ${HOME}/.config/powerline/config.json|jq '.ext.shell.theme'
cat ${HOME}/.config/powerline/themes/shell/default_leftonly.json|\
jq '.segments.left[].function'
jq '.ext.shell|select(.theme=="default")' ${HOME}/.config/powerline/config.json
jq '.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")'\
 ${HOME}/.config/powerline/themes/shell/default_leftonly.json
cat ${HOME}/.config/powerline/config.json |\
 jq '.ext.shell|select(.theme=="default")|.theme="default_leftonly"'

cat ${HOME}/.config/powerline/themes/shell/default_leftonly.json |\
 jq '.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")|.args={"status_colors":true}'
jq '(.ext.shell|select(.theme=="default")).theme="default_leftonly"'\
 ${HOME}/.config/powerline/config.json

jq '(.segments.left[]|select(.function=="powerline.segments.common.vcs.branch")).args={"status_colors":true}'\
 ${HOME}/.config/powerline/themes/shell/default_leftonly.json

References

References