From 9bfc7702ae08eb390c54db809311faf72d2370be Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Fri, 20 Mar 2026 22:23:07 +0200 Subject: [PATCH] feat(scripts): add x-gitprofile for mise enter hook git-profile switching Creates .mise.toml files with enter hooks that auto-switch git profiles when entering project directories (e.g. ~/Code/ivuorinen, ~/Code/masf). --- local/bin/x-gitprofile | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 local/bin/x-gitprofile diff --git a/local/bin/x-gitprofile b/local/bin/x-gitprofile new file mode 100755 index 0000000..3d8dce1 --- /dev/null +++ b/local/bin/x-gitprofile @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# @description Set up mise enter hooks for git-profile auto-switching +set -euo pipefail + +DEFAULTS=( + "home:$HOME/Code/ivuorinen" + "masf:$HOME/Code/masf" +) + +write_hook() +{ + local profile="$1" dir="$2" + mkdir -p "$dir" + cat > "$dir/.mise.toml" << EOF +[hooks] +enter = "git profile use $profile" +EOF + echo "Set git profile '$profile' for $dir" +} + +if [[ $# -eq 0 ]]; then + for entry in "${DEFAULTS[@]}"; do + write_hook "${entry%%:*}" "${entry#*:}" + done +elif [[ $# -eq 2 ]]; then + write_hook "$1" "$2" +else + echo "Usage: x-gitprofile [ ]" + echo " No args: set up defaults (home, masf)" + echo " With args: create .mise.toml in " + exit 1 +fi