2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-04 06:00:45 +00:00
dotbare/README.md

449 lines
16 KiB
Markdown
Raw Normal View History

2020-04-06 05:07:59 +00:00
# dotbare
2020-05-17 01:54:07 +00:00
![CI Status](https://github.com/kazhala/dotbare/workflows/CI/badge.svg)
2021-08-16 03:18:00 +00:00
![AWSCodeBuild](https://codebuild.ap-southeast-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiVVo4eUt6T0JGSFU1M1plVml0Y1dOWkJnaTV0eWZNNm5uY043Z3MwaUY2aUhaTHllQklhaVFiWmxIcTNVc0ZFRFhwbFdpZ3dsb3RMZFU0aDk3S1FUQUpRPSIsIml2UGFyYW1ldGVyU3BlYyI6ImVUdjloSlNTa3NyTUJVemIiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
2020-05-18 12:11:30 +00:00
![Platform](https://img.shields.io/badge/platform-macos%20%7C%20linux-blue)
2020-05-17 04:32:11 +00:00
![License](https://img.shields.io/badge/license-MIT-green)
2020-05-11 05:51:35 +00:00
2020-05-17 04:32:11 +00:00
## Introduction
2020-08-04 01:08:25 +00:00
`dotbare` is a command line utility to help manage dotfiles and or as a generic fuzzy git client. As a dotfile management tool,
it wraps around git bare repository, query git information from it and display them through [fzf](https://github.com/junegunn/fzf) for an
interactive experience. It is originally inspired by [forgit](https://github.com/wfxr/forgit), a git wrapper using fzf.
`dotbare` uses a different implementation approach and focuses on managing and interacting with system dotfiles. Because
of the flexible implementation of `dotbare`, it can easily integrate with symlink/GNU stow setup or even as a generic
fuzzy git client to use in any git repository.
2020-10-21 01:50:49 +00:00
As a generic fuzzy git client (using `--git` flag), `dotbare` dynamically determine the top level `.git` folder and process git information
2020-08-04 01:08:25 +00:00
and perform git operation in the current working tree.
2020-05-17 04:32:11 +00:00
You could find out how git bare repository could be used for managing dotfiles [here](https://www.atlassian.com/git/tutorials/dotfiles).
Or a [video](https://www.youtube.com/watch?v=tBoLDpTWVOM&t=288s) explanation that helped me to get started. If you are currently
2020-07-09 01:04:31 +00:00
using a symlink/GNU stow setup, checkout how to integrate `dotbare` with them [here](#migrating-from-a-generic-symlink-setup-or-gnu-stow).
2020-05-17 04:32:11 +00:00
2020-08-04 01:08:25 +00:00
Select and edit dotfiles.
![fedit](https://user-images.githubusercontent.com/43941510/87669391-37f28180-c7b1-11ea-907d-3b26f363a279.png)
2020-07-15 01:05:39 +00:00
Stage and unstage dotfiles.
![fstat](https://user-images.githubusercontent.com/43941510/87669408-43de4380-c7b1-11ea-8a31-fc702eb69804.png)
2020-07-15 01:05:39 +00:00
Interactive log viewer.
![flog](https://user-images.githubusercontent.com/43941510/87669399-3e80f900-c7b1-11ea-9bfa-5db31c4307c3.png)
For more capabilities and commands, checkout [wiki](https://github.com/kazhala/dotbare/wiki/Commands).
2020-05-17 05:38:31 +00:00
2020-05-17 04:32:11 +00:00
## Why
It has always been a struggle for me to get started with managing dotfiles using version control,
2020-07-09 01:04:31 +00:00
as tools like "GNU stow" really scares me off with all the symlinks, until I found
2020-05-17 04:32:11 +00:00
out about using git bare repository for managing dotfiles, zero symlinks, minimal setup
2020-07-09 01:04:31 +00:00
required while keeping dotfiles at the location they should be.
2020-05-17 04:32:11 +00:00
2020-05-19 13:17:19 +00:00
However, it has always lack some interactive experience as it does not provide any auto
2020-05-17 04:32:11 +00:00
completion on git commands nor file paths by default. It is also a pain when migrating the setup over
2020-05-19 13:17:19 +00:00
to another system as you will have to manually resolve all the git checkout issues.
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
`dotbare` solves the above problems by providing a series of scripts starts with a prefix f
2020-05-19 13:17:19 +00:00
(e.g. `dotbare fadd`, `dotbare flog` etc) that will enable a interactive experience by processing
all the git information and display it through fzf. In addition, `dotbare` also comes with command line completion
that you could choose to either to complete `git` commands or `dotbare` commands.
`dotbare` also comes with the ability to integrate with GNU stow or any symlink set up as long as you are using git.
2020-08-04 01:08:25 +00:00
It is easy to migrate to any system with minimal set up required. In addition, with a simple flag `--git`, you can
now also use `dotbare` as a generic fuzzy git client to manage any git repository.
2020-05-17 04:32:11 +00:00
## Install
2020-05-17 04:32:11 +00:00
### zsh
2020-05-17 04:32:11 +00:00
`dotbare` should work with any zsh plugin manager, below is only demonstration. Checkout [wiki](https://github.com/kazhala/dotbare/wiki/Completion#zsh)
about how to enable completion for zsh.
2020-05-22 03:05:20 +00:00
#### zinit
2020-05-17 04:32:11 +00:00
```sh
zinit light kazhala/dotbare
```
2020-05-17 04:32:11 +00:00
#### Fig
[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
Install `dotbare` in just one click.
<a href="https://fig.io/plugins/other/dotbare_kazhala" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
#### oh-my-zsh
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
- Clone the repository in to [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) plugins directory.
```sh
git clone https://github.com/kazhala/dotbare.git $HOME/.oh-my-zsh/custom/plugins/dotbare
```
2020-07-09 01:04:31 +00:00
- Activate the plugin in `~/.zshrc`.
2020-05-17 04:32:11 +00:00
```zsh
plugins=( [plugins...] dotbare [plugins...] )
```
2020-05-22 03:05:20 +00:00
#### Antigen
2020-05-22 03:05:20 +00:00
```sh
antigen bundle kazhala/dotbare
```
#### Manual
2020-07-09 01:04:31 +00:00
- Clone the repository (change ~/.dotbare to the location of your preference).
2020-05-22 05:32:58 +00:00
```sh
git clone https://github.com/kazhala/dotbare.git ~/.dotbare
2020-05-22 05:32:58 +00:00
```
2020-07-09 01:04:31 +00:00
- Put below into `.zshrc`.
2020-05-22 05:32:58 +00:00
```sh
source ~/.dotbare/dotbare.plugin.zsh
```
### bash
`dotbare` comes with a `dotbare.plugin.bash` which contains the command line completion
function for both `git` and `dotbare`, checkout [wiki](https://github.com/kazhala/dotbare/wiki/Completion#bash)
about how to enable it.
2020-06-06 01:48:28 +00:00
2020-07-09 01:04:31 +00:00
- Clone the repository (change ~/.dotbare to the location of your preference).
2020-05-22 05:32:58 +00:00
```sh
git clone https://github.com/kazhala/dotbare.git ~/.dotbare
2020-05-22 05:32:58 +00:00
```
2020-07-09 01:04:31 +00:00
- Put below into `.bashrc` or `.bash_profile`.
2020-05-22 05:32:58 +00:00
```sh
source ~/.dotbare/dotbare.plugin.bash
2020-05-22 05:32:58 +00:00
```
2020-05-22 03:05:20 +00:00
### others
2020-07-09 01:04:31 +00:00
1. Clone the repository (change ~/.dotbare to the location of your preference).
```sh
git clone https://github.com/kazhala/dotbare.git ~/.dotbare
```
2020-07-09 01:04:31 +00:00
2. Add `dotbare` to your PATH.
```sh
2020-06-06 04:42:35 +00:00
# This is only an example command for posix shell
# If you are on fish, use the fish way to add dotbare to your path
export PATH=$PATH:$HOME/.dotbare
```
2020-07-09 01:04:31 +00:00
Or you could create a alias which point to dotbare executable.
```sh
alias dotbare="$HOME/.dotbare/dotbare"
```
## Getting started
2020-05-17 04:32:11 +00:00
### Dependencies
You will need git on the system for obvious reasons..and because `dotbare` is written in bash,
it will require you to have bash in the system (You don't need to run bash, just need to be in the system).
#### Required dependency
- [fzf](https://github.com/junegunn/fzf)
2020-05-19 23:21:25 +00:00
#### Optional dependency
2020-05-19 23:21:25 +00:00
- [tree](https://linux.die.net/man/1/tree) (Provide a directory tree view when finding directory)
2020-05-17 04:32:11 +00:00
```sh
# if you are on macos
brew install tree
```
- [bat](https://github.com/sharkdp/bat) or [highlight](http://www.andre-simon.de/doku/highlight/en/highlight.php) or [coderay](https://github.com/rubychan/coderay)
or [rougify](https://github.com/rouge-ruby/rouge) (Syntax highlighting when previewing files, otherwise cat will be used)
- [delta](https://github.com/dandavison/delta) or [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy)
or any diff tools of your choice (Fancy git diff preview like in the screen shot)
2020-07-09 01:04:31 +00:00
2020-05-17 04:32:11 +00:00
### Setup
2020-07-09 01:04:31 +00:00
1. init git bare repository.
2020-05-17 04:32:11 +00:00
Note: by default, `dotbare finit` will set up a bare repository in \$HOME/.cfg, to customize
2020-05-19 23:21:25 +00:00
location and various other settings, checkout [customization](#customization)
```sh
dotbare finit
```
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
2. add dotfiles you want to track.
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
Treat `dotbare` as normal `git` commands.
2020-05-19 23:21:25 +00:00
```sh
2020-05-19 23:21:25 +00:00
dotbare fadd -f
# or
2021-08-15 14:35:52 +00:00
dotbare add [FILENAME]
2020-05-19 23:21:25 +00:00
2020-07-09 01:04:31 +00:00
# add entire repository like .config directory
2020-05-19 23:21:25 +00:00
dotbare fadd -d
# or
dotbare add [DIRECTORY]
```
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
3. commit changes and push to remote.
2020-05-17 04:32:11 +00:00
2020-05-19 23:21:25 +00:00
```sh
dotbare commit -m "First commit"
dotbare remote add origin [URL]
dotbare push -u origin master
```
2020-05-17 04:32:11 +00:00
### Migration
#### Migrating from normal git bare repository
2020-07-09 01:04:31 +00:00
1. follow the steps in [install](#install) to install `dotbare`.
2. check your current alias of git bare reference.
2020-05-17 04:32:11 +00:00
2020-05-19 23:21:25 +00:00
```sh
# Below is an example alias, check yours for reference
alias config=/usr/bin/git --git-dir=$HOME/.cfg --work-tree=$HOME
```
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
3. set env variable for `dotbare`.
2020-05-17 04:32:11 +00:00
2020-05-19 23:21:25 +00:00
```sh
export DOTBARE_DIR="$HOME/.cfg"
export DOTBARE_TREE="$HOME"
```
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
4. remove the original alias and use `dotbare`.
2020-07-09 01:04:31 +00:00
5. optionally you could alias `config` to `dotbare` so you keep your muscle memory.
2020-05-17 04:32:11 +00:00
2020-05-19 23:21:25 +00:00
```sh
alias config=dotbare
```
2020-05-17 04:32:11 +00:00
#### Migrating from a generic symlink setup or GNU stow
##### Keep your current setup but integrate dotbare
2020-07-09 01:04:31 +00:00
1. follow the steps in [install](#install) to install `dotbare`.
2. set environment variable so that `dotbare` knows where to look for git information.
2020-05-17 04:32:11 +00:00
2020-05-19 23:21:25 +00:00
```sh
# e.g. I have all my dotfiles stored in folder $HOME/.myworld and symlinks all of them to appropriate location.
# export DOTBARE_DIR="$HOME/.myworld/.git"
# export DOTBARE_TREE="$HOME/.myworld"
2020-07-09 01:04:31 +00:00
export DOTBARE_DIR=<Path to your .git location>
2020-05-19 23:21:25 +00:00
export DOTBARE_TREE=<Path to directory which contains all your dotfiles>
```
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
3. Run `dotbare` anywhere in your system.
Note: with this method, you do not run `dotbare finit -u [URL]` when migrating to new system,
you will do your normal migration steps and then do the above steps.
##### Complete migration
2020-07-09 01:04:31 +00:00
While bare method is great and easy, I recommend keeping your current symlink/GNU stow setup and integrate it with `dotbare` instead of a migration.
If you are really happy with `dotbare`, as long as your remote repository resembles the structure of your home holder
(reference what I mean in my [repo](https://github.com/kazhala/dotfiles.git)), simply run the command below.
2020-07-09 01:04:31 +00:00
**Disclaimer**: I have not done nearly enough test on this as I don't personally use symlink/GNU stow setup, migrate this way with caution.
I recommend you test this migration in docker, see [Test-it-in-docker](#test-it-in-docker).
2020-05-17 04:32:11 +00:00
```sh
# dotbare will replace all symlinks with the original file and a bare repository will be created at $DOTBARE_DIR
dotbare finit -u [URL]
2020-05-17 04:32:11 +00:00
```
#### Migrating dotbare to a new system
2020-05-17 04:32:11 +00:00
2020-07-09 01:04:31 +00:00
1. follow the steps in [install](#install) to install `dotbare`.
2. Optionally set env variable to customize `dotbare` location (checkout [customization](#customization)).
2020-05-17 04:32:11 +00:00
2020-05-19 23:21:25 +00:00
```sh
export DOTBARE_DIR="$HOME/.cfg"
export DOTBARE_TREE="$HOME"
```
2020-07-09 01:04:31 +00:00
3. give `dotbare` your remote URL and let it handle the rest.
2020-05-19 23:21:25 +00:00
```sh
dotbare finit -u https://github.com/kazhala/dotfiles.git
```
2020-05-17 04:32:11 +00:00
2020-05-17 12:10:34 +00:00
#### Test it in docker
When you are about to do migrations, I strongly suggest you give the migration a try in docker first.
2020-07-09 01:04:31 +00:00
The `dotbare` image is based on alpine linux.
2020-05-17 12:10:34 +00:00
```sh
docker pull kazhala/dotbare:latest
docker container run -it --rm --name dotbare kazhala/dotbare:latest
```
2020-05-17 04:32:11 +00:00
2020-05-20 01:22:20 +00:00
![migration demo](https://user-images.githubusercontent.com/43941510/82392054-3ee96600-9a86-11ea-9ea9-158452c62d06.gif)
2020-05-17 12:10:34 +00:00
## Customization
2020-07-09 01:04:31 +00:00
`dotbare` could be customized through modification of env variables.
2020-05-18 11:41:37 +00:00
2020-07-09 01:04:31 +00:00
Note: customization of fzf is not covered here, checkout their [wiki](https://github.com/junegunn/fzf/wiki).
2020-05-18 11:41:37 +00:00
### DOTBARE_DIR
2020-07-09 01:04:31 +00:00
This is the location of the bare repository, `dotbare` will look for this directory
and query git information or it will create this directory when initializing `dotbare`.
2020-05-18 11:41:37 +00:00
Change this to location or rename the directory to your liking.
If you are using symlink/GNU stow setup, set this variable point to the .git folder
within your dotfile directory.
2020-05-18 11:41:37 +00:00
```sh
2020-07-09 01:04:31 +00:00
# Default value
2020-07-04 09:37:42 +00:00
export DOTBARE_DIR="$HOME/.cfg"
2020-05-18 11:41:37 +00:00
```
### DOTBARE_TREE
This is the working tree for the git bare repository, meaning this is where the version
2020-05-19 13:17:19 +00:00
control will take place. I don't recommend changing this one unless **ALL** of your config
2020-07-09 01:04:31 +00:00
file is in something like \$XDG_CONFIG_HOME. If you are using symlink/GNU stow setup,
set this variable to point to the folder containing all of your dotfiles.
2020-05-18 11:41:37 +00:00
```sh
2020-07-09 01:04:31 +00:00
# Default value
2020-07-04 09:37:42 +00:00
export DOTBARE_TREE="$HOME"
2020-05-18 11:41:37 +00:00
```
### DOTBARE_BACKUP
This variable is used to determine where to store the backup of your files. It is used
mainly by `dotbare fbackup` which will back up all of your tracked dotfiles into this location.
2020-07-09 01:04:31 +00:00
It is also used by `dotbare finit -u [URL]`, when there is checkout conflict, `dotbare` will
automatically backup conflicted files to this location.
2020-05-18 11:41:37 +00:00
```sh
2020-07-09 01:04:31 +00:00
# Default value
2020-07-04 09:37:42 +00:00
export DOTBARE_BACKUP="${XDG_DATA_HOME:-$HOME/.local/share}/dotbare"
2020-05-18 11:41:37 +00:00
```
### EDITOR
2020-07-09 01:04:31 +00:00
This is probably already set in your ENV. `dotbare` uses this variable to determine
2020-05-18 11:41:37 +00:00
which editor to use when running `dotbare fedit`.
```sh
2020-07-09 01:04:31 +00:00
# Default value
2020-07-04 09:37:42 +00:00
export EDITOR="vim"
2020-05-18 11:41:37 +00:00
```
### DOTBARE_KEY
2020-07-09 01:04:31 +00:00
This variable set default keybinds for fzf in `dotbare`. You could checkout a list of keybinds
2020-05-18 11:41:37 +00:00
to set [here](https://github.com/junegunn/fzf/blob/97a725fbd0e54cbc07e4d72661ea2bd2bb7c01c1/man/man1/fzf.1#L648).
```sh
2020-07-09 01:04:31 +00:00
# Default value
2020-07-04 09:37:42 +00:00
export DOTBARE_KEY="
2020-05-18 11:41:37 +00:00
--bind=alt-a:toggle-all # toggle all selection
--bind=alt-j:jump # label jump mode, sort of like vim-easymotion
2020-05-18 11:41:37 +00:00
--bind=alt-0:top # set cursor back to top
--bind=alt-s:toggle-sort # toggle sorting
--bind=alt-t:toggle-preview # toggle preview
"
```
### DOTBARE_FZF_DEFAULT_OPTS
Customize fzf settings for dotbare. This is useful when you want a different
fzf behavior from your normal system fzf settings.
```sh
2020-07-09 01:04:31 +00:00
# By default this variable is not set
2020-05-18 11:41:37 +00:00
# More settings checkout fzf man page and their wiki
# Example: if you want your preview window for dotbare to be bigger
export DOTBARE_FZF_DEFAULT_OPTS="--preview-window=right:65%"
2020-05-18 11:41:37 +00:00
```
2020-07-09 01:04:31 +00:00
### DOTBARE_PREVIEW
2020-05-17 12:10:34 +00:00
2020-07-09 01:04:31 +00:00
This variable determines the preview command for file previews. By default, the preview is automatically determined
using fall back (bat -> highlight -> coderay -> rougify -> cat). Set this variable to control the preview command if
you have a specific preference or if you want extra flags/settings. Reference [here](https://github.com/kazhala/dotbare/blob/master/helper/preview.sh).
2020-05-17 05:38:31 +00:00
```sh
2020-07-09 01:04:31 +00:00
# By default this value is not set, dotbare uses a fall back method to determine which command to use.
# Make sure to have "{}" included when customizing it, the preview script substitute "{}" for actual filename.
# Example: enable line number for cat command
2020-07-09 01:04:31 +00:00
export DOTBARE_PREVIEW="cat -n {}"
2020-05-17 05:38:31 +00:00
```
2020-07-09 01:04:31 +00:00
### DOTBARE_DIFF_PAGER
2020-07-09 01:04:31 +00:00
This variable controls the diff output pager in previews like `dotbare flog`, `dotbare fadd` etc. It will read the value
of `git config core.pager` to determine the pager to use. If you have a specific preference for `dotbare` or have not set
the global pager in git config, you could use this variable to customize the diff preview.
2020-05-19 13:06:11 +00:00
2020-07-09 01:04:31 +00:00
```sh
# By default this value uses fall back (git config core.pager -> cat)
export DOTBARE_DIFF_PAGER="delta --diff-so-fancy --line-numbers"
```
2020-05-19 23:21:25 +00:00
2020-07-09 01:04:31 +00:00
## Usage
2020-05-20 00:27:08 +00:00
All usage and commands are documented in **[wiki](https://github.com/kazhala/dotbare/wiki/Commands)**.
2020-05-20 00:27:08 +00:00
2020-07-15 01:05:39 +00:00
- [Commands](https://github.com/kazhala/dotbare/wiki/Commands)
- [Completion](https://github.com/kazhala/dotbare/wiki/Completion)
- [Custom Scripts and API](https://github.com/kazhala/dotbare/wiki/Custom-Scripts)
- [Tips and Tricks](https://github.com/kazhala/dotbare/wiki/Tips-and-Tricks)
2020-07-09 01:04:31 +00:00
## Changes
2020-08-04 01:08:25 +00:00
Latest changes are documented in [CHANGELOG](https://github.com/kazhala/dotbare/blob/master/CHANGELOG.md).
2020-05-19 13:06:11 +00:00
## Testing
2020-07-09 01:04:31 +00:00
`dotbare` is unit tested using [bats](https://github.com/bats-core/bats-core). Mock tests are implemented using PATH override method.
2020-07-17 00:36:40 +00:00
This is documented [here](https://github.com/kazhala/dotbare/blob/master/tests/README.md) for better readability and extensibility.
2020-05-19 23:21:25 +00:00
Not all functions have 100% coverage and lots of user interaction cannot be effectively tested, please fire up issues if something went wrong.
2020-05-19 13:06:11 +00:00
I've added AWSCodeBuild to CI/CD to build the docker image. It is mainly for my personal practice. If you are interested in what's happening in AWSCodeBuild
2020-05-19 13:06:11 +00:00
you could checkout my cloudformation [template](https://github.com/kazhala/AWSCloudFormationStacks/blob/master/CICD_dotbare.yaml).
## Contributing
2020-07-17 00:36:40 +00:00
Checkout out [CONTRIBUTING.md](https://github.com/kazhala/dotbare/blob/master/CONTRIBUTING.md) to see how you could contribute to `dotbare`. PRs are
welcome and I'm happy to improve/extend `dotbare`'s functionality.
2020-05-19 13:06:11 +00:00
Don't forget to leave a star :)
2020-05-19 13:06:11 +00:00
2020-05-20 01:22:20 +00:00
## Background
2020-07-09 01:04:31 +00:00
`dotbare` was initially part of my personal scripts, I had a hard time sharing those scripts
2020-05-20 01:22:20 +00:00
and as the number of scripts grows, I feel like is more appropriate to make a dedicated project
for it. I hope you find it useful and enjoy it, thanks!
2020-05-19 13:06:11 +00:00
## Credit
2020-05-20 00:27:08 +00:00
- credit to [forgit](https://github.com/wfxr/forgit) for inspiration.
- credit to [fzf](https://github.com/junegunn/fzf) for fzf and the preview script from fzf.vim.
- credit to [OMZ](https://github.com/ohmyzsh/ohmyzsh) for upgrading method.
2020-05-20 00:27:08 +00:00
- credit to [this](https://www.atlassian.com/git/tutorials/dotfiles) post for step by step guide of setting up git bare repo.
2020-06-06 04:42:35 +00:00
- credit to [this](https://www.youtube.com/watch?v=tBoLDpTWVOM&t=288s) video for introducing git bare repo.
2020-05-20 03:46:36 +00:00
## Demo
2020-07-09 01:04:31 +00:00
You could find some more demo [here](https://github.com/kazhala/dotbare/issues/1)
2020-05-20 03:46:36 +00:00
[![asciicast](https://asciinema.org/a/332231.svg)](https://asciinema.org/a/332231)