Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active November 15, 2024 14:20
Show Gist options
  • Save mariocesar/1b6ab784bde1f1fa47073c96566f6590 to your computer and use it in GitHub Desktop.
Save mariocesar/1b6ab784bde1f1fa47073c96566f6590 to your computer and use it in GitHub Desktop.
Useful oneliners that I often forget. #terminal #python #shell

bash

Get a sha256sum hash for all the given files, similar to GitHub Action hashFiles function.

hashFiles() {
    local files=("$@")
    if [[ ${#files[@]} -eq 0 ]]; then
        echo "Error: No files provided" >&2
        return 1
    }
    sha256sum "${files[@]}" 2>/dev/null | sort | sha256sum | cut -d' ' -f1
}

# Usage example:
CURRENT_HASH=$(hashFiles pyproject.toml poetry.lock)

direnv

List all the available functions in the standard lib:

direnv stdlib | grep -o -E "^(\w+)\(\)"
...
use_node()
use_nodenv()
use_nix()
use_flake()
use_guix()
use_vim()
direnv_version()
on_git_branch()

Git

Tag your commit with the current poetry version plus the git revision, semver compatible.

version="v$(poetry version --short)-rev.$(git rev-parse --short HEAD)"
git tag -a "$version" -m "Release $version"

How can I use SSH for Git on a network that blocks outbound SSH

In Github is easy, just convert this

git clone [email protected]:rtyley/small-test-repo.git

to this

git clone ssh://[email protected]:443/rtyley/small-test-repo.git

You will be able to clone the repository using SSH over port 443, which is typically open on most networks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment