Skip to content

Instantly share code, notes, and snippets.

@rafaelpadovezi
Last active November 27, 2024 16:07
Show Gist options
  • Save rafaelpadovezi/1cfc1026f78255458f5a2ea56291ed23 to your computer and use it in GitHub Desktop.
Save rafaelpadovezi/1cfc1026f78255458f5a2ea56291ed23 to your computer and use it in GitHub Desktop.
Using fish shell with git bash on windows

Using fish shell with git bash on windows

To install fish shell on windows the options are:

  • Cygwin
  • WSL
  • MSYS2

Since git bash is based on MSYS2 it seems a good fit to install fish. The problem is that git bash is a lightweight version of MSYS2 which does not include pacman as a package management, used to install fish.

This OS thread has great suggestions on how to solve this problem including using the full MSYS2. But the best solution for me was this answer by Michael Chen which installs pacman on git bash.

I'll reproduce here his answer with some updates that made it work for me:

Step 1

Download pacman, pacman-mirrors and msys2-keyring from MSYS2's site. Also, for fish to work it is necessary download gcc-libs since uses msys-stdc++-6.dll.

The files are in the zst format. To decompress to tar format download the windows version of the zstd tool and execute these commands from cmd:

zstd.exe -d msys2-keyring-1_20210213-2-any.pkg.tar.zst
zstd.exe -d pacman-mirrors-20210423-2-any.pkg.tar.zst
zstd.exe -d pacman-6.0.0-2-x86_64.pkg.tar.zst
zstd.exe -d gcc-libs-10.2.0-1-x86_64.pkg.tar.zst

Step 2

From git bash root unpack the tar files and restore the packages. It can be necessary to open git bash as admin.

cd /
tar -xvf ~/Downloads/msys2-keyring-1_20210213-2-any.pkg.tar
tar -xvf ~/Downloads/pacman-mirrors-20210423-2-any.pkg.tar
tar -xvf ~/Downloads/pacman-6.0.0-2-x86_64.pkg.tar
tar -xvf ~/Downloads/gcc-libs-10.2.0-1-x86_64.pkg.tar
pacman-key --init
pacman-key --populate msys2
pacman -Syu

Step 3

To sync the metadata files it's needed to run the commands below. This step takes some minutes to finish.

URL=https://github.com/git-for-windows/git-sdk-64/raw/main
cat /etc/package-versions.txt | while read p v; do d=/var/lib/pacman/local/$p-$v;
 mkdir -p $d; for f in desc files install mtree; do curl -sSL "$URL$d/$f" -o $d/$f;
 done; done

Step 4

Now that pacman is installed on git bash, fish can be installed:

pacman -S fish

Step 5

If all is well and working fine edit the file ~/.bashrc adding these lines to make fish as the default shell:

if [ -t 1 ]; then
exec fish
fi
@jasojone
Copy link

everything up to pacman worked I am getting command not found. Also, you have pacman in step 2 before we get it working.

@jasojone
Copy link

you are missing step one from the stack overflow "answer" listed above

@voidptr
Copy link

voidptr commented Aug 14, 2022

The instructions, as written, worked perfectly for me.

@duebbert
Copy link

duebbert commented Oct 5, 2022

This worked with one additional step.

The command pacman -Syu (in Step 2 above) failed with an "incompatible database" error. Running pacman-db-upgrade -r /../ upgraded the database and then I could do the remaining steps. From comment: https://stackoverflow.com/questions/32712133/package-management-in-git-for-windows-git-bash/65204171#comment124229393_65204171

Also, I slightly changed Step 3 to show me what it's doing because it takes a while:

URL=https://github.com/git-for-windows/git-sdk-64/raw/main
cat /etc/package-versions.txt | while read p v; do
  d=/var/lib/pacman/local/$p-$v
  mkdir -p $d
  for f in desc files install mtree; do
    echo "$URL$d/$f" ..... $d/$f
    curl -sSL "$URL$d/$f" -o $d/$f
  done
done

@Raketenphysik
Copy link

Worked right out of the box as described above (Step 1-5).
Make my day, Sir!

@matthewdeanmartin
Copy link

I couldn't get this to work (I got error: keyring is not writable)

The only thing that worked was:

nano /etc/pacman.conf
edit
SigLevel = Required DatabaseOptional
change to
SigLevel = Optional TrustAll

rerun pacman -Sy fish

So far, git-bash and fish is the only combo where pipenv can activate an environment. (cygwin+fish and msys2+fish couldn't activate a venv)

@Lucas-Bravo
Copy link

Lucas-Bravo commented Feb 20, 2023

When running pacman -Syu I get this:

image

Anyone else?

@voidptr
Copy link

voidptr commented May 19, 2023

Something folks might try is making sure that your GitBash is running with administrator privileges. If you don't have admin privileges, your tar step will fail, and then commands won't be found, or things won't be writeable.

I've run all the instructions, exactly as written, on five different devices so far, including today, and it's worked perfectly every time.

@crossgate10
Copy link

Thank you for sharing this, it's helpful :D

@eedrxs
Copy link

eedrxs commented Mar 9, 2024

It works but gives this prompt every time the fish shell initializes:

error: Unable to open shared memory with path '/fish_shmem_197609': Permission denied

But it doesn't do that when you run the Terminal app as administrator or you run the fish command in sudo mode

@voidptr @rafaelpadovezi

@jm355
Copy link

jm355 commented Apr 1, 2024

https://gist.github.com/crossgate10/a67421cfed9c6d11cdfb50e5eac14fc0?permalink_comment_id=4997234#gistcomment-4997234 this worked for me, I had to also start and exit fish one time in the root shell

@piomar123
Copy link

It works for me, although I had an issue while installing, messages containing CreateThread failed for sig and child_copy: data read copy failed. I had to force close the Git Bash window.
I also have an issue like @eedrxs Unable to open shared memory with path '/fish_shmem_4096'

@yusiwen
Copy link

yusiwen commented Oct 15, 2024

What is the step 3 for exactly? Is this needed after executing a 'pacman -Syu'

BTW, these two packages in the latest git-for-windows release's package-versions.txt are 404 in https://github.com/git-for-windows/git-sdk-64/raw/main:
mingw-w64-x86_64-libwinpthread-git 12.0.0.r329.g8f7b5ce36-1
msys2-runtime 3.5.4-1

@phibel
Copy link

phibel commented Nov 27, 2024

Another solution for errors like...

error: Unable to open shared memory with path '/fish_shmem_1062462': Permission denied

...is to set write permission to everyone in the Windows filesystem for folder: C:\Program Files\Git\dev\shm
In this folder fish wants to create the file fish_shmem_1062462 (where 1062462 is your user id)

@piomar123
Copy link

Thanks @phibel it works for me 👍

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