AutoYADM commit: 2024-11-10 00:34:11

This commit is contained in:
Daniel Fichtinger 2024-11-10 00:34:11 -05:00
parent 7f706ba05c
commit 4fb68f0552
7 changed files with 293 additions and 0 deletions

49
.config/yadm/README.md Normal file
View file

@ -0,0 +1,49 @@
# Daniel's Dotfiles
My personal Linux dotfiles.
I use Arch btw.
The root of this repo is equivalent to my $HOME directory.
## Of Interest
### Neovim
Neovim, my beloved.
The best text editor ever made. There's too much going on there to cover here, so I invite you to read my [Neovim config README](./.config/nvim/README.md).
### Shell
I use Zsh. It has some nice features while remaining POSIX compliance, which is important if you like to tinker and end up copying a lot of shell scripts from the internet. I also use `starship` for my prompt because it's wicked fast. I find that the `pure` preset with some minor changes to cwd display is really great for my needs.
### Tmux
I really like tmux as a terminal multiplexer. The `vim-tmux-navigator` plugin offers really nice compatibility with Neovim split windows. The `minimal-tmux-status` is also really nice: displays only what's needed, in a slightly cleaner way than the default status bar. `tmux-yank` is awesome for easily copying text from the terminal without needing to use the mouse.
### Terminal
Kitty has been the best terminal for me so far. It displays stuff properly, and is as fast as I need it to be.
### i3
I'm using i3 for window management. I have experimented in the past with Hyprland, but I prefer the simplicity of i3.
### Launcher
Rofi is my application launcher of choice. It's easy to configure, minimal, and gets out of the way.
### Process Viewer
`btop` works great when `ps aux | grep` doesn't cut it. It's fast and has a pleasing, intuitive UI. I highly recommend it over both top and htop.
### Notifications
Dunst is all I want from a notification manager.
### Management
Currently I'm using `yadm` to manage these dotfiles. I have tried some other solutions like `chezmoi` and `stow`, but this one has stuck for me. I highly recommend it.
If you see a file with a weird name, like `config##hostname.dbox`, it's leveraging `yadm`'s alternate files feature; the program will automatically symlink that file to its appropriate destination depending on which computer it's on.

45
.config/yadm/autoyadm.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
# This script reads tracked paths
# from a file and executes "yadm add"
# on all of them, then creates a timestamped
# commit and pushes the changes.
AYE="AutoYADM Error:"
AYM="AutoYADM:"
# First we read each path from "tracked"
while read -r path; do
# Execute yadm add on each real file
# if the path points to a directory
# This ensures symlinks are not added
if [ -d "$path" ]; then
find "$path" -type f -exec yadm add {} +
# If just a file, we add directly
elif [ -f "$path" ]; then
yadm add "$path"
# If neither file nor dir, something is very wrong!
else
echo "$AYE Target must be a directory or a file!"
exit 1
fi
done <"$HOME/.config/yadm/tracked"
# Define the location of the ssh-agent environment
sshenv="$HOME/.ssh/environment-$HOST"
if [[ -n $(yadm status --porcelain) ]]; then
yadm commit -m "AutoYADM commit: $(date +'%Y-%m-%d %H:%M:%S')"
# Check if the ssh-agent env exists
if [ -f "$sshenv" ]; then
# Directive to suppress shellcheck warning
# shellcheck source=/dev/null
source "$sshenv"
yadm push
else
echo "$AYE ssh-agent environment not found, aborting push..."
exit 1
fi
fi
echo "$AYM Push successful!"

32
.config/yadm/oldautoyadm.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/bash
# Add individual files, ignoring symlinks
[ ! -L "$HOME/.zshrc" ] && yadm add "$HOME/.zshrc"
# Directory navigation
cd "$HOME/.config/" || exit
# List of config directories/files to add
configs=(nvim btop dunst i3 kitty lazygit nushell polybar rofi tmux wal zathura starship.toml yadm)
# Loop through each item in configs array
for config in "${configs[@]}"; do
# Check if it's not a symlink before adding
# [ ! -L "$config" ] && [ -n "$(find "$config" -type l)" ] && yadm add "$config"
find "$config" -type f -exec yadm add {} +
done
sshenv="$HOME/.ssh/environment-$(cat /etc/hostname)"
# Commit and push if there are changes
if [[ -n $(yadm status --porcelain) ]]; then
yadm commit -m "Auto commit: $(date +'%Y-%m-%d %H:%M:%S')"
# Check if the ssh-agent env is present
if [ -f "$sshenv" ]; then
# shellcheck source=/dev/null
source "$sshenv"
yadm push
else
echo "ERROR: ssh-agent environment not found, aborting push..."
exit
fi
fi

16
.config/yadm/tracked Normal file
View file

@ -0,0 +1,16 @@
/home/fic/.config/yadm
/home/fic/.config/nvim
/home/fic/.config/btop
/home/fic/.config/dunst
/home/fic/.config/i3
/home/fic/.config/kitty
/home/fic/.config/lazygit
/home/fic/.config/nushell
/home/fic/.config/polybar
/home/fic/.config/rofi
/home/fic/.config/tmux
/home/fic/.config/wal
/home/fic/.config/zathura
/home/fic/.config/starship.toml
/home/fic/.zshrc
/home/fic/.bashrc

37
.config/yadm/yadmadd.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
# This script takes file or directories as
# arguments and appends them to the "tracked"
# file, for use by autoyadm.sh
YADMDIR="$HOME/.config/yadm"
AYE="AutoYADM Error:"
AYM="AutoYADM:"
# We check if any arguments have been provided
if [ $# -eq 0 ]; then
echo "$AYE $0 <file_or_directory> [<file_or_directory> ...]"
exit 1
fi
# We loop through arguments
for arg in "$@"; do
# check if current arg is a real path
if [ ! -e "$arg" ]; then
echo "$AYE '$arg' is not a valid path."
continue
fi
# get its absolute path
abs=$(realpath "$arg")
# check if it's inside home dir
if [[ "$abs" == "$HOME"* ]]; then
# convert to path relative to ~
rel=${abs#"$HOME/"}
# append to tracked file
echo "$HOME/$rel" >>"$YADMDIR/tracked"
echo "$AYM Tracking $HOME/$rel"
else
echo "$AYM Path must be inside the home directory."
exit 1
fi
done