Posts tagged: cli

All posts with the tag "cli"

100 posts latest post 2026-06-29
Publishing rhythm
Jun 2026 | 2 posts

Authentication from cli tools can be a bit of a bear, and I have to look it up every time. This is my reference guide for future me to remember how to easily do it.

I set up a fastapi server running on port 8000, it uses a basic auth with waylonwalker as the username and asdf as the password. The server follows along with what comes out of the docs. I have it setup to take basic auth, form username and password, or a bearer token for authentication.

curl #

The og of command line url tools.

# basic auth
curl -u 'waylonwalker:asdf' -X POST localhost:8000/token
# basic auth with password prompt
curl -u 'waylonwalker' -X POST localhost:8000/token
# token
curl -H 'Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg' -X POST localhost:8000/token

wget #

My go to if I want the result to go into a file.

# basic auth
wget -q -O - --auth-no-challenge --http-user=waylonwalker --http-password=asdf --post-data '' localhost:8000/token

# token
wget -q -O - --header="Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg" -O - --post-data '' localhost:8000/token

httpx #

An http client written in python, primarilty used with the python api, but has a nice cli.

# install
python3 -m pip install httpx

# basic auth
httpx -m POST --auth waylonwalker asdf http://localhost:8000/token

# basic auth with password prompt
httpx -m POST --auth waylonwalker - http://localhost:8000/token

# token
httpx -m POST --headers="Authorization" "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg" http://localhost:8000/token

httpie #

A modern http client written in python.

# install
python3 -m pip install httpie

# basic auth
http POST localhost:8000/token -a waylonwalker:asdf

# basic auth with password prompt
http POST localhost:8000/token -a waylonwalker

# token
http POST localhost:8000/token -A bearer -a eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ3YXlsb253YWxrZXIiLCJleHAiOjE3MDI5NTI2MDJ9.GeYNt7DNal6LTiPoavJnqypaMt4vYeriXdq5lqu1ILg

httpie with plugin #

# install
python3 -m pip install httpie-credential-store
# usage
http POST localhost:8000/token -A creds

httpie prompt #

http-prompt comes from the httpie org, and has an interactive cli interface into apis. You can even specify a spec file to autocomplete on api methods.

http-prompt localhost:8000 --auth waylonwalker:asdf --spec openapi.json
[1]@willmcgugan [1]) on X — Just a wee thing that came up today. I think this is kind of neat." loading="lazy"> Will McGugan (@willmcgugan [2]) on X Just a wee thing that came up today. I think this is kind of neat. X (formerly Twitter) · twitter.com Textual is so sick, Will just made a live markdown editor in the terminal! References: [1]: https://twitter.com/willmcgugan/status/1729158038551220477 [2]: https://willmcgugan.github.io
kv - Command | Vault | HashiCorp Developer The "kv" command groups subcommands for interacting with Vault's key/value secret engine. kv - Command | Vault | HashiCorp Developer · developer.hashicorp.com [1] hashi vault lets you manage secrets right from your cli. # set your vault url export VAULT_ADDR=https://myvault.mydomain vault login # get a secret vault kv get secret/hvac # put a secret vault kv put -mount=secret creds passcode=my-long-passcode # get it vault kv get secret/creds # == Secret Path == # secret/data/creds # # ======= Metadata ======= # Key Value # --- ----- # created_time 2023-11-05T02:53:40.978120001Z # custom_metadata <nil> # deletion_time n/a # destroyed false # version 3 # # ====== Data ====== # Key Value # --- ----- # bar baz # passcode my-long-passcode # get one field vault kv get -field=passcode secret/creds # my-long-passcode vault kv put -mount=secret creds bar=baz # set more keys vault kv put -mount=secret creds passcode=my-long-passcode bar=baz # # == Secret Path == # secret/data/creds # # ======= Metadata ======= # Key Value # --- ----- # created_time 2023-11-05T03:24:14.65958906Z # custom_metadata <nil> # deletion_time n/a # destroyed fa...
GitHub - casey/just: 🤖 Just a command runner 🤖 Just a command runner. Contribute to casey/just development by creating an account on GitHub. GitHub · github.com [1] I think just, might just be the thing I have been looking for. I’ve been looking for some ci/cd that I can host myself, but everything looks pretty big, so for now I am going to use just as my task runner. I installed with installer. curl https://i.wayl.one/casey/just | bash I set up my devtainer builds with just. Here is my justfile, yes you just need the cli and a file named justfile. default: base alpine slim base: build deploy alpine: build-alpine deploy-alpine slim: build-slim deploy-slim build: podman build -t registry.wayl.one/devtainer:latest . deploy: podman push registry.wayl.one/devtainer build-alpine: podman build -f docker/Dockerfile.alpine -t registry.wayl.one/devtainer:alpine . deploy-alpine: podman push registry.wayl.one/devtainer:alpine build-slim: podman build -f docker/Dockerfile.slim -t registry.wayl.one/devtainer:slim . deploy-slim: podman push registry.wayl.one/devtainer:slim References: [1]: https://github.com/casey/just
[1] Wincent (Greg Hurrel) has a pretty solid and fast zshrc. I recently grabbed his completion section and it seems to be working better than whatever I had. zsh completion snippet # # Completion # fpath=($HOME/.zsh/completions $fpath) autoload -U compinit compinit -u # Make completion: # - Try exact (case-sensitive) match first. # - Then fall back to case-insensitive. # - Accept abbreviations after . or _ or - (ie. f.b -> foo.bar). # - Substring complete (ie. bar -> foobar). zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]}' '+m:{[:upper:]}={[:lower:]}' '+m:{_-}={-_}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # Colorize completions using default `ls` colors. zstyle ':completion:*' list-colors '' # Allow completion of ..<Tab> to ../ and beyond. zstyle -e ':completion:*' special-dirs '[[ $PREFIX = (../)#(..) ]] && reply=(..)' # $CDPATH is overpowered (can allow us to jump to 100s of directories) so tends # to dominate completion; exclude path-directories from the tag-order so that # they will only be used as a fallback if no completions are found. zstyle ':completion:*:complete:(cd|pushd):*' tag-order 'local-directories named-directories' # Categorize completion...

jpillora/installer is the install script generator I have been looking for. It downloads binaries for your machine from GitHub releases and unzips them for you. It grabs the latest release, so you can easily update them. I have tried scripting these installs in the past and struggled to consistently get the latest version for every package and unpack it correctly.

Also these pre-compiled binaries install rediculously fast compared to building them from source.

Check out some example links.

opening in a browser will show metadata

https://i.jpillora.com/serve

If you pass in script=true it will instead return the install script as it would by default through curl.

https://i.jpillora.com/serve?script=true

Use it to install neovim #

All you need to do to generate an install script is to pass in the GitHub repo slug with the org.

curl https://i.jpillora.com/neovim/neovim | bash

The shell script that it generates for neovim looks like this.

#!/bin/bash
if [ "$DEBUG" == "1" ]; then
    set -x
fi
TMP_DIR=$(mktemp -d -t jpillora-installer-XXXXXXXXXX)
function cleanup {
    rm -rf $TMP_DIR > /dev/null
}
function fail {
    cleanup
    msg=$1
    echo "============"
    echo "Error: $msg" 1>&2
    exit 1
}
function install {
    #settings
    USER="neovim"
    PROG="neovim"
    ASPROG=""
    MOVE="false"
    RELEASE="stable"
    INSECURE="false"
    OUT_DIR="$(pwd)"
    GH="https://github.com"
    #bash check
    [ ! "$BASH_VERSION" ] && fail "Please use bash instead"
    [ ! -d $OUT_DIR ] && fail "output directory missing: $OUT_DIR"
    #dependency check, assume we are a standard POISX machine
    which find > /dev/null || fail "find not installed"
    which xargs > /dev/null || fail "xargs not installed"
    which sort > /dev/null || fail "sort not installed"
    which tail > /dev/null || fail "tail not installed"
    which cut > /dev/null || fail "cut not installed"
    which du > /dev/null || fail "du not installed"
    #choose an HTTP client
    GET=""
    if which curl > /dev/null; then
        GET="curl"
        if [[ $INSECURE = "true" ]]; then GET="$GET --insecure"; fi
        GET="$GET --fail -# -L"
    elif which wget > /dev/null; then
        GET="wget"
        if [[ $INSECURE = "true" ]]; then GET="$GET --no-check-certificate"; fi
        GET="$GET -qO-"
    else
        fail "neither wget/curl are installed"
    fi
    #debug HTTP
    if [ "$DEBUG" == "1" ]; then
        GET="$GET -v"
    fi
    #optional auth to install from private repos
    #NOTE: this also needs to be set on your instance of installer
    AUTH="${GITHUB_TOKEN}"
    if [ ! -z "$AUTH" ]; then
        GET="$GET -H 'Authorization: $AUTH'"
    fi
    #find OS #TODO BSDs and other posixs
    case `uname -s` in
    Darwin) OS="darwin";;
    Linux) OS="linux";;
    *) fail "unknown os: $(uname -s)";;
    esac
    #find ARCH
    if uname -m | grep -E '(arm|arch)64' > /dev/null; then
        ARCH="arm64"

        # no m1 assets. if on mac arm64, rosetta allows fallback to amd64
        if [[ $OS = "darwin" ]]; then
            ARCH="amd64"
        fi

    elif uname -m | grep 64 > /dev/null; then
        ARCH="amd64"
    elif uname -m | grep arm > /dev/null; then
        ARCH="arm" #TODO armv6/v7
    elif uname -m | grep 386 > /dev/null; then
        ARCH="386"
    else
        fail "unknown arch: $(uname -m)"
    fi
    #choose from asset list
    URL=""
    FTYPE=""
    case "${OS}_${ARCH}" in
    "linux_amd64")
        URL="https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz"
        FTYPE=".tar.gz"
        ;;
    "darwin_amd64")
        URL="https://github.com/neovim/neovim/releases/download/stable/nvim-macos.tar.gz"
        FTYPE=".tar.gz"
        ;;
    *) fail "No asset for platform ${OS}-${ARCH}";;
    esac
    #got URL! download it...
    echo -n "Downloading"
    echo -n " $USER/$PROG"
    if [ ! -z "$RELEASE" ]; then
        echo -n " $RELEASE"
    fi
    if [ ! -z "$ASPROG" ]; then
        echo -n " as $ASPROG"
    fi
    echo -n " (${OS}/${ARCH})"

    echo "....."

    #enter tempdir
    mkdir -p $TMP_DIR
    cd $TMP_DIR
    if [[ $FTYPE = ".gz" ]]; then
        which gzip > /dev/null || fail "gzip is not installed"
        bash -c "$GET $URL" | gzip -d - > $PROG || fail "download failed"
    elif [[ $FTYPE = ".tar.bz" ]] || [[ $FTYPE = ".tar.bz2" ]]; then
        which tar > /dev/null || fail "tar is not installed"
        which bzip2 > /dev/null || fail "bzip2 is not installed"
        bash -c "$GET $URL" | tar jxf - || fail "download failed"
    elif [[ $FTYPE = ".tar.gz" ]] || [[ $FTYPE = ".tgz" ]]; then
        which tar > /dev/null || fail "tar is not installed"
        which gzip > /dev/null || fail "gzip is not installed"
        bash -c "$GET $URL" | tar zxf - || fail "download failed"
    elif [[ $FTYPE = ".zip" ]]; then
        which unzip > /dev/null || fail "unzip is not installed"
        bash -c "$GET $URL" > tmp.zip || fail "download failed"
        unzip -o -qq tmp.zip || fail "unzip failed"
        rm tmp.zip || fail "cleanup failed"
    elif [[ $FTYPE = ".bin" ]]; then
        bash -c "$GET $URL" > "neovim_${OS}_${ARCH}" || fail "download failed"
    else
        fail "unknown file type: $FTYPE"
    fi
    #search subtree largest file (bin)
    TMP_BIN=$(find . -type f | xargs du | sort -n | tail -n 1 | cut -f 2)
    if [ ! -f "$TMP_BIN" ]; then
        fail "could not find find binary (largest file)"
    fi
    #ensure its larger than 1MB
    #TODO linux=elf/darwin=macho file detection?
    if [[ $(du -m $TMP_BIN | cut -f1) -lt 1 ]]; then
        fail "no binary found ($TMP_BIN is not larger than 1MB)"
    fi
    #move into PATH or cwd
    chmod +x $TMP_BIN || fail "chmod +x failed"
    DEST="$OUT_DIR/$PROG"
    if [ ! -z "$ASPROG" ]; then
        DEST="$OUT_DIR/$ASPROG"
    fi
    #move without sudo
    OUT=$(mv $TMP_BIN $DEST 2>&1)
    STATUS=$?
    # failed and string contains "Permission denied"
    if [ $STATUS -ne 0 ]; then
        if [[ $OUT =~ "Permission denied" ]]; then
            echo "mv with sudo..."
            sudo mv $TMP_BIN $DEST || fail "sudo mv failed"
        else
            fail "mv failed ($OUT)"
        fi
    fi
    echo "Downloaded to $DEST"
    #done
    cleanup
}
install

Self Host Your Own #

I’d reccomend self hosting your own. This way you know that it’s consistent and unlikely to change in a way that breaks your use.

curl -s https://i.jpillora.com/installer | bash

Repos I am using installer for #

Here are the repos I am using installer for.

atuinsh/atuin
benbjohnson/litestream
bootandy/dust
BurntSushi/ripgrep
chmln/sd
cjbassi/ytop
dalance/procs
dbrgn/tealdeer
ducaale/xh
go-task/task
imsnif/bandwhich
imsnif/diskonaut
kovidgoyal/kitty
mgdm/htmlq
neovim/neovim
ogham/dog
ogham/exa
pemistahl/grex
sharkdp/bat
sharkdp/fd
sharkdp/pastel
sirwart/ripsecrets
starship/starship
topgrade-rs/topgrade
zellij-org/zellij
GitHub - jpillora/installer: One-liner for installing binaries from Github releases One-liner for installing binaries from Github releases - jpillora/installer GitHub · github.com [1] This is a sick looking bash script generator for installing binaries off of github releases. it reccomends curl into bash, but you could curl into install.sh and toss that in your dotfiles repo or wherever. Install installer with installer curl -s https://i.jpillora.com/installer | bash References: [1]: https://github.com/jpillora/installer
Formatter How to use the Biome formatter. Biome · biomejs.dev [1] Tried out biome today and it worked better than prettier on jinja templates, I might adopt this over prettier. References: [1]: https://biomejs.dev/formatter/
cURL Command Without Using Cache | Baeldung on Linux A quick and practical guide to using curl without cache. Baeldung on Linux · baeldung.com [1] Busting cache with curl. I’m not sure how much gets cached by curl, but I have ran into several cases where I am looking for new content and I want to ensure the content is new and no chance of being cached. This article suggests 3 different techniques. curl -H 'Cache-Control: no-cache, no-store' http://www.example.com curl -H 'Pragma: no-cache' http://www.example.com curl http://www.example.com/?xyzzyspoon References: [1]: https://www.baeldung.com/linux/curl-without-cache#adding-the-pragma-http-header
GitHub - sharkdp/bat: A cat(1) clone with wings. A cat(1) clone with wings. Contribute to sharkdp/bat development by creating an account on GitHub. GitHub · github.com [1] Bat is my favorite pager, its the one for me that seems to just work more than the rest. colors, syntax highlighting, line numbers search, it just feels the most natural. References: [1]: https://github.com/sharkdp/bat
How To Format All Files in a Directory with Prettier Format any project, folder, or workspace using Prettier code formatter one line in the Prettier CLI. Medium · levelup.gitconnected.com [1] Use prettier to format all files in a directory. By default prettier does not write, it just echos out the format that it would do. Give it the --write and it will write the changes to the files. prettier --write . I just used this on my thoughts repo. prettier --write templates References: [1]: https://levelup.gitconnected.com/how-to-format-all-files-in-a-directory-with-prettier-5f0ff5f4ffb2
Textual - Center things Textual is a TUI framework for Python, inspired by modern web development. Textual Documentation · textual.textualize.io [1] How to center things in textual. Textual has a very unique way of styling text user interfaces for the terminal using css. If you know css it feels natural. @willmcgugan [2], has put together a great article on how to center things in textual here the final result from textual.app import App, ComposeResult from textual.widgets import Static QUOTE = "Could not find you in Seattle and no terminal is in operation at your classified address." class CenterApp(App): """How to center things.""" CSS = """ Screen { align: center middle; } #hello { background: blue 50%; border: wide white; width: 40; height: 9; text-align: center; content-align: center middle; } """ def compose(self) -> ComposeResult: yield Static(QUOTE, id="hello") if __name__ == "__main__": app = CenterApp() app.run() References: [1]: https://textual.textualize.io/how-to/center-things/ [2]: https://willmcgugan.github.io
Deleting Specific Lines in a File with sed or yq — Nick Janetakis We Nick Janetakis · nickjanetakis.com [1] sed can be a tricky beast, I often stumble when trying to pipe into it. Next time I need to use sed, I should reference this article by Nick Janetakis. He makes it looks much easier than my experience has been, and it appears to behave like a vim :%s/ substitution does, or a g/ g command. References: [1]: https://nickjanetakis.com/blog/deleting-specific-lines-in-a-file-with-sed-or-yq
GitHub - 1j01/textual-paint: :art: MS Paint in your terminal. :art: MS Paint in your terminal. Contribute to 1j01/textual-paint development by creating an account on GitHub. GitHub · github.com [1] 1j01 [2] created a complete working clone of ms paint in the terminal using the textual framework. It’s incredible. References: [1]: https://github.com/1j01/textual-paint [2]: https://github.com/1j01
GitHub - doyensec/wsrepl: WebSocket REPL for pentesters WebSocket REPL for pentesters. Contribute to doyensec/wsrepl development by creating an account on GitHub. GitHub · github.com [1] Very inspiring textual project to check out how they set up the ui. Their intro video has a pretty epic dev experience. References: [1]: https://github.com/doyensec/wsrepl
[1]https://t.co/km5m7k6Pb0 [1] #doyensec #appsec #websockets [2] #burpsuite" loading=“lazy”> Doyensec (@Doyensec) on X Announcing wsrepl, the WebSocket testing tool from Doyensec! This intuitive tool is super easy to use and makes automation around WebSockets simple! Check out our blog for the details and download… X (formerly Twitter) · twitter.com wsrepl is an epic websocket repl built in python on the textual framework. References: [1]: https://twitter.com/Doyensec/status/1681320727465672706 [2]: /tags/websockets/

Quickly and easily create new versions of your Python package with the gh release command. Get the version number, changelog, and

Releasing a new version of your Python package can be a daunting task. You need to make sure that all the necessary files are included, and that the version number is correct. But now, with the help of the gh release command, you can make the process much smoother.

The gh release command allows you to quickly and easily create a new version of your Python package. All you need to do is provide the version number, the changelog, and the distribution files. For example, if you wanted to create a new version of your package with the version number v1.2.3, you could use the following command:

gh release create v1.2.3 -F CHANGELOG.md dist/*.whl dist/*.tar.gz

This command will create a new version of your package with the specified version number, and include the changelog and the distribution files. It’s a great way to make sure that all the necessary files are included in the release, and that the version number is correct.

The gh release command is a great tool for quickly and easily creating new versions of your Python package. With just a few simple commands, you can make sure that all the necessary files are included, and that the version number is correct. So if you’re looking for an easy way to release a new version of your Python package, give the gh release command a try.

Give github actions the -e flag in the shebang #! so they fail on any one command failure. Otherwise each line will set the exit status, but only the last one will be passed to ci.

#!/bin/bash -e

What is -e #

The -e flag to the bash command allows your script to exit immediately if any command within the script returns a non-zero exit status. This can be useful for ensuring that your script exits with an error if any of the commands it runs fail, which can help you identify and debug issues in your script. For example, if you have a script that runs several commands and one of those commands fails, the script will continue running without the -e flag, but will exit immediately if the -e flag is present. This can make it easier to troubleshoot your script and ensure that it runs correctly.

Solution for Windows #

In windows the solution is not quite as simple. You can define a function in a Windows batch script that wraps an if statement to check the exit status of a command and handle any errors that may have occurred. Here is an example of how you might define a function called “check_error” that does this:

:check_error
if errorlevel 1 (
  echo An error occurred!
  exit /b 1
)

To use this function in your script, you would simply call it after running a command, like this:

some_command
call :check_error

This would run the “some_command” and then call the “check_error” function to check the exit status and handle any errors that may have occurred. This approach allows you to reuse the error-checking logic in your script, which can make it easier to write and maintain.