-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodular.sh
executable file
·67 lines (57 loc) · 2.19 KB
/
modular.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# Unix shell helper functions for a modular bare repo approach
# Copyright 2023 Jonathan Bowman. All documentation and code contained
# in this file may be freely shared in compliance with the
# Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
# and is provided "AS IS" without warranties or conditions of any kind.
#
# To use this script, first ask yourself if I can be trusted, then read the code
# below and make sure you feel good about it, then consider downloading and
# executing this code that comes with no warranties or claims of suitability:
#
# OUT="$(mktemp)"; wget -q -O - https://raw.githubusercontent.com/bowmanjd/dotfile-scripts/main/modular.sh > $OUT; . $OUT
#
# Now you can use "dtfnew $module $repo_url" to set up a new repo, or
# "dtfrestore $module $repo_url" to download and configure an already populated
# repo to a specific directory. Then use "dtf $module " instead of "git" to
# add, commit, push, pull, etc.
DOTFILES="$HOME/.dotfiles"
dtf () {
MODULE=$1
shift
git --git-dir="$DOTFILES/$MODULE" --work-tree="$HOME" $@
}
dtfclone () {
mkdir -p $DOTFILES
DISPOSABLE=$(mktemp -dt dtf-XXXXXX)
git clone -c status.showUntrackedFiles=no -n --separate-git-dir $DOTFILES/$1 $2 $DISPOSABLE
rm -rf $DISPOSABLE
}
dtfnew () {
dtfclone $1 $2
echo "Please add and commit additional files"
echo "using 'dtf $1 add' and 'dtf $1 commit', then run"
echo "dtf $1 push -u origin HEAD"
}
dtfrestore () {
dtfclone $1 $2
#dtf $MODULE branch -t $(dtf $MODULE symbolic-ref --short HEAD) origin/HEAD
dtf $1 checkout || echo -e "Deal with conflicting files, then run (possibly with -f flag if you are OK with overwriting)\ndtf $1 checkout"
}
dtfcheck () {
for mod in $(find "$DOTFILES" -maxdepth 1 -mindepth 1 -type d); do
printf "\n$(basename $mod):\n"
git --git-dir="$mod" remote update >/dev/null
dtf $(basename "$mod") status | rg --color=never '(Changes|ahead|behind|new file|modified)'
done
}
dtfquery () {
for modpath in $(find "$DOTFILES" -maxdepth 1 -mindepth 1 -type d); do
mod="$(basename $modpath)"
match="$(dtf $mod ls-tree --name-only HEAD $@)"
if [ -n "$match" ]; then
echo "${mod}:"
echo "$match" | rg '^' -r ' '
fi
done
}