Skip to content

Instantly share code, notes, and snippets.

@maotovisk
Created March 23, 2025 11:51
Show Gist options
  • Save maotovisk/d2ba13fb7e277c680d57f08d75da72bd to your computer and use it in GitHub Desktop.
Save maotovisk/d2ba13fb7e277c680d57f08d75da72bd to your computer and use it in GitHub Desktop.
Replace notepad.exe from wineprefix with native editor.
#!/bin/bash
if [ -z "$1" ]; then
echo "[INFO] No prefix path argument passed"
WINEPREFIX="$HOME/.local/share/wineprefixes/osu-wineprefix"
echo "[INFO] Using default prefix path: $WINEPREFIX"
else
WINEPREFIX="$1"
echo "[INFO] Using custom prefix path: $WINEPREFIX"
fi
echo "[INFO] Checking if WINEPREFIX path is valid..."
if [ ! -d "$WINEPREFIX" ]; then
echo "[ERROR] osu! wine prefix not found!"
exit
fi
echo "[INFO] osu! wine prefix found, deleting all notepad.exe files inside it..."
script=$(cat <<'EOF'
#!/bin/bash
win_path="$*"
if [[ "$win_path" =~ ^[A-Za-z]:\\ ]]; then
drive_letter=$(echo "$win_path" | cut -d ':' -f 1 | tr 'A-Z' 'a-z')
wine_path=$(echo "$win_path" | sed -E 's#^[A-Za-z]:\\##; s#\\#/#g')
unix_path="${WINEPREFIX:-$HOME/.wine}/dosdevices/${drive_letter}:/${wine_path}"
else
unix_path=$(echo "$win_path" | sed -E 's#^Z:/##; s#\\#/#g')
fi
# gedit "$unix_path" &
xdg-open "$unix_path" &
# code "$unix_path" &
exit 0
EOF
)
find "$WINEPREFIX" -name notepad.exe -exec rm -f {} \;
echo "$script" > "$WINEPREFIX/drive_c/windows/notepad.exe"
chmod +x "$WINEPREFIX/drive_c/windows/notepad.exe"
# other locations that notepad.exe might be called from
ln -sf "$WINEPREFIX/drive_c/windows/notepad.exe" "$WINEPREFIX/drive_c/windows/system32/notepad.exe"
ln -sf "$WINEPREFIX/drive_c/windows/notepad.exe" "$WINEPREFIX/drive_c/windows/syswow64/notepad.exe"
if [ ! -f "$WINEPREFIX/drive_c/windows/notepad.exe" ]; then
echo "[ERROR] Failed to replace notepad.exe"
exit
fi
echo "[INFO] notepad.exe replaced with script"
echo "[INFO] Done"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment