Compare commits
No commits in common. "main" and "track-file" have entirely different histories.
main
...
track-file
3 changed files with 30 additions and 113 deletions
15
.build.yml
15
.build.yml
|
@ -1,15 +0,0 @@
|
|||
image: alpine/latest
|
||||
packages:
|
||||
- git
|
||||
- openssh
|
||||
secrets:
|
||||
- 0639564d-6995-4e2e-844b-2f8feb0b7fb1
|
||||
environment:
|
||||
repo: autoyadm
|
||||
github: git@github.com:ficcdaf/autoyadm.git
|
||||
tasks:
|
||||
- mirror: |
|
||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||
cd "$repo"
|
||||
git remote add github "$github"
|
||||
git push --mirror github
|
109
README.md
109
README.md
|
@ -1,48 +1,19 @@
|
|||
# AutoYADM
|
||||
|
||||
<!--toc:start-->
|
||||
|
||||
- [AutoYADM](#autoyadm)
|
||||
- [Features](#features)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Tracking](#tracking)
|
||||
- [Ignoring Certain Files](#ignoring-certain-files)
|
||||
- [Committing & Pushing](#committing-pushing)
|
||||
- [Calling AutoYADM Automatically](#calling-autoyadm-automatically)
|
||||
- [Contributing](#contributing)
|
||||
|
||||
<!--toc:end-->
|
||||
|
||||
AutoYADM is a small shell utility to automate the process of managing dotfiles
|
||||
with [YADM](https://github.com/yadm-dev/yadm) by allowing the user to define a
|
||||
list of files & directories to be automatically added, committed and pushed
|
||||
whenever the script is run. **Most notably, AutoYADM accounts for newly created
|
||||
files previously untracked by YADM.**
|
||||
|
||||
The benefits of this approach:
|
||||
|
||||
1. Robust version control thanks to YADM and Git.
|
||||
2. You won't forget to commit new files in important folders.
|
||||
3. Maintain control over paths to auto-commit, and paths to only manually
|
||||
commit.
|
||||
|
||||
I have personally been using AutoYADM to sync my dotfiles between devices
|
||||
without any problems since October 2024.
|
||||
AutoYADM is a small shell utility to automate the process of managing dotfiles with [YADM](https://github.com/yadm-dev/yadm) by allowing the user to define a list of files & directories to be automatically added, committed and pushed whenever the script is run. **Most notably, AutoYADM accounts for newly created files previously untracked by YADM.**
|
||||
|
||||
## Features
|
||||
|
||||
- Configure a list of files & directories to be automatically tracked by YADM.
|
||||
- Configure a list of files & directories to be automatically tracked by YADM
|
||||
- Tracked directories will also track any new files inside them!
|
||||
- Automatically add, commit, and push tracked paths.
|
||||
- `.ignore`/`.gitignore` support with `fd`.
|
||||
- Automatically add, commit, and push tracked paths
|
||||
|
||||
## Installation
|
||||
|
||||
Simply clone the repository:
|
||||
|
||||
```Bash
|
||||
git clone https://git.ficd.sh/ficd/autoyadm
|
||||
git clone git@github.com:ficcdaf/autoyadm.git
|
||||
```
|
||||
|
||||
You may consider adding aliases to your shell configuration:
|
||||
|
@ -54,44 +25,36 @@ alias yadmadd="/path/to/autoyadm/yadmadd.sh"
|
|||
alias autoyadm="AUTOYADMPUSH=1 /path/to/autoyadm/autoyadm.sh"
|
||||
```
|
||||
|
||||
**Dependencies**:
|
||||
<details>
|
||||
<summary>Click to see dependencies</summary>
|
||||
|
||||
- [YADM](https://github.com/yadm-dev/yadm)
|
||||
- `git`
|
||||
- `fd` (optional, but recommended)
|
||||
- fallback to `find` otherwise
|
||||
- `openssh` (required for pushing)
|
||||
- Bash/Zsh
|
||||
- `openssh` (optional)
|
||||
|
||||
</details>
|
||||
|
||||
## Usage
|
||||
|
||||
> Note: The following assumes you have created shell aliases to the two scripts.
|
||||
> You may, of course, simply call them directly.
|
||||
> Note: The following assumes you have created shell aliases to the two scripts. You may, of course, simply call them directly.
|
||||
|
||||
### Tracking
|
||||
|
||||
AutoYADM maintains a list of files and directories for automatic tracking.
|
||||
_**All** children of tracked directories will be tracked, including newly
|
||||
created, previously untracked files._ For example, if you add your Neovim
|
||||
configuration at `~/.config/nvim` to tracking, then any new files you create
|
||||
inside that folder will automatically be added and committed by AutoYADM.
|
||||
AutoYADM maintains a list of files and directories for automatic tracking. _**All** children of tracked directories will be tracked, including newly created, previously untracked files._ For example, if you add your Neovim configuration at `~/.config/nvim` to tracking, then any new files you create inside that folder will automatically be added and committed by AutoYADM.
|
||||
|
||||
The tracking file is stored in `~/.config/yadm/tracked`. `$XDG_CONFIG_HOME` is
|
||||
respected. The file will be automatically created if it doesn't already exist.
|
||||
You can even add it to tracking: `yadmadd ~/.config/yadm/tracked`
|
||||
The tracking file is stored in `~/.config/yadm/tracked`. `$XDG_CONFIG_HOME` is respected. The file will be automatically created if it doesn't already exist. You can even add it to tracking: `yadmadd ~/.config/yadm/tracked`
|
||||
|
||||
> **Important**: Symlinks are _**not**_ added; this is to avoid conflicts with
|
||||
> `yadm alt`
|
||||
> **Important**: Symlinks are _**not**_ added; this is to avoid conflicts with `yadm alt`
|
||||
|
||||
The tracking file contains the paths to tracked files & directories **relative
|
||||
to $HOME**. For example:
|
||||
The tracking file contains the paths to tracked files & directories **relative to $HOME**. For example:
|
||||
|
||||
```
|
||||
.bashrc
|
||||
.config/nvim
|
||||
```
|
||||
|
||||
To add paths to be tracked, you may use `yadmadd.sh`. Any valid absolute or
|
||||
relative path should work.
|
||||
To add paths to be tracked, you may use `yadmadd.sh`. Any valid absolute or relative path should work.
|
||||
|
||||
```Bash
|
||||
$ yadmadd ~/.bashrc
|
||||
|
@ -104,21 +67,6 @@ $ yadmadd .bashrc .zshrc .config/nvim
|
|||
|
||||
To remove a target from tracking, simply delete it from the `tracked` file.
|
||||
|
||||
### Ignoring Certain Files
|
||||
|
||||
It's possible to ignore certain patterns inside a folder you're otherwise
|
||||
tracking with `yadmadd`. For example, suppose you've added `.config/foo`, but
|
||||
you want to specifically ignore `.config/foo/bar.log`. You can use a
|
||||
`.ignore`/`.gitignore` file for this:
|
||||
|
||||
```sh
|
||||
echo "bar.log" > ~/.config/foo/.ignore
|
||||
```
|
||||
|
||||
The `.ignore`/`.gitignore` file must be in the root of the directory you've
|
||||
added with `yadmadd`. You also need `fd` available on your `$PATH` for ignoring
|
||||
to work.
|
||||
|
||||
### Committing & Pushing
|
||||
|
||||
To automatically add and commit your tracking targets, use `autoyadm.sh`:
|
||||
|
@ -127,8 +75,7 @@ To automatically add and commit your tracking targets, use `autoyadm.sh`:
|
|||
$ autoyadm
|
||||
```
|
||||
|
||||
By default, automatic pushing is disabled. You can enable it with an environment
|
||||
variable:
|
||||
By default, automatic pushing is disabled. You can enable it with an environment variable:
|
||||
|
||||
```Bash
|
||||
$ export AUTOYADMPUSH=1
|
||||
|
@ -137,24 +84,17 @@ $ autoyadm
|
|||
$ AUTOYADMPUSH=1 autoyadm
|
||||
```
|
||||
|
||||
> Note: For auto push to work, ssh-agent must be enabled, and the environment
|
||||
> file needs to exist inside `~/.ssh`. Furthermore, you must have SSH setup with
|
||||
> your git host.
|
||||
> Note: For auto push to work, ssh-agent must be enabled, and the environment file needs to exist inside `~/.ssh`. Furthermore, you must have SSH setup with your git host.
|
||||
|
||||
### Calling AutoYADM Automatically
|
||||
|
||||
By default, AutoYADM only runs when the user calls it explicitly. If you want to
|
||||
automate this process, you are responsible for setting it up yourself. You may
|
||||
consider configuring a cron job for this. The following example will run
|
||||
AutoYADM every 15 minutes, with automatic push enabled, appending its output to
|
||||
a log file:
|
||||
By default, AutoYADM only runs when the user calls it explicitly. If you want to automate this process, you are responsible for setting it up yourself. You may consider configuring a cron job for this. The following example will run AutoYADM every 15 minutes, with automatic push enabled, appending its output to a log file:
|
||||
|
||||
```Bash
|
||||
*/15 * * * * AUTOYADMPUSH=1 /path/to/autoyadm/audoyadm.sh >> /path/to/log/file.log
|
||||
```
|
||||
|
||||
If you are on Arch Linux, you can follow these instructions to set up the cron
|
||||
job:
|
||||
If you are on Arch Linux, you can follow these instructions to set up the cron job:
|
||||
|
||||
```Bash
|
||||
# Install a cron daemon if you
|
||||
|
@ -168,3 +108,12 @@ $ crontab -e
|
|||
$ systemctl enable cronie
|
||||
$ systemctl start cronie
|
||||
```
|
||||
|
||||
## Feature Roadmap
|
||||
|
||||
- [x] Allow custom `tracked` file location & name
|
||||
- [ ] Optionally allow symlinks only if they are explicitly added to tracking
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are very welcome. This is a very small and simple script, but if you have some improvements or new features, please feel free to submit a PR. Bug reports welcome, too.
|
||||
|
|
19
autoyadm.sh
19
autoyadm.sh
|
@ -4,8 +4,6 @@
|
|||
# from a file and executes "yadm add"
|
||||
# on all of them, then creates a timestamped
|
||||
# commit and pushes the changes.
|
||||
# Author: Daniel Fichtinger
|
||||
# License: MIT
|
||||
|
||||
AYE="AutoYADM Error:"
|
||||
AYM="AutoYADM:"
|
||||
|
@ -37,16 +35,6 @@ if [ -z "$HOST" ]; then
|
|||
HOST="$(hostname)"
|
||||
fi
|
||||
|
||||
# check if fd is installed,
|
||||
# if so we prefer that. Setting this variable
|
||||
# avoids needing to repeat the check on every
|
||||
# fd/find invocation.
|
||||
if command -v fd >/dev/null; then
|
||||
FD="true"
|
||||
else
|
||||
FD="false"
|
||||
fi
|
||||
|
||||
# First we read each path from "tracked"
|
||||
(while read -r relpath; do
|
||||
path="$HOME/$relpath"
|
||||
|
@ -54,12 +42,7 @@ fi
|
|||
# if the path points to a directory
|
||||
# This ensures symlinks are not added
|
||||
if [ -d "$path" ]; then
|
||||
if [ "$FD" == "true" ]; then
|
||||
# we prefer fd because it respects .ignore and .gitignore
|
||||
fd --no-require-git --hidden -t f . "$path" -X yadm add
|
||||
else
|
||||
find "$path" -type f -exec yadm add {} +
|
||||
fi
|
||||
find "$path" -type f -exec yadm add {} +
|
||||
# If just a file, we add directly
|
||||
elif [ -f "$path" ]; then
|
||||
yadm add "$path"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue