Created
April 21, 2025 17:21
-
-
Save bengerman13/04cb7e521285a8e9109a5ad2461aaf0a to your computer and use it in GitHub Desktop.
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 zsh | |
| # howdidi is a tool for remembering how you installed things | |
| function howdidi_load_vars() { | |
| HOWDIDI_TARGET="$1" | |
| HOWDIDI_TARGET_DIR="${HOWDIDI_DIR:=${HOME}/.howdidi}/${HOWDIDI_TARGET}" | |
| HOWDIDI_TARGET_META="${HOWDIDI_TARGET_DIR}/meta" | |
| HOWDIDI_TARGET_HIST="${HOWDIDI_TARGET_DIR}/history" | |
| HOWDIDI_TARGET_POST="${HOWDIDI_TARGET_DIR}/post" | |
| HOWDIDI_OLD_PS1="${PS1}" | |
| HOWDIDI_PS1="${HOWDIDI_OLD_PS1}(installing ${HOWDIDI_TARGET}) " | |
| } | |
| function iminstalling() { | |
| if [[ "$1" == "help" ]] ; then | |
| iminstallinghelp | |
| return | |
| fi | |
| howdidi_load_vars "$1" | |
| mkdir -p "${HOWDIDI_TARGET_DIR}" | |
| # start a new history stack with a new history file | |
| fc -p "${HOWDIDI_TARGET_HIST}" | |
| PS1="${HOWDIDI_PS1}" | |
| echo "Now tracking your install at ${HOWDIDI_TARGET_DIR}." | |
| echo "Run \"imdone\" or exit this shell when you're done" | |
| echo "Run \"howdidiinstall ${HOWDIDI_TARGET}\" later to see how you installed ${HOWDIDI_TARGET}" | |
| echo "install_date=$(date)" >> "$HOWDIDI_TARGET_META" | |
| echo "start_pwd=$(pwd)" >> "$HOWDIDI_TARGET_META" | |
| function imdone() { | |
| # for bash, we'd need to: | |
| # write to new histfile | |
| # read from new histfile | |
| # write to original histfile | |
| # fix ps1, ps2, histfile | |
| PS1="${HOWDIDI_OLD_PS1}" | |
| unset HOWDIDI_TARGET HOWDIDI_TARGET_DIR HOWDIDI_TARGET_HIST HOWDIDI_PS1 HOWDIDI_OLD_PS1 | |
| unset -f imdone | |
| # flush the stack, revert to original histfile | |
| fc -P | |
| } | |
| # to support BASH, we'd need to: | |
| # 1. cache histfile, ps1, ps2 | |
| # 2. write current history to current histfile | |
| # 3. set new histfile | |
| # 4. set ps1, ps2 | |
| } | |
| function howdidiinstall() { | |
| # find histfiles where you installed the thing | |
| howdidi_load_vars "${1}" | |
| if [[ ! -d "${HOWDIDI_TARGET_DIR}" ]] ; then | |
| echo "You didn't record installing ${HOWDIDI_TARGET}" | |
| fi | |
| cat "${HOWDIDI_TARGET_META}" | |
| [[ -f "${HOWDIDI_TARGET_HIST}" ]] && cat "${HOWDIDI_TARGET_HIST}" | |
| [[ -f "${HOWDIDI_TARGET_POST}" ]] && cat "${HOWDIDI_TARGET_POST}" | |
| } | |
| function iinstalled() { | |
| howdidi_load_vars "${1}" | |
| mkdir -p "${HOWDIDI_TARGET_DIR}" | |
| echo "install_date=$(date)" >> "$HOWDIDI_TARGET_META" | |
| echo "start_pwd=$(pwd)" >> "$HOWDIDI_TARGET_META" | |
| echo "${@:2}" >> "${HOWDIDI_TARGET_POST}" | |
| } | |
| function iminstallinghelp() { | |
| true | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment