dotsync: add hook functionality for aichat
This commit is contained in:
parent
f71d136006
commit
1d4cfaa346
2 changed files with 39 additions and 20 deletions
common/.local
|
@ -1,11 +1,12 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# vim: set noexpandtab:
|
# vim: set noexpandtab:
|
||||||
|
# shellcheck disable=SC2155
|
||||||
|
|
||||||
BOLD="$(tput bold)"
|
export BOLD="$(tput bold)"
|
||||||
RED="$(tput setaf 1)"
|
export RED="$(tput setaf 1)"
|
||||||
GREEN="$(tput setaf 2)"
|
export GREEN="$(tput setaf 2)"
|
||||||
BLUE="$(tput setaf 4)"
|
export BLUE="$(tput setaf 4)"
|
||||||
NC="$(tput sgr0)"
|
export NC="$(tput sgr0)"
|
||||||
|
|
||||||
stow_git() {
|
stow_git() {
|
||||||
git -C "$STOW_DIR" "$@"
|
git -C "$STOW_DIR" "$@"
|
||||||
|
@ -21,7 +22,7 @@ multi_stow() {
|
||||||
host_package="fallback"
|
host_package="fallback"
|
||||||
fi
|
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"
|
stow --no-folding -d "$STOW_DIR" -t "$HOME" "$@" "$package"
|
||||||
ret=$((ret + $?))
|
ret=$((ret + $?))
|
||||||
done
|
done
|
||||||
|
@ -56,7 +57,7 @@ first_clone() {
|
||||||
touch "${HOME}/.gitconfig"
|
touch "${HOME}/.gitconfig"
|
||||||
git config --global filter.redact.clean "$filter_file clean"
|
git config --global filter.redact.clean "$filter_file clean"
|
||||||
git config --global filter.redact.smudge "$filter_file smudge"
|
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"
|
rm "$filter_file" "${HOME}/.gitconfig"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,16 +70,16 @@ mkdir -p "$STOW_DIR"
|
||||||
|
|
||||||
# First run
|
# First run
|
||||||
if [ ! -e "$STOW_DIR/.git" ]; then
|
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
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...$NC\n\n"
|
printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...${NC}\n\n"
|
||||||
multi_stow -D || printf "%b" "${RED}Failed to run stow!$NC\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)
|
stash_result=$(stow_git stash push)
|
||||||
needs_pop=1
|
needs_pop=1
|
||||||
if [ "$stash_result" = "No local changes to save" ]; then
|
if [ "$stash_result" = "No local changes to save" ]; then
|
||||||
|
@ -86,27 +87,31 @@ if [ "$stash_result" = "No local changes to save" ]; then
|
||||||
fi
|
fi
|
||||||
printf "\n"
|
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)"
|
old_commit="$(stow_git rev-parse HEAD)"
|
||||||
stow_git pull origin "$STOW_BRANCH"
|
stow_git pull origin "$STOW_BRANCH"
|
||||||
stow_git submodule update --remote --merge
|
stow_git submodule update --remote --merge
|
||||||
printf "\n"
|
printf "\n"
|
||||||
|
|
||||||
if [ $needs_pop -eq 1 ]; then
|
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
|
stow_git stash pop
|
||||||
fi
|
fi
|
||||||
printf "\n"
|
printf "\n"
|
||||||
|
|
||||||
unmerged_files=$(stow_git diff --name-only --diff-filter=U)
|
unmerged_files=$(stow_git diff --name-only --diff-filter=U)
|
||||||
if [ -n "$unmerged_files" ]; then
|
if [ -n "$unmerged_files" ]; then
|
||||||
printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n\n"
|
printf "%b" "${RED}The following files have merge conflicts after popping the stash:${NC}\n\n"
|
||||||
printf "%s" "$unmerged_files\n\n"
|
printf "%s" "${unmerged_files}\n\n"
|
||||||
printf "%s" "${BOLD}${BLUE}Reverting to previous commit...$NC"
|
printf "%s" "${BOLD}${BLUE}Reverting to previous commit...${NC}"
|
||||||
stow_git checkout "$old_commit"
|
stow_git checkout "$old_commit"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...$NC\n\n"
|
printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...${NC}\n\n"
|
||||||
multi_stow || printf "%b" "${RED}Failed to run stow!$NC\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"
|
||||||
|
|
14
common/.local/libexec/dothooks/aichat-functions
Executable file
14
common/.local/libexec/dothooks/aichat-functions
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue