]>
Lady’s Gitweb - HOMEDIR/blob - sh/git.sh
2 # @(#)🏠📂 HOMEDIR sh/git.sh 2026-03-22T02:03:39Z
3 # SPDX-FileCopyrightText: 2026 Lady <https://www.ladys.computer/about/#lady>
4 # SPDX-License-Identifier: MPL-2.0
8 ## ∎ Copyright © 2026 Lady [@ Ladys Computer].
10 ## ⋮ This Source Code Form is subject to the terms of the Mozilla
11 ## Public License, version 2.0.
12 ## If a copy of the M·P·L was not distributed with this file, You can
13 ## obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.
17 ## This script enables a “splitting” of Git working directories and
18 ## underlying repos, with pseud‐specific configurations.
19 ## It is intended to accommodate cloud syncing services where one
20 ## intends for the working copy of files to be synced, but not the
21 ## underlying Git directory (which is stored in a different
24 ## Working directory paths must have the format
25 ## `${path_PSEUDDIR}/~${PSEUD}/${REPONAME}´; that is, the first
26 ## directory inside of `${path_PSEUDDIR}´ which begins with a `~´
27 ## is taken to be a pseud, and the first directory inside of that is
28 ## taken as the repository root.
29 ## For working directories which do not match this format, this script
30 ## just calls Git normally.
32 ## The corresponding repository for a working directory is taken to be
33 ## `${path_REPODIR}/~${PSEUD}/${REPONAME}.git´.
34 ## These are effectively bare repositories.
35 ## If no repository is found, one is created.
39 ## The following variables provide hooks to override the commands used
42 ## As this script is expected to override `git´ in the `${PATH}´, the
43 ## actual path to the Git binary must be used.
45 : "${cmd_GIT:=/usr/bin/git}"
46 : "${cmd_MKDIR:=mkdir}"
47 : "${cmd_PRINTF:=printf}"
51 : "${cmd_TOUCH:=touch}"
53 ## The `path_PSEUDDIR´ variable gives the directory which contains the
54 ## actual underlying Git repository for the current directory.
55 ## By default, it is the first of the following which returns an actual
58 ## • `~/Documents/Pseuds´
64 if "${cmd_TEST}" -z "${path_PSEUDDIR}"
66 if "${cmd_TEST}" -d "${HOME}"'/Documents/Pseuds'
68 path_PSEUDDIR
="${HOME}"'/Documents/Pseuds'
69 elif "${cmd_TEST}" -d "${HOME}"'/Pseuds'
71 path_PSEUDDIR
="${HOME}"'/Pseuds'
73 path_PSEUDDIR
="${HOME}"'/pseuds'
77 ## The `path_REPODIR´ variable gives the directory which contains the
78 ## actual underlying Git repository for the current directory.
79 ## By default, it is the first of the following which returns an actual
90 if "${cmd_TEST}" -z "${path_REPODIR}"
92 if "${cmd_TEST}" -d "${HOME}"'/Git'
94 path_REPODIR
="${HOME}"'/Git'
95 elif "${cmd_TEST}" -d "${HOME}"'/git'
97 path_REPODIR
="${HOME}"'/git'
98 elif "${cmd_TEST}" -d "${HOME}"'/Repositories'
100 path_REPODIR
="${HOME}"'/Repositories'
102 path_REPODIR
='/srv/git'
108 ## The `realpwd´ variable holds the “real” path to the current
115 ## The `workdir´ variable holds the full path to the working directory,
116 ## taken to be the first directory after the first directory
117 ## beginning with a `~´.
120 "${cmd_PRINTF}" '%s\n' "${realpwd}" |
121 "${cmd_SED}" '\%/~.*/%!d;s%\([^~]*/~[^/]*/[^/]*\)\(/.*\)*%\1%'
124 ## If `${workdir}´ does not begin with `${path_PSEUDDIR}´, it is nulled
127 if "${cmd_TEST}" "${workdir##"${path_PSEUDDIR}"}" = "${workdir}"
132 ## The `reponame´ variable holds the pseud and repository name.
135 "${cmd_PRINTF}" '%s\n' "${workdir}" |
136 "${cmd_SED}" 's%[^~]*/\(~[^/]*/[^/]*\)%\1%'
139 ## The `pseudname´ variable holds just the pseud.
142 "${cmd_PRINTF}" '%s\n' "${reponame}" |
143 "${cmd_SED}" 's%\(~[^/]*\)/.*%\1%'
146 ## If the repo name is null, this script just calls Git normally.
148 if "${cmd_TEST}" -z "${reponame}"
152 ## Otherwise, it must call Git specially.
153 ## The configuration file at `${path_REPODIR}/${pseudname}/.gitconfig´
154 ## is included into the Git configuration.
157 configfile
="${path_REPODIR}"'/'"${pseudname}"'/.gitconfig'
158 baredir
="${path_REPODIR}/${reponame}.git"
160 ## If the pseud directory does not exist within `${path_REPODIR}´, it
163 if "${cmd_TEST}" ! -d "${path_REPODIR}"'/'"${pseudname}"
165 "${cmd_MKDIR}" -p "${path_REPODIR}"'/'"${pseudname}"
168 ## If the configuration file does not already exist, it is created.
170 if "${cmd_TEST}" ! -f "${configfile}"
172 "${cmd_TOUCH}" "${configfile}"
175 ## If the repository does not already exist, it is initialized with a
178 if "${cmd_TEST}" ! -d "${baredir}"
182 -c "include.path=${configfile}" \
183 --git-dir="${baredir}" init \
184 --object-format=sha256
188 ## Finally, Git is run with the appropriate Git directory and work
192 -c "include.path=${configfile}" \
193 --git-dir="${baredir}" \
194 --work-tree="${workdir}" \
This page took 0.109395 seconds and 5 git commands to generate.