1
0
Fork 0

dotsync: add hook functionality for aichat

This commit is contained in:
Luca Bilke 2025-02-26 16:34:41 +01:00
parent f71d136006
commit 1d4cfaa346
Signed by: luca
GPG key ID: F6E11C9BAA7C82F5
2 changed files with 39 additions and 20 deletions
common/.local
bin
libexec/dothooks

View file

@ -1,11 +1,12 @@
#!/bin/sh
# vim: set noexpandtab:
# shellcheck disable=SC2155
BOLD="$(tput bold)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
BLUE="$(tput setaf 4)"
NC="$(tput sgr0)"
export BOLD="$(tput bold)"
export RED="$(tput setaf 1)"
export GREEN="$(tput setaf 2)"
export BLUE="$(tput setaf 4)"
export NC="$(tput sgr0)"
stow_git() {
git -C "$STOW_DIR" "$@"
@ -21,7 +22,7 @@ multi_stow() {
host_package="fallback"
fi
for package in common ${host_package}; do
for package in submodules common ${host_package}; do
stow --no-folding -d "$STOW_DIR" -t "$HOME" "$@" "$package"
ret=$((ret + $?))
done
@ -56,7 +57,7 @@ first_clone() {
touch "${HOME}/.gitconfig"
git config --global filter.redact.clean "$filter_file clean"
git config --global filter.redact.smudge "$filter_file smudge"
git clone -j4 --recursive "$STOW_REPO" "$STOW_DIR"
git clone -j4 --recurse-submodules "$STOW_REPO" "$STOW_DIR"
rm "$filter_file" "${HOME}/.gitconfig"
}
@ -69,16 +70,16 @@ mkdir -p "$STOW_DIR"
# First run
if [ ! -e "$STOW_DIR/.git" ]; then
printf "%b" "${BOLD}${BLUE}Cloning dotfiles...$NC\n\n"
printf "%b" "${BOLD}${BLUE}Cloning dotfiles...${NC}\n\n"
first_clone
multi_stow || printf "%b" "${RED}Failed to run stow!$NC\n"
multi_stow || printf "%b" "${RED}Failed to run stow!${NC}\n"
exit 0
fi
printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...$NC\n\n"
multi_stow -D || printf "%b" "${RED}Failed to run stow!$NC\n"
printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...${NC}\n\n"
multi_stow -D || printf "%b" "${RED}Failed to run stow!${NC}\n"
printf "%b" "${BOLD}${BLUE}Stashing existing changes...$NC\n"
printf "%b" "${BOLD}${BLUE}Stashing existing changes...${NC}\n"
stash_result=$(stow_git stash push)
needs_pop=1
if [ "$stash_result" = "No local changes to save" ]; then
@ -86,27 +87,31 @@ if [ "$stash_result" = "No local changes to save" ]; then
fi
printf "\n"
printf "%b" "${BOLD}${BLUE}Pulling updates from dotfiles repo...$NC\n"
printf "%b" "${BOLD}${BLUE}Pulling updates from dotfiles repo...${NC}\n"
old_commit="$(stow_git rev-parse HEAD)"
stow_git pull origin "$STOW_BRANCH"
stow_git submodule update --remote --merge
printf "\n"
if [ $needs_pop -eq 1 ]; then
printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n"
printf "%b" "${BOLD}${BLUE}Popping stashed changes...${NC}\n"
stow_git stash pop
fi
printf "\n"
unmerged_files=$(stow_git diff --name-only --diff-filter=U)
if [ -n "$unmerged_files" ]; then
printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n\n"
printf "%s" "$unmerged_files\n\n"
printf "%s" "${BOLD}${BLUE}Reverting to previous commit...$NC"
printf "%b" "${RED}The following files have merge conflicts after popping the stash:${NC}\n\n"
printf "%s" "${unmerged_files}\n\n"
printf "%s" "${BOLD}${BLUE}Reverting to previous commit...${NC}"
stow_git checkout "$old_commit"
fi
printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...$NC\n\n"
multi_stow || printf "%b" "${RED}Failed to run stow!$NC\n"
printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...${NC}\n\n"
multi_stow || printf "%b" "${RED}Failed to run stow!${NC}\n"
printf "%b" "${BOLD}${GREEN}Dotfiles synced successfully!$NC\n"
printf "%b" "${BOLD}${BLUE}Running hooks...${NC}\n"
run-parts -v "${HOME}/.local/libexec/dothooks"
printf "\n"
printf "%b" "${BOLD}${GREEN}Dotfiles synced successfully!${NC}\n"

View file

@ -0,0 +1,14 @@
#!/bin/sh
command -v argc >/dev/null 2>&1 || {
printf "%b" "${BOLD}${RED}argc is not installed${NC}"
exit 1
}
cd "${XDG_CONFIG_HOME}/aichat/functions" || {
printf "%b" "${BOLD}${RED}could not cd into ${XDG_CONFIG_HOME}/aichat/functions${NC}"
exit 1
}
argc link-web-search web_search_tavily.sh
argc build