mirror of
https://github.com/samsonjs/config.git
synced 2026-06-24 04:59:08 +00:00
Add tracked jj config with aliases, revsets, and per-machine override support
This commit is contained in:
parent
6c815121ff
commit
009a2df1b4
2 changed files with 61 additions and 44 deletions
63
init.sh
63
init.sh
|
|
@ -61,60 +61,35 @@ for FILE in "$CONFIG_PATH"/*; do
|
|||
fi
|
||||
done
|
||||
|
||||
setup_jj_identity() {
|
||||
if ! command -v jj >/dev/null 2>&1; then
|
||||
echo "Note: jj is not installed, skipping jj identity setup"
|
||||
# Symlink jj/config.toml into ~/.config/jj/. To override anything on a specific
|
||||
# machine/account, drop any *.toml into ~/.config/jj/conf.d/ — jj loads that
|
||||
# directory and it takes precedence over config.toml.
|
||||
setup_jj_config() {
|
||||
local src="${CONFIG_PATH}/jj/config.toml"
|
||||
local dest="${HOME}/.config/jj/config.toml"
|
||||
|
||||
if [ ! -f "$src" ]; then
|
||||
echo "Note: ${src} not found, skipping jj config link"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -z "$(jj config get user.name 2>/dev/null)" ]; then
|
||||
jj config set --user user.name "Sami Samhuri"
|
||||
echo "→ Set jj user.name"
|
||||
else
|
||||
echo "✓ jj user.name already set"
|
||||
fi
|
||||
mkdir -p "${HOME}/.config/jj"
|
||||
|
||||
if [ -z "$(jj config get user.email 2>/dev/null)" ]; then
|
||||
jj config set --user user.email "sami@samhuri.net"
|
||||
echo "→ Set jj user.email"
|
||||
else
|
||||
echo "✓ jj user.email already set"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prefer the "github" remote over the default "origin" everywhere jj defaults
|
||||
# to it: trunk() resolution, git push, git fetch. The trunk() alias is a
|
||||
# fallback chain — repo-level trunk() (written by jj at init) still wins.
|
||||
setup_jj_github_defaults() {
|
||||
if ! command -v jj >/dev/null 2>&1; then
|
||||
if [ -L "$dest" ] && [ "$(readlink "$dest")" = "$src" ]; then
|
||||
echo "✓ ${dest} already linked correctly"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local trunk_alias='latest(present(main@github) | present(master@github) | present(main@origin) | present(master@origin) | root())'
|
||||
|
||||
if [ "$(jj config get 'revset-aliases."trunk()"' 2>/dev/null)" = "$trunk_alias" ]; then
|
||||
echo "✓ jj trunk() alias already set"
|
||||
else
|
||||
jj config set --user 'revset-aliases."trunk()"' "$trunk_alias"
|
||||
echo "→ Set jj trunk() alias to prefer github"
|
||||
if [ -e "$dest" ] || [ -L "$dest" ]; then
|
||||
echo "Backing up existing ${dest} to ~/original-dot-files/"
|
||||
mkdir -p "${HOME}/original-dot-files"
|
||||
mv "$dest" "${HOME}/original-dot-files/jj-config.toml.$(date +%Y%m%d_%H%M%S)"
|
||||
fi
|
||||
|
||||
if [ "$(jj config get git.push 2>/dev/null)" = "github" ]; then
|
||||
echo "✓ jj git.push already set to github"
|
||||
else
|
||||
jj config set --user git.push github
|
||||
echo "→ Set jj git.push to github"
|
||||
fi
|
||||
|
||||
if [ "$(jj config get git.fetch 2>/dev/null)" = "github" ]; then
|
||||
echo "✓ jj git.fetch already set to github"
|
||||
else
|
||||
jj config set --user git.fetch github
|
||||
echo "→ Set jj git.fetch to github"
|
||||
fi
|
||||
ln -s "$src" "$dest"
|
||||
echo "→ Linked ${dest} to ${src}"
|
||||
}
|
||||
|
||||
setup_jj_identity
|
||||
setup_jj_github_defaults
|
||||
setup_jj_config
|
||||
|
||||
echo "Done!"
|
||||
|
|
|
|||
42
jj/config.toml
Normal file
42
jj/config.toml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#:schema https://docs.jj-vcs.dev/latest/config-schema.json
|
||||
|
||||
# Symlinked to ~/.config/jj/config.toml by init.sh. To override anything on a
|
||||
# specific machine/account, drop any *.toml into ~/.config/jj/conf.d/ — jj loads
|
||||
# that directory and it wins over this file.
|
||||
|
||||
[user]
|
||||
name = "Sami Samhuri"
|
||||
email = "sami@samhuri.net"
|
||||
|
||||
[git]
|
||||
push = "github"
|
||||
fetch = "github"
|
||||
|
||||
[revset-aliases]
|
||||
# Prefer the github remote, and treat a `dev` integration branch as trunk when
|
||||
# it exists (hobby repos where dev is worked on and merged to main to release).
|
||||
# latest() picks the most recently-committed of whichever are present.
|
||||
"trunk()" = "latest(present(dev@github) | present(dev@origin) | present(main@github) | present(master@github) | present(main@origin) | present(master@origin) | root())"
|
||||
|
||||
# Tip changes (heads) you own that carry no bookmark and aren't in trunk.
|
||||
"unbookmarked()" = "(visible_heads() & mine()) ~ bookmarks() ~ ::trunk()"
|
||||
|
||||
# Your mutable work-in-progress: everything you own that isn't in trunk yet.
|
||||
"open()" = "mine() & ~::trunk()"
|
||||
|
||||
# The bookmark nearest below a given rev — powers `tug`.
|
||||
"closest_bookmark(to)" = "heads(::to & bookmarks())"
|
||||
|
||||
[aliases]
|
||||
# Compact log of your open work.
|
||||
wip = ["log", "-r", "open()"]
|
||||
|
||||
# Your unbookmarked tip changes.
|
||||
tips = ["log", "-r", "unbookmarked()"]
|
||||
|
||||
# Bookmarks (local + remote) with date + name.
|
||||
bks = ["log", "--no-graph", "-r", "bookmarks() | remote_bookmarks()",
|
||||
"-T", "separate(\" \", committer.timestamp().local().format(\"%Y-%m-%d %H:%M\"), separate(\" \", bookmarks, remote_bookmarks)) ++ \"\\n\""]
|
||||
|
||||
# Drag the closest bookmark up to @.
|
||||
tug = ["bookmark", "move", "--from", "closest_bookmark(@)", "--to", "@"]
|
||||
Loading…
Reference in a new issue