initial commit

This commit is contained in:
Matthias Johnson 2025-02-15 17:49:25 -07:00
commit 1174bf47eb
2 changed files with 117 additions and 0 deletions

71
README.md Normal file
View file

@ -0,0 +1,71 @@
# dotGit
There are a lot of ways to manage your dotfiles. dotGit implements an idea that has been floating around on the internet for a while: a bare git repo for storing your dotfiles. A quick search finds [this](https://news.ycombinator.com/item?id=11070797), but there may be older sources.
dotGit has modest aims
- 🏡keep config files where tools expect them in `$HOME`
- 🐚stay as light and close to git and the shell as possible
- 🚀reduce friction and make config changes quick and convenient
dotGit gives you a handful of shell aliases (tested with `zsh`🐚 and `bash`) to make dotfile management quick and easy. The shortcuts mimic a subset of those found in the [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) [git](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git) plugin.
- `.g` is the alias for running `git` with correct `--git-dir` and `--work-tree`
- `.ga` to `git add`
- `.gc` to `git commmit`
- `.gco` to `git checkout`
- `.gd` to run `git diff`
- `.gss` shows the `git status --short`
- `.gp` will `git push`
- `.gl` witll `git pull`
- `.glo` runs `git log --oneline --decorate `
- `.glg` runs `git log --stat`
- `.glgp` runs `git log --stat --patch`
- `.gg` runs `git grep` on your dotfiles. It will pass it through [FZF](https://github.com/junegunn/fzf) (if available) for editing with `$EDITOR` on the correct line (works with vi, emacs, nano, and micro)
- `.ge` (requires [FZF](https://github.com/junegunn/fzf)) lists all files using FZF and opens the selected file in your `$EDITOR`
- `.lazygit` (requires [lazygit](https://github.com/jesseduffield/lazygit)) will run `lazygit` with the correct `-g` and `-w`
- `.gitui` (requires [gitui](https://github.com/extrawurst/gitui)) will run `gitui` with the correct `-d` and `-w`
There are two additional aliases used to (re)set up the bare git setup.
- `.ginit` creates the bare git repository in `$DOT_FILES` directory.
- `.gclone` will clone the repository set in `$DOT_ORIGIN` into the `$DOT_FILES` directory
## requirements
- `EDITOR` set to your liking
- [git](https://git-scm.com/)
- [bat](https://github.com/sharkdp/bat)
- [fzf](https://github.com/junegunn/fzf) (optional)
- [lazygit](https://github.com/jesseduffield/lazygit) (optional)
- [gitui](https://github.com/extrawurst/gitui) (optional)
## installation
1. clone this repository or simply copy the [aliases.sh](./aliases.sh)
2. add some config sauce to your shell initialization (.i.e. `.zshrc` or `.bashrc`). The `DOT_FILES` and `DOT_HOME` variables **must be set** for the aliases.sh to load!
```bash
export DOT_FILES="${HOME}/.dotfiles"
export DOT_HOME="${HOME}"
export DOT_ORIGIN="git@github.com:user/your-dotfiles-repo.git" # optional
source <path to aliases.sh>`
```
3. restart your shell or `source ~/.zshrc` or `source ~/.bashrc`
4. run `.ginit` or `.gclone` (see the *initial clone setup* below, if cloning)
5. `.gc <branch>` to checkout the config files
## initial clone cleanup
Existing config files will prevent checking out the files. To list the files causing the checkout to fail, run the following.
```bash
.g checkout 2>&1|grep -E '^\s'|cut -f2-|xargs -I {} echo "{}"
```
To remove all the conflicting files, simply change the `echo` in the above command to `rm`. **This will delete files, so be sure you want to remove them.** Once the files are removed the checkout will succeed.
## alternatives
- [GNU Stow](https://www.gnu.org/software/stow)
- [dotbare](https://github.com/kazhala/dotbare) (this is close in spirit to dotGit, and can be used together with dotGit from what I can tell)
- [Home Manager](https://github.com/nix-community/home-manager)

46
aliases.sh Normal file
View file

@ -0,0 +1,46 @@
[[ ! "${DOT_FILES}" ]] && echo "NOT setting dotGit aliases, since DOT_FILES not set." && return
[[ ! "${DOT_HOME}" ]] && echo "NOT setting dotGit aliases, since DOT_HOME not set." && return
alias .g='git --git-dir=${DOT_FILES} --work-tree=${DOT_HOME}'
alias .ga='.g add'
alias .gc='.g commit'
alias .gco='.g checkout'
alias .gd='.g diff'
alias .gss='.g status --short'
alias .gp='.g push'
alias .gl='.g pull'
alias .glo='.g log --oneline --decorate'
alias .glg='.g log --stat'
alias .glgp='.g log --stat --patch'
# shellcheck disable=SC2142,SC215
alias .ge='_dotgit_ge(){
cd ${DOT_HOME}
FILE=$( Q="$@"; .g ls-files --full-name |
fzf --preview "bat -n --color=always {}" -q "${Q}")
[[ "$FILE" ]] && $EDITOR "${FILE}"
cd ${OLDPWD}
}; _dotgit_ge'
if [[ $(command -v fzf) ]]; then
# shellcheck disable=SC2142
alias .gg='_dotgit_gg(){
cd ${DOT_HOME}
.g grep --full-name --color=always -n "$@" |
fzf -0 --ansi -d ":" --bind "enter:execute($EDITOR +{2} {1})" \
--preview "bat -n -H {2} --color=always {1}" \
--preview-window "right,60%,<60(down,75%),+{2}/2"
cd ${OLDPWD}
}; _dotgit_gg'
else
alias .gg='.g grep'
fi
alias .ginit='git init --bare "${DOT_FILES}"; .g config --local status.showUntrackedFiles no'
[[ -n "$DOT_ORIGIN" ]] && alias .gclone='git clone --bare "${DOT_ORIGIN}" "${DOT_FILES}"; .g config --local status.showUntrackedFiles no'
# if lazygit or gitui are avaiable, we set up a .lazygit and .gitui
[[ $(command -v lazygit) ]] &&
alias .lazygit='lazygit -g ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}'
[[ $(command -v gitui) ]] &&
alias .gitui='gitui -d ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}'