diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..545353a --- /dev/null +++ b/.envrc @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +( + set -euo pipefail + + now="$(date +%Y-%m-%d)" + if [[ -s .direnv/pull-date && "$now" = "$(cat .direnv/pull-date)" ]]; then + return 0 + fi + + prints_true() { + [[ "$("$@" 2>/dev/null)" = "true" ]] + } + + git_dot_git_dir() { + if prints_true git rev-parse --is-inside-work-tree; then + git rev-parse --git-dir 2>/dev/null + fi + } + + gdot="$(git_dot_git_dir)" + [ -n "$gdot" ] || return 1 + + if [[ -f "$gdot/rebase-merge/interactive" ]]; then + printf >&2 "%s\n" "REBASE-i" + return 1 + elif [[ -d "$gdot/rebase-merge" ]]; then + printf >&2 "%s\n" "REBASE-m" + return 1 + elif [[ -d "$gdot/rebase-apply" ]]; then + printf >&2 "%s\n" "AM/REBASE" + return 1 + elif [[ -f "$gdot/MERGE_HEAD" ]]; then + printf >&2 "%s\n" "MERGING" + return 1 + elif [[ -f "$gdot/CHERRY_PICK_HEAD" ]]; then + printf >&2 "%s\n" "CHERRY-PICKING" + return 1 + elif [[ -f "$gdot/BISECT_LOG" ]]; then + printf >&2 "%s\n" "BISECTING" + return 1 + fi + + git pull --rebase --autostash + + mkdir -p .direnv/ + printf "%s\n" "$now" >.direnv/pull-date +) diff --git a/.gitignore b/.gitignore index 22f4fa3..99f64da 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ !/justfile !/.gitignore !/clean.sh +!/.envrc