.github/workflows | ||
helper | ||
scripts | ||
tests | ||
.travis.yml | ||
buildspec.yml | ||
Dockerfile | ||
dotbare | ||
LICENSE | ||
README.md | ||
shellcheck.sh |
dotbare
Introduction
dotbare is a command line utility to help you manage your dotfiles. It wraps around git bare repository and heavily utilise fzf for better user expereince. It is inspired by forgit, a git wrapper that utilise fzf for interactive expereince. dotbare uses a different implementation approach and focuses on managing and interacting with your dotfiles.
Core characteristics:
- No symlink
- Easy setup/remove
- Customization
- Minimal dependency
- Easy migration
- Zero learning curve
- Manage dotfiles in any directory
You could find out how git bare repository could be used for managing dotfiles here.
Why
It has always been a struggle for me to get started with managing dotfiles using version control, as some other tools like "gnu stow" really scares me off with all the symlinks, until I found out about using git bare repository for managing dotfiles, zero symlinks, minimal setup required and you keep your dotfiles at the location they should be.
However, it has always lack some interactive expereince as it does not provide any auto completion on git commands nor file paths by default. It is also a pain when migrating the setup over to another system as you will have to manully resolve all the git checkout issues.
dotbare solves the above problems by providing a series of scripts starts with a prefix f (e.g. dotbare fadd, dotbare flog etc) that will enable a interactive expereince by processing all the git information from your bare repository and display it through fzf. dotbare also comes with the ability to migrate easily to other systems with one single command without having user to do any extra work.
Getting started
Install
- Clone the repository (change ~/.dotbare to the location of your preference)
git clone https://github.com/kazhala/dotbare.git ~/.dotbare
- Add dotbare to your PATH (below is only an example, put PATH into your appropriate shellrc file,
$HOME/.zshrc
etc)
echo "PATH=$PATH:$HOME/.dotbare" >> "$HOME"/.bashrc
Dependencies
- Required dependency
- fzf
- bash(You don't need to run bash, but dotbare does require you have bash in your system)
- Optional dependency
- tree (Will provide a directory tree view when finding directory)
# if you are on macos brew install tree
- tree (Will provide a directory tree view when finding directory)
Setup
Treat dotbare as normal
git
commands. For interactive commands, check out usage
- init git bare repository
Note: by default,
dotbare finit
will set up a bare repo in $HOME/.cfg, to customize location and various other settings, checkout customization
dotbare finit
- add dotfiles you want to track
dotbare fadd -f
# or
dotbare add [FIELNAME]
# add entire repository like .config
dotbare fadd -d
# or
dotbare add [DIRECTORY]
- commit changes and push to remote
dotbare commit -m "First commit"
dotbare remote add origin [URL]
dotbare push -u origin master
Migration
Migrating from normal git bare repository
- follow the steps in install to install dotbare
- check your current alias of git bare reference
# Below is an example alias, check yours for reference
alias config=/usr/bin/git --git-dir=$HOME/.cfg --work-tree=$HOME
- set env variable for dotbare
export DOTBARE_DIR="$HOME/.cfg"
export DOTBARE_TREE="$HOME"
- optionally you could alias config to dotbare so you keep your muscle memory
alias config=dotbare
Migrating dotbare to a new system
- follow the steps in install to install dotbare
- set env variable to let dotbare know where to init dotbare, backup etc.
Copy below to your cmd line and set them temporarily
export DOTBARE_DIR="$HOME/.cfg"
export DOTBARE_TREE="$HOME"
- give dotbare your remote URL and let it handle the rest
dotbare finit -u https://github.com/kazhala/dotfiles.git
Migrating from gnu stow
I haven't used gnu stow but I would advise to stay with gnu stow if you are happy with it. If you want to give dotbare a try, as long as your remote repository resembles the structure of your home folder (reference what I mean in my repo)
dotbare finit -u [URL]
Test it in docker
If you know docker, I stronly suggest you give dotbare a try in docker, especially when it comes to first time migration.
docker pull kazhala/dotbare:latest
docker container run -it --rm --name dotbare kazhala/dotbare:latest
Customization
dotbare could be customized through modification of env variables.
Note: customization of fzf is not covered here, you should checkout their wiki.
DOTBARE_DIR
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. Change this to location or rename the directory to your liking.
# Default
DOTBARE_DIR="$HOME/.cfg"
DOTBARE_TREE
This is the working tree for the git bare repository, meaning this is where the version control will take place, I don't recommand changing this one unless ALL of your config file is in something like $XDG_CONFIG_HOME.
# Default
DOTBARE_TREE="$HOME"
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.
It is also used by dotbare finit -u [URL]
, when there is checkout conflict, dotbare will
automatically backup conflicted files to this location. You probably shouldn't change this
location.
# Default
# 2. If XDG_DATA_HOME exist, use XDG_DATA_HOME/dotbare
# 3. otherwise, use $HOME/.local/share/dotbare
DOTBARE_BACKUP="${XDG_DATA_HOME:-$HOME/.local/share}/dotbare"
EDITOR
This is probably already set in your ENV. dotbare uses this variable to determine
which editor to use when running dotbare fedit
.
# Default
EDITOR="vim"
DOTBARE_KEY
This variable set default keybinds for fzf in dotbare. You could checkout a list of keybinds to set here.
# Default
DOTBARE_KEY="
--bind=alt-a:toggle-all # toggle all selection
--bind=alt-j:jump # label jump mode, sort of like easymotion
--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.
# Default is unset
# More settings checkout fzf man page and their wiki
# You could also take a look at my fzf config
# https://github.com/kazhala/dotfiles/blob/5507a2dea4f4a420e6d65a423abaa247521f89a8/.zshrc#L56
Commands
dotbare doesn't have a man page yet, will come later, for help, type dotbare [COMMAND] -h
Checkout all available scripts and their help manual
# run dotbare without any arguments
dotbare
# or checkout help for dotbare
dotbare -h
dotbare help
# for normal git help
dotbare --help
fedit
List all tracked dotfiles and edit the selected file through $EDITOR, it also support edit commits through interactive rebase.
fadd
Stage modified files, stage new file or directory interactivly through fzf.
By default dotbare fadd
will list modified files and stage them on selection.
freset
Reset/unstage file, reset HEAD back to certain commits and reset certain file back to certain
commits. Demo only shows unstaging files, detailed usage checkout dotbare freset -h
.
fcheckout
Checkout files/commit/branch interactivly, default behavior is to checkout files back to HEAD (Reset file changes back to HEAD).
flog
Interactive log viewer that will prompt you with a menu after selecting a commit. Allows edit, reset, revert and checkout the selected commits.
fstash
View and manage your stash interactivly. Pass -p
flag for pop
, otherwise by default,
stash apply
is used under the hood. Pass -d
flag for deleting a stash.
fbackup
Backup all of the tracked dotfiles to DOTBARE_BACKUP directory. This is used also by
dotbare finit -u [URL]
for backing up conflicted checkout files.
Background
dotbare was initially part of my personal scripts, however as the number of scripts grows, I feel like is more appropriate to make a dedicated project for it. I've just started scripting for a few months, so there must be a lot of improvements that could be made, please help me out by firing up issues and any PR is welcome.