You should read the Typer Tutorial - User Guide before referring to this summary. Information icons ℹ️ link to the relevant sections of the Typer Tutorial.
- Documentation: https://typer.tiangolo.com
- Source Code: https://github.com/fastapi/typer
#! /usr/bin/env bash | |
set -o errexit -o nounset -o errtrace -o pipefail | |
IFS=$'\n\t' | |
shopt -s nullglob | |
# shellcheck disable=SC2154 | |
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
warn() { [ $# -ge 1 ] && printf >&2 "%s\n" "$*"; } | |
main() { |
#! /usr/bin/env python3 | |
"""Decode or encode the Swedish Robber Language. | |
Proof of concept by traal (Fredrik Mellström). | |
""" | |
import argparse | |
import re | |
import sys |
"""Indent Rich text or renderable.""" | |
from dataclasses import dataclass | |
from typing import Optional | |
from rich.abc import RichRenderable | |
from rich.console import Console, ConsoleOptions, RenderResult | |
from rich.segment import Segment | |
You should read the Typer Tutorial - User Guide before referring to this summary. Information icons ℹ️ link to the relevant sections of the Typer Tutorial.
#! /usr/bin/env python3 | |
"""Read Apple Plist files and output JSON data.""" | |
# https://stackoverflow.com/a/72958435/5201675 | |
import argparse as ap | |
import json | |
import plistlib | |
import sys | |
from typing import IO, Any |
#! /usr/bin/env python3 | |
"""Try to autodetect, parse and display CSV, but fallback to plain text otherwise.""" | |
# Copyright 2024 Fredrik Mellström <https://github.com/harkabeeparolus> | |
# MIT License; SPDX short identifier: MIT | |
import argparse | |
import csv | |
import io |
(Source: ofek/userpath wrong shell #3)
Rant mode ON. 🙀
Just FYI (Unix geek here), I think bash is broken by design when it comes to startup files. This is especially true in big university multiuser Unix installations, which is my own background. For proof, run man bash
, look under the "INVOCATION" section, and prepare to have your mind blown. Compare and contrast this with man zsh
and look under "STARTUP/SHUTDOWN FILES", for a much less insane approach to system and user configuration. IMHO. 👀
Red Hat Enterprise Linux, Ubuntu, and probably other OSes or distros attempt to work around the bash problem by providing clever dotfiles in "/etc/skel" -- these are dotfiles that are copied into a new user's home directories by default when the new user is created. These default dotfiles are supposed to create a complex structure where each user has a ~/.bash_profile (OR ~/.profile on Ubuntu) which always sources the use
# This used to exist in distutils, which is removed since Python 3.12 | |
# https://github.com/pypa/distutils/blob/main/distutils/util.py#L340 | |
def strtobool(val: str) -> bool: | |
"""Convert a string representation of truth to True or False. | |
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', | |
'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. | |
""" | |
val = val.strip().casefold() |