Skip to content

Instantly share code, notes, and snippets.

@DeanPDX
Last active April 7, 2024 07:55
Show Gist options
  • Star 40 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DeanPDX/acff533cff0cfbda2761d1e62e8cb1a7 to your computer and use it in GitHub Desktop.
Save DeanPDX/acff533cff0cfbda2761d1e62e8cb1a7 to your computer and use it in GitHub Desktop.

Windows 10 - Using Git Bash With TMUX

Why Not Use WSL?

I tried the WSL and it isn't quite seamless enough for me. I ran in to problems when editing in VSCode and having watchers on my files (ng serve, dotnet watch run, etc.). In addition, I kept running in to problems that only manifest themselves when running in WSL. For example, this issue with doing production builds and the terser plugin has made many a developer rage-quit on using WSL. Just figuring out that it was an issue with the WSL took a lot of time.

That terser plugin issue was never resolved and I ended up having to keep a git bash window open in addition to my WSL console window so I could do production builds. To make matters worse, my npm packages were platform-dependent so I couldn't use the same project folder. So, my procedure was: commit whatever changes to test branch, push to repo, git pull on my "windows" project folder, and do a production build there. It wasn't untenable but it was far from ideal.

Getting Started

  • Install git with git bash.
  • Install msys2. Follow instructions on that page and be sure to close window when it tells you to and reopen to complete setup.

Install TMUX

  • In a msys2 window, use Pacman to install tmux (pacman -S tmux).
  • Copy tmux and msys-event binaries from msys2 bin folder (probably C:\msys64\usr\bin) to git bash bin folder (probably C:\Program Files\Git\usr\bin).
  • Restart your git bash and try tmux command.

If everything went according to plan, you should see tmux running in your git bash:

Tmux Git Bash

Getting NPM Colors / Progress Working

If you run npm commands, you get no progress spinner or colors. The solution is to use winpty (which is installed as part of the git bash shell as it uses msys). Here's an example of an npm install with and without winpty:

winpty vs normal npm command

To always use winpty, edit your bashrc (vim ~/.bashrc) and add the following alias:

alias npm="winpty npm.cmd"
@DeanPDX
Copy link
Author

DeanPDX commented Sep 11, 2019

Screenshot of tmux + git bash:

Tmux Git Bash

@DeanPDX
Copy link
Author

DeanPDX commented Sep 12, 2019

Comparison of npm vs winpty npm:

winpty vs normal npm command

@pangyuteng
Copy link

oh my goodness. thank you for this write up! I am missing tmux so bad at my work pc!!!

@DeanPDX
Copy link
Author

DeanPDX commented Apr 4, 2022

oh my goodness. thank you for this write up! I am missing tmux so bad at my work pc!!!

I'm glad you were able to get some use from this! I made this for myself for future installs and didn't think anybody else would even find it. But I'm glad you did. I'm still using this setup daily and it's working great for me.

@Stephane-Ag
Copy link

Wish it worked. Doesn't for me.

  • I had to run msys2 as an administrator for pacman install to work
  • After moving over the binaries, running tmux did not work for me. Got error: open terminal failed: not a terminal

@DeanPDX
Copy link
Author

DeanPDX commented Jul 23, 2022

@Stephane-Ag interesting. What terminal are you using when you get that error? See also:

https://stackoverflow.com/questions/44891356/using-tmux-through-cygwin-open-terminal-failed-not-a-terminal

@Stephane-Ag
Copy link

@DeanPDX Thanks for the link. I was using git bash through the Windows CMD command prompt.
I reinstalled git bash to use mintty as the emulator and all is good now!

@CengsBlanky
Copy link

I am wondering how to set tmux config file, it should be ~/.tmux.conf, but it did not work, and the <Backspace> and <C-c> can not work properly in tmux

@DeanPDX
Copy link
Author

DeanPDX commented Sep 16, 2022

Hey @CengsBlanky, putting config in ~/.tmux.conf works for me. Here's my ~/.tmux.conf:

# Taken from tmux sensible
# address vim mode switching delay (http://superuser.com/a/252717/65504)
set -s escape-time 0

# tmux messages are displayed for 4 seconds
set -g display-time 4000

# refresh 'status-left' and 'status-right' more often
set -g status-interval 5

# upgrade $TERM
set -g default-terminal "xterm-256color"

# focus events enabled for terminals that support them
set -g focus-events on

# super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on

# Enable mouse
set -g mouse on
# don't rename windows automatically
set-option -g allow-rename off
# enable true color support
set -ga terminal-overrides ',*:Tc'
#set -g default-terminal "screen-256color"
# fix escape for the sake of vim
#set -sg escape-time 0

set -g status-bg "colour141"
set -g status-fg black

# clear bindings
unbind C-b
unbind '"'
unbind %
# nicer ctrl+a prefix
set -g prefix C-a
#bind Space send-prefix

# Attempt to make a terminator-like setup
bind -n C-E split-window -h
bind -n C-S-Left resize-pane -L 3
bind -n C-S-Right resize-pane -R 3
bind -n C-S-Up resize-pane -U 3
bind -n C-S-Down resize-pane -D 3
bind -n C-O split-window -v

# move panes without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
bind r source-file ~/.tmux.conf

As you can see I came from Terminator and have bindings that attempt to make it Terminator-ish. Try set -g prefix C-a as your prefix since C-c isn't working maybe?

@verajosemanuel
Copy link

Tmux only works with the MinTTY version of Git Bash (git-bash.exe). If you usually use the native bash.exe or git-cmd.exe Git prompts, you'll get the error open terminal failed: not a terminal when trying to run Tmux.)

@CengsBlanky
Copy link

Actually, I can open tmux and there is no error showed to me, but it can't work normally, and my ~/.tmux.conf does not take effect,I have been used to tmux on Linux, but I can only use windows10 at office, such a pity...

@DeanPDX
Copy link
Author

DeanPDX commented Sep 17, 2022

@CengsBlanky it's likely you are having some sort of path issue. Have you tried vim ~/.tmux.conf from your Git Bash window where you're running tmux to make sure you're looking at the right user home folder?

@dnoliver
Copy link

dnoliver commented Jan 9, 2023

Works in Windows 11 as well. Thank you!

@DeanPDX
Copy link
Author

DeanPDX commented Jan 9, 2023

Works in Windows 11 as well. Thank you!

Good to know! I haven't made the switch yet.

@mikejw
Copy link

mikejw commented Apr 20, 2023

I'm using Window 10 64bit and instead of copying "msys-event" (which didn't exist), I had to copy across "msys-event-2-1-7.dll" and "msys-event_core-2-1-7.dll" to the Git directory.

@DeanPDX
Copy link
Author

DeanPDX commented Apr 20, 2023

I'm using Window 10 64bit and instead of copying "msys-event" (which didn't exist), I had to copy across "msys-event-2-1-7.dll" and "msys-event_core-2-1-7.dll" to the Git directory.

I haven't had to reinstall in a while so this is probably going to help me next time I do. Thank you.

@bhubr
Copy link

bhubr commented Jul 12, 2023

Worked perfectly for me!
Thanks for putting this together!

@fzzio
Copy link

fzzio commented Jul 17, 2023

I'm running tmux via a custom shell script with a specific location of tmux.conf file, do you know how to tell it to use that specific path?

@DeanPDX
Copy link
Author

DeanPDX commented Jul 17, 2023

Worked perfectly for me! Thanks for putting this together!

Glad it worked!

I'm running tmux via a custom shell script with a specific location of tmux.conf file, do you know how to tell it to use that specific path?

@fzzio I believe you want -f myConfig. From the man pages:

     -f file       Specify an alternative configuration file.  By
                   default, tmux loads the system configuration file
                   from @SYSCONFDIR@/tmux.conf, if present, then looks
                   for a user configuration file at ~/.tmux.conf,
                   $XDG_CONFIG_HOME/tmux/tmux.conf or
                   ~/.config/tmux/tmux.conf.

You could also alias it like so from this answer:

alias tmux='tmux -f "some/location/to/tmux.conf"'

@fzzio
Copy link

fzzio commented Jul 17, 2023

Worked perfectly for me! Thanks for putting this together!

Glad it worked!

I'm running tmux via a custom shell script with a specific location of tmux.conf file, do you know how to tell it to use that specific path?

@fzzio I believe you want -f myConfig. From the man pages:

     -f file       Specify an alternative configuration file.  By
                   default, tmux loads the system configuration file
                   from @SYSCONFDIR@/tmux.conf, if present, then looks
                   for a user configuration file at ~/.tmux.conf,
                   $XDG_CONFIG_HOME/tmux/tmux.conf or
                   ~/.config/tmux/tmux.conf.

You could also alias it like so from this answer:

alias tmux='tmux -f "some/location/to/tmux.conf"'

It works! thanks!

@thangdoan89
Copy link

So glad I found this thread. Thank you so much to put efforts into the work. I will enjoy tmux as much as possible. Cheers 👏👏

@akhilsahuji
Copy link

I have done all the steps according to the plan.
but it is giving error open terminal failed: not a terminal .

@DeanPDX
Copy link
Author

DeanPDX commented Jan 30, 2024

I have done all the steps according to the plan. but it is giving error open terminal failed: not a terminal .

Quoting from this answer:

It sounds like the terminal you're using doesn't support full tty emulation. Clients like mintty (comes with Cygwin---or should, anyway), putty, rxvt for Windows, &c. will handle that. CMD, ConEmu, and Cmder won't.

What terminal are you using?

@akhilsahuji
Copy link

I am using Windows terminal preview with the git bash on Windows 11.

@DeanPDX
Copy link
Author

DeanPDX commented Jan 30, 2024

I am using Windows terminal preview with the git bash on Windows 11.

Switch to a different terminal per the answer I linked to above. I'm using Git Bash (AKA mintty). That should work!

@akhilsahuji
Copy link

Now it works!
Thanks, for the gist and your help.

@vleboutouiller
Copy link

vleboutouiller commented Feb 20, 2024

I had some trouble with my .tmux.conf with syntaxe error or bad value: on

The solution was simply to convert from CRLF to LF !

@DeanPDX
Copy link
Author

DeanPDX commented Feb 20, 2024

The solution was simply to convert from CRLF to LF !

I can't tell you how often CRLF vs LF has caused problems in my career. Glad you figured that out!

@EricYoung37
Copy link

I'm using Window 10 64bit and instead of copying "msys-event" (which didn't exist), I had to copy across "msys-event-2-1-7.dll" and "msys-event_core-2-1-7.dll" to the Git directory.

This worked for me.

@EricYoung37
Copy link

EricYoung37 commented Mar 24, 2024

Hey @CengsBlanky, putting config in ~/.tmux.conf works for me. Here's my ~/.tmux.conf:

# Taken from tmux sensible
# address vim mode switching delay (http://superuser.com/a/252717/65504)
set -s escape-time 0

# tmux messages are displayed for 4 seconds
set -g display-time 4000

# refresh 'status-left' and 'status-right' more often
set -g status-interval 5

# upgrade $TERM
set -g default-terminal "xterm-256color"

# focus events enabled for terminals that support them
set -g focus-events on

# super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on

# Enable mouse
set -g mouse on
# don't rename windows automatically
set-option -g allow-rename off
# enable true color support
set -ga terminal-overrides ',*:Tc'
#set -g default-terminal "screen-256color"
# fix escape for the sake of vim
#set -sg escape-time 0

set -g status-bg "colour141"
set -g status-fg black

# clear bindings
unbind C-b
unbind '"'
unbind %
# nicer ctrl+a prefix
set -g prefix C-a
#bind Space send-prefix

# Attempt to make a terminator-like setup
bind -n C-E split-window -h
bind -n C-S-Left resize-pane -L 3
bind -n C-S-Right resize-pane -R 3
bind -n C-S-Up resize-pane -U 3
bind -n C-S-Down resize-pane -D 3
bind -n C-O split-window -v

# move panes without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
bind r source-file ~/.tmux.conf

As you can see I came from Terminator and have bindings that attempt to make it Terminator-ish. Try set -g prefix C-a as your prefix since C-c isn't working maybe?

Thanks! Really impressive.

For anyone wondering the location to put .tmux.conf, it's C:\Users\<your-username>.

Btw, took me a while to notice that ctrl -b is bound to ctrl -a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment