Skip to content

Instantly share code, notes, and snippets.

@jborbely
Created July 1, 2024 23:50
Show Gist options
  • Select an option

  • Save jborbely/d37029ee6162aa640b8ed9384955269f to your computer and use it in GitHub Desktop.

Select an option

Save jborbely/d37029ee6162aa640b8ed9384955269f to your computer and use it in GitHub Desktop.
Install `pipx` to the %LOCALAPPDATA%\Programs\Python\Launcher directory
@echo off
setlocal EnableDelayedExpansion
set pipx_dir=!LOCALAPPDATA!\Programs\Python\Launcher
echo.
if not exist "!pipx_dir!\NUL" mkdir "!pipx_dir!" 2>nul
(echo.@echo off
echo.if "%%1" == "-U" (
echo. setlocal enabledelayedexpansion
echo. echo.Fetching latest pipx tag from GitHub
echo. for /F "delims=: tokens=2" %%%%t in ('curl -s -L --get https^://api.github.com/repos/pypa/pipx/releases/latest ^^^| findstr tag_name'^) do set tag_name=%%%%t
echo. if "^!tag_name^!" == "" echo.Cannot get latest tag from GitHub, try again soon ^& goto^:eof
echo. set latest=^^!tag_name:~2,-2^^!
echo. curl -s -L https://github.com/pypa/pipx/releases/download/^^!latest^^!/pipx.pyz ^> "%%~dp0pipx.pyz"
echo. echo.Installed pipx v^^!latest^^!
echo.^) else (
echo. py "%%~dp0pipx.pyz" %%*
echo.^)
) >"!pipx_dir!\pipx.bat"
setx PIPX_BIN_DIR "!pipx_dir!" 1>nul
setx PIPX_MAN_DIR "!LOCALAPPDATA!\pipx\pipx\man" 1>nul
call "!pipx_dir!\pipx.bat" -U
goto:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment