Git scripts#
home/dot_local/bin/executable_mg and home/dot_local/bin/my-git implement the mg runtime.
This page documents runtime layout and completion integration. For user-facing command usage, see
Git workflow.
Runtime layout#
home/dot_local/bin/executable_mg: entrypoint, alias resolution, dynamic command loading, top-level help, and__complete-metadataoutput for shell completions.home/dot_local/bin/my-git/cmd-*.sh: subcommand handlers and per-command_usage_*blocks.home/dot_local/bin/my-git/git-lib.sh: shared git helpers (gitlib_*).home/dot_local/lib/bash-lib.sh: shared generic helpers (lib_*).home/dot-bash/bashrc.d/bashrc-git.sh: aliases andmgloader function for Bash.home/dot-bash/completions/mg.bash: metadata-driven Bash completions for commands/options/remotes/branches.home/dot_config/fish/functions/mg.fish: Fish wrapper that executes the Bashmgscript and handlescdfollow-up behavior.home/dot_config/fish/completions/mg.fish: metadata-driven Fish completion registration.
How dispatch works#
Entrypoint is
my_git_main()inhome/dot_local/bin/executable_mg.my_git_main()resolves aliases (u,c,s,n,b,i,rb,rw)._run_subcommand()loadscmd-<name>.shon demand and dispatches to_cmd_<name>.Name transform rule:
-in subcommand names maps to_in function names. - Example:self-branch->cmd-self-branch.sh->_cmd_self_branch.
Completion metadata flow#
home/dot_local/bin/executable_mgexposes__complete-metadatawith command names, aliases, options, and argument-position hints.home/dot-bash/completions/mg.bashreads that metadata and applies Bash completion behavior.home/dot_config/fish/completions/mg.fishreads the same metadata and registers Fish completions.switch,new-branch,path,remove-branch, andremove-worktreecomplete branch names from local branches plus remote-short names.new-branch --fromcompletes branch names for explicit base selection.self-branchandalien-branchcomplete a remote first, then branch names filtered to that remote.
Layout detection and worktree placement#
home/dot_local/bin/my-git/git-lib.shdetects runtime layout viagitlib_repo_layout_kindusinggit rev-parse --is-bare-repositoryplus path classification.Supported layout labels are
default,parent-bare-siblings,bare-siblings.git, andbare-siblings.gitlib_worktree_dir_for_branchresolves an existing worktree first, then computes the expected path withgitlib_computed_worktree_dir_for_branch.In
defaultlayout, default branch stays at repo root and non-default branches resolve under<repo>-worktrees.In bare sibling layouts, new branches resolve as siblings of the detected default-branch worktree parent.
gitlib_worktree_add_*helpers centralizegit worktree addcalls and create parent directories before add.gitlib_branch_for_worktree_basenameandgitlib_worktree_dir_for_basenameresolve basename selectors forremove-branchandremove-worktree.
Bash wrapper runtime#
home/dot-bash/bashrc.d/bashrc-git.sh defines mg as a shell function that resolves and sources
the installed mg script once, then calls my_git_main directly.
home/dot-bash/bashrc.d/bashrc-git.shkeeps shell aliases plus script-loading logic.home/dot-bash/completions/mg.bashprovides completion behavior and is sourced by the Bash wrapper file.
Fish wrapper runtime#
home/dot_config/fish/functions/mg.fish defines mg as a Fish function that resolves the script
path and invokes it through bash.
home/dot_config/fish/conf.d/git-config.fishprovides abbreviations and thelgalias.home/dot_config/fish/functions/mg.fishdelegates command execution to bashmgand then, forswitch/new-branchsuccess paths, resolvesmg path <branch>and appliescdin the current Fish shell.home/dot_config/fish/completions/mg.fishloads metadata frommgand registers completions.
Include guards#
mg uses include-guard variables to avoid re-sourcing files.
home/dot_local/lib/bash-lib.shusesMG_INCLUDE_GUARD_BASH_LIB_LOADED.home/dot_local/bin/my-git/git-lib.shusesMG_INCLUDE_GUARD_GIT_LIB_LOADED.home/dot_local/bin/executable_mguses_MG_INCLUDE_GUARD_SUBCOMMAND_SCRIPTS(associative array keyed by subcommand).
Naming assumptions#
Loader conventions:
File names:
cmd-<subcommand>.shHandler functions:
_cmd_<subcommand-with-underscores>Usage functions:
_usage_<subcommand-with-underscores>Shared git helper names:
gitlib_<name>
Prefix meaning in command scripts:
gitlib_*: shared helpers fromgit-lib.shlib_*: generic string/path helpers fromhome/dot_local/lib/bash-lib.sh_cmd_*and_usage_*: subcommand-local interface
When adding a subcommand#
Add
cmd-<subcommand>.shinhome/dot_local/bin/my-git.Define
_cmd_<subcommand-with-underscores>and_usage_<subcommand-with-underscores>.Register script mapping in
_subcommand_script_path()inhome/dot_local/bin/executable_mg.Add metadata rows in
_print_completion_metadata()forcmd,opts, and anybranch/remotehints used by completion.