Skip to content

Instantly share code, notes, and snippets.

@crossgate10
Forked from rafaelpadovezi/git-bash-fish.md
Last active June 5, 2024 02:13
Show Gist options
  • Save crossgate10/a67421cfed9c6d11cdfb50e5eac14fc0 to your computer and use it in GitHub Desktop.
Save crossgate10/a67421cfed9c6d11cdfb50e5eac14fc0 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
    echo "$URL$d/$f" ..... $d/$f
    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
@crossgate10
Copy link
Author

crossgate10 commented Mar 22, 2024

if got error Unable to open shared memory with path '/fish_shmem_197609': Permission denied
try to use below command in the root git bash

pacman -R fish
pacman -S fish

from https://gist.github.com/rafaelpadovezi/1cfc1026f78255458f5a2ea56291ed23?permalink_comment_id=4979093#gistcomment-4979093

@crossgate10
Copy link
Author

if gor error duplicated database entry
try to use below command in the root git bash

ls /var/lib/pacman/local/ | grep <pkgname>
rm -rf /var/lib/pacman/local/<old_package>

from

@crossgate10
Copy link
Author

if gor error like this

error: failed to commit transaction (conflicting files)
station: /usr/bin/station exists in filesystem

try to use below command in the root git bash

pacman -S package-name --overwrite '*'

from https://unix.stackexchange.com/questions/490949/pacman-filename-exists-in-filesystem

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