2023-10-05 18:12:37 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-10-16 19:07:40 +02:00
|
|
|
# This is a noteish on how to pre-commit on SteamOS. Or it was, but then I
|
|
|
|
# decided that pipx is a thing that I could put into the venv more reasonably
|
|
|
|
# and feel less bad about abusing it O:)
|
2023-10-05 18:12:37 +02:00
|
|
|
set -x
|
|
|
|
|
2023-10-16 19:10:50 +02:00
|
|
|
# In case there is some valid reason to use different Python
|
|
|
|
PYTHON=python3
|
|
|
|
|
2023-10-05 18:12:37 +02:00
|
|
|
cd ~
|
|
|
|
mkdir -p ~/.local/bin/
|
2023-10-06 06:55:06 +02:00
|
|
|
|
2023-10-16 19:10:50 +02:00
|
|
|
# My pre-commit configuration expects to find a pypy which SteamOS doesn't
|
|
|
|
# come with and it was the original motivation for this script, so it's
|
|
|
|
# difficult to start changing anything here. If you don't want it, just
|
|
|
|
# install pypy or symlink it in path yourself!
|
2024-06-06 19:59:19 +02:00
|
|
|
if ! hash pypy 2> /dev/null; then
|
2023-10-06 06:55:06 +02:00
|
|
|
ln -sf /usr/bin/python ~/.local/bin/pypy
|
|
|
|
fi
|
2024-06-06 19:59:19 +02:00
|
|
|
if ! hash pypy3 2> /dev/null; then
|
2023-10-06 06:55:06 +02:00
|
|
|
ln -sf /usr/bin/python3 ~/.local/bin/pypy3
|
|
|
|
fi
|
2023-10-05 18:12:37 +02:00
|
|
|
|
|
|
|
mkdir -p ~/venv
|
2023-10-16 19:10:50 +02:00
|
|
|
$PYTHON -m venv ~/venv
|
2023-10-05 18:12:37 +02:00
|
|
|
. ~/venv/bin/activate
|
2023-10-16 19:10:50 +02:00
|
|
|
$PYTHON -m pip install pip --upgrade
|
|
|
|
$PYTHON -m pip install pipx --upgrade
|
|
|
|
$PYTHON -m pipx install pre-commit
|
|
|
|
$PYTHON -m pipx upgrade-all
|
2023-10-16 18:49:20 +02:00
|
|
|
|
2023-10-16 19:07:40 +02:00
|
|
|
# As this script claims to be pre-commit on SteamOS, let's do it properly all
|
|
|
|
# the way!
|
|
|
|
mkdir -p ~/.git-template
|
|
|
|
git config --global init.templatedir ~/.git-template
|
|
|
|
pre-commit init-templatedir ~/.git-template
|
|
|
|
|
2023-10-05 18:12:37 +02:00
|
|
|
# Removes duplicates from $PATH. Copied from https://unix.stackexchange.com/a/14896
|
|
|
|
PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}')
|
|
|
|
printf "Remember to apply the following somewhere appropiate:\nPATH=$PATH"
|
|
|
|
|
|
|
|
set +x
|