Last active
November 12, 2025 13:50
-
-
Save balupton/c481c2d5beb7f914b7bdbf8aaff1b6f8 to your computer and use it in GitHub Desktop.
@dhh's bash argument parsing example <https://x.com/dhh/status/1988152033900122174> now amplified with Dorothy's bash conventions and utilities. Dorothy, a dotfile ecosystem, can be found at <https://dorothy.bevry.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| function dhh_example() ( | |
| if [[ -n ${DOROTHY-} ]]; then | |
| source "$DOROTHY/sources/bash.bash" | |
| else | |
| eval "$(curl -fsSL 'https://raw.githubusercontent.com/bevry/dorothy/HEAD/sources/bash.bash')" | |
| eval "$(curl -fsSL 'https://raw.githubusercontent.com/bevry/dorothy/HEAD/sources/styles.bash')" | |
| fi | |
| function help { | |
| __print_help "$@" <<-EOF || return $? | |
| ABOUT: | |
| Example for @dhh | |
| USAGE: | |
| dhh-example [...options] | |
| OPTIONS: | |
| --[no-]cache | |
| Do not use cached downloads, redownload everything. | |
| --[no-]boot-offer | |
| Do not offer to set up Dorothy to run at boot/login. | |
| --[no-]local-source | |
| Use local source files instead of downloading from the internet. | |
| --dev | |
| Use the development version of Omarchy Installer. | |
| EOF | |
| return 22 # EINVAL 22 Invalid argument | |
| } | |
| local item option_cache='yes' option_boot_offer='yes' option_local_source='no' OMARCHY_INSTALLER_REF | |
| while [[ $# -ne 0 ]]; do | |
| item="$1" | |
| shift | |
| case "$item" in | |
| --help | -h) help ;; | |
| --no-cache* | --cache*) __flag --source={item} --target={option_cache} --affirmative ;; | |
| --no-boot-offer* | --boot-offer*) __flag --source={item} --target={option_boot_offer} --affirmative ;; | |
| --no-local-source* | --local-source*) __flag --source={item} --target={option_local_source} --affirmative ;; | |
| --dev) OMARCHY_INSTALLER_REF=dev ;; | |
| --*) help 'An unrecognised flag was provided: ' --variable-value={item} ;; | |
| *) help 'An unrecognised argument was provided: ' --variable-value={item} ;; | |
| esac | |
| done | |
| __dump {option_cache} {option_boot_offer} {option_local_source} {OMARCHY_INSTALLER_REF} | |
| ) | |
| # fire if invoked standalone | |
| if [[ $0 == "${BASH_SOURCE[0]}" ]]; then | |
| dhh_example "$@" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment