Skip to content

Instantly share code, notes, and snippets.

@DeanPDX
Last active October 12, 2024 13:54
Show Gist options
  • 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"
@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.

@ericmariot
Copy link

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 !

I spent some minutes trying to figure out why it wasn't working, the same thing happened to me lmao

Also, thanks for the quick setup for TMUX, now I can use it at work :)

@mohnasir-gh
Copy link

Gettting this error after adding following the steps
image

@DeanPDX
Copy link
Author

DeanPDX commented May 21, 2024

@mohnasir-gh did you copy both DLLs to C:/Git/bin/?

@nhanlun
Copy link

nhanlun commented May 22, 2024

Hi, this seems to not work for Windows Terminal. Does anyone suffer the same issue? After copying the msys-event and tmux file, normal git bash can start tmux but not windows Terminal

@akhilsahuji
Copy link

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?

it only works with git-bash.exe

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