Last active
April 2, 2025 03:11
-
-
Save shmerl/2b6944099212e6595d27b97885a90037 to your computer and use it in GitHub Desktop.
For creating a new Wine prefix without mime associations clutter and shell folder symlinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Notes: | |
# | |
# Requires WINEPREFIX to be set | |
# Uses wine_env.sh which sets the environment (without it will use default wine) | |
# relies on ripgrep (rg) | |
# | |
source "$(dirname ${BASH_SOURCE[0]})/wine_env.sh" | |
# to prevent mime associations on initial wine calls before setting is disabled | |
WINEDLLOVERRIDES='winemenubuilder.exe=d' | |
if [[ "$WINEPREFIX" == "" ]]; then | |
echo "error: No path for prefix specified! Aborting" | |
exit 1 | |
fi | |
function assert() { | |
local rc=$1 | |
local message="$2" | |
if ((rc != 0)); then | |
echo $message | |
exit $rc | |
fi | |
} | |
function ensure_command() { | |
command -v "$1" &>/dev/null | |
if (($? != 0)); then | |
echo "error: ${1} is required to operate, aborting!" | |
exit 1 | |
fi | |
} | |
# ensure ripgrep | |
ensure_command rg | |
function create_prefix() { | |
echo "Creating new Wine prefix at ${WINEPREFIX}" | |
wine winecfg /v win11 &> /dev/null | |
assert $? "error: Failed to create the initial prefix!" | |
echo "Disabling mime associations to prevent clutter..." | |
wine reg add 'HKEY_CURRENT_USER\Software\Wine\FileOpenAssociations' /v "Enable" /d "N" /f &> /dev/null | |
assert $? "error: Failed to disable mime associations!" | |
} | |
# turns shell folders into normal directories if they were symlinks | |
function normalize_shell_folders() { | |
local folders_key='HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' | |
local folders=( | |
"Desktop" # Desktop | |
"Personal" # Documents | |
"My Pictures" # Pictures | |
"My Music" # Music | |
"My Videos" # Videos | |
"Templates" # Templates | |
'{374DE290-123F-4565-9164-39C4925E467B}' # Downloads | |
) | |
for folder in "${folders[@]}"; do | |
echo "=== processing shell folder ===============" | |
local folder_path=$(wine reg query "$folders_key" /v "$folder" 2> /dev/null | rg '\s+REG_SZ\s+(.*)' --only-matching --replace '$1') | |
# drop windows style end of line from the value just in case | |
folder_path="${folder_path%%[[:cntrl:]]}" | |
if [[ "$folder_path" == "" ]]; then | |
echo "warn: no value found for folder ${folder}" | |
continue | |
fi | |
local system_path=$(wine winepath -u "$folder_path" 2> /dev/null) | |
# drop windows style end of line from the value just in case | |
system_path="${system_path%%[[:cntrl:]]}" | |
if [[ "$system_path" == "" ]]; then | |
echo "warn: could not retrieve system path for folder path ${folder_path}" | |
continue | |
fi | |
echo "folder path: ${folder_path}" | |
echo "system path: ${system_path}" | |
if [[ -L "$system_path" ]]; then | |
echo "${system_path} is a symbolic link" | |
echo "unlinking and creating a normal directory" | |
unlink "$system_path" | |
mkdir -v "$system_path" | |
else | |
echo "${system_path} is already not a symbolic link, ignoring" | |
fi | |
done | |
} | |
create_prefix | |
normalize_shell_folders |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment