Useful snippets

    Bash. check if a file exists

    Tue 03. March 2026 | 2026-03-03

    Check if prepush is activated or not

    lsprepush() {
      if [[ -f ".git/hooks/pre-push" ]]; then
        echo ".git/hooks/pre-push was found:"
        echo "pre-push is activated"
      else
        if [[ -f ".git/hooks/pre-push.sample" ]]; then
          echo ".git/hooks/pre-push was not found:"
          echo "but .git/hooks/pre-push.sample was found:"
          echo "pre-push is deactivated"
        else
          echo "Hmmmmm"
        fi
      fi
    }

    git hooks

    Wed 25. February 2026 | 2026-02-25

    To activate pre-push, rename .git/hooks/pre-push.sample to .git/hooks/pre-push


    Example script:

    branch_name=$(git symbolic-ref HEAD 2>/dev/null)
    
    echo "$branch_name"
    
    if [ "$branch_name" != "refs/heads/min-branch" ]; then
      echo "You can't push this branch." # also prevents git push --force-with-lease
      exit 1
    fi
    
    exit 0

    should work given that this command:

    git symbolic-ref HEAD 2>/dev/null

    gives: refs/heads/min-branch

    and:

    git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3

    gives min-branch

    UV python

    Thu 22. January 2026 | 2026-01-22

    uv python install <version>
    uv init

    Set correct python version in .python-version

    (re)-build venv

    uv venv

    Updates .venv files

    Activate venv environment

    source .venv/bin/activate
    deactivate

    Install dependencies from requirements.txt

    uv pip install -r requirements.txt