Skip to content

Instantly share code, notes, and snippets.

@duganchen
Last active May 14, 2023 20:27
Show Gist options
  • Save duganchen/fd78b16a799be39d3d6c438b2c8a9228 to your computer and use it in GitHub Desktop.
Save duganchen/fd78b16a799be39d3d6c438b2c8a9228 to your computer and use it in GitHub Desktop.
tter.com/WINE prefix manager. For the FISH shell.

Wine Bottler

I've knocked up a system for managing WINE prefixes from the command-line. It's for FISH, because that's what I use, and it's reasonably versatile and maintainable.

Note 1: I'm going to use "prefix" and "bottle" interchangeably.

Note 2: This is for hardcore command-line users, and it's similar to tools like virtualenv and rbenv. Most people would probably want to use Lutris.

Anyway...

First, you want your WINE prefix in your prompt. Edit it:

funced fish_prompt

And add it:

if set -q WINEPREFIX
	echo -n -s (set_color -b 722437 white) "(" (basename $WINEPREFIX) ")" (set_color normal) " "
end

Create a function named "uncork":

funced uncork

And paste the following into it:

function uncork
	if not count $argv > /dev/null
		echo Bottle not specified 2>&1
		return 1
	end

	set bottle $argv[1]

	if not contains $bottle $bottles
		echo Bottle not found 2>&1
		return 1
	end

	if functions --query cork
		cork
	end

	if set --query PATH
		set --global _PATH $PATH
	end

	if set --query WINEDEBUG
		set --global _WINEDEBUG $WINEDEBUG
	end

	if set --query WINEPREFIX
		set --global _WINEPREFIX $WINEPREFIX
	end

	if set --query WINEARCH
		set --global _WINEARCH $WINEARCH
	end

	if set --query WINEDLLOVERRIDES
		set --global _WINEDLLOVERRIDES $WINEDLLOVERRIDES
	end

	function goc
		cd $WINEPREFIX/drive_c
	end

	function cork
		if set --query _WINEPREFIX
			set --global --export  WINEPREFIX $_WINEPREFIX
			set --global --erase _WINEPREFIX
		else
			set --global --erase WINEPREFIX
		end

		if set --query _WINEDEBUG
			set --global --export WINEDEBUG $_WINEDEBUG
			set --global --erase _WINEDEBUG
		else
			set --global --erase WINEDEBUG
		end

		if set --query _WINEARCH
			set --global --export WINEARCH $_WINEARCH
			set --global --erase _WINEARCH
		else
			set --global --erase WINEARCH
		end

		if set --query _WINEDLLOVERRIDES
			set --global --export WINEDLLOVERRIDES $_WINEDLLOVERRIDES
			set --global --erase _WINEDLLOVERRIDES
		else
			set --global --erase WINEDLLOVERRIDES
		end

		if set --query _PATH
			set --global --export PATH $_PATH
			set --global --erase _PATH
		else
			set --global --erase PATH
		end

		functions --erase cork
		functions --erase goc
	end

	switch $argv[1]
		# WINE prefix settings go here
	end
end

Also create a functioned named "update_bottle_completions":

funced update_bottle_completions

It should contain the following:

function update_bottle_completions
	set --global bottles ''
	complete --exclusive --command uncork --arguments "$bottles"
end

Add the following to config.fish:

update_bottle_completions

At this point, we have a general framework set up, but without the following information:

  • the "bottles" global, which will contain a space-separated list of WINE prefix names, is empty
  • the switch block, which sets the environment for each bottle, is empty

We'll fill them in as we add bottles..

Steam Bottle

We'll create a bottle for Steam (64-bit). Edit update_bottle_completions

funced update_bottle_completions

And add the name of the bottle to the "bottles" global, which contains the list of bottles:

function update_bottle_completions
	set --global bottles steam
	complete --exclusive --command uncork --arguments "$bottles"
end

Then we'll add to the switch statement at the bottom of the uncork function:

funced uncork

Add a case for the Steam bottle:

switch $argv[1]
	case steam
		set -gx WINEPREFIX ~/Software/winsteam
		set -gx WINEDEBUG '-all'
		set -gx WINEDLLOVERRIDES 'winemenubuilder.exe=d wine setup.exe'

		# I know that Wolfenstein: The New Order's savegames break if you
		# change the WINE version
		set -gx PATH ~/wine-3.11/bin
end

And update the global list of bottles:

update_bottle_completions

Note that if you just type "uncork" and press TAB, the argument autocompletes as "steam".

Now we can set the WINE prefix, and the other bottle settings, in our environment:

uncork steam

Your prompt will change to show "steam".

Then you can create the WINE prefix:

winecfg

And install Steam:

winetricks steam

To actually start Steam, I just do the following. It works really well with FISH's command-line history:

wine start C:\\Program\ Files\\Steam\\Steam.exe

Or, for games that have crackling audio with out:

env PULSE_LATENCY_MSEC=60 wine start C:\\Program\ Files\ \(x86\)\\Steam\\Steam.exe

When you're done using the bottle, you enter "cork" to bring your environment back to normal.

cork

Falcom Bottle

Let's say I want to create another bottle for Falcom games from GOG. Well, I would edit the list of bottle completions:

funced update_bottle_completions

I would enter it into the list:

function update_bottle_completions
	set --global bottles steam falcom
	complete --exclusive --command uncork --arguments "$bottles"
end

I would update the bottle environment settings:

funced uncork

And I would add the commands for the Falcom bottle:

function bottlerc
	switch $argv[1]
		case steam
			set -gx WINEPREFIX ~/.local/share/wineprefixes/steam
			set -gx WINEDEBUG '-all'
			set -gx WINEDLLOVERRIDES 'winemenubuilder.exe=d wine setup.exe'
		case falcom
			set -gx WINEPREFIX ~/.local/share/wineprefixes/falcom
			set -gx WINEDEBUG '-all'
	end
end

This time, I want a 32-bit prefix, and I want native quartz and amstream overrides to get the cinematics to work:

update_bottle_completions
uncork falcom
env WINEARCH=win32 winecfg
winetricks quartz
winetricks amstream
wineboot -u

Then I install the game, and "uncork" when I'm done.

(That's enough for Ys 1 & 2 Chronicles. For Trails and the Sky and possibly other games, I'd also need xvid).

What Now

Now, I can enter "echo $bottles" to get a list of bottles. Of course, that prints out a space-separated list of bottles:

steam falcom

I can enter either "uncork steam" or "uncork falcom". If I enter "uncork" and press tab, both appear in the autocomplete list.

After activating either, I see it in my terminal prompt. I can enter "goc" to go to its C: drive (this is another command from the old winetricks wiki).

And then I can enter "cork" to bring my environment back to normal.

If I want to add or remove a bottle, I need to update two functions. I find this acceptable, and I haven't come up with an alternative that I like better.

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