From 1251bb4eab66618fc1f1f07b5689115a16b7bcba Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Fri, 20 Oct 2023 14:57:50 +0200 Subject: [PATCH] Update conditional checks and add yadm pre_commit hook --- .config/aliasrc | 16 ++++++++-------- .config/environment | 2 +- .config/yadm/hooks/post_pull | 5 +++++ .config/yadm/hooks/pre_ci | 1 + .config/yadm/hooks/pre_commit | 30 ++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 9 deletions(-) create mode 100755 .config/yadm/hooks/post_pull create mode 120000 .config/yadm/hooks/pre_ci create mode 100755 .config/yadm/hooks/pre_commit diff --git a/.config/aliasrc b/.config/aliasrc index 7bf402e..470d3b9 100644 --- a/.config/aliasrc +++ b/.config/aliasrc @@ -71,17 +71,17 @@ alias xdebug='XDEBUG_CONFIG="remote_host=127.0.0.1 remote_port=9003"' ### conditionals -[ -x "$(command -v bat)" ] && alias cat='bat -pp' +test -x "$(command -v bat)" && alias cat='bat -pp' -[ -x "$(command -v eza)" ] && alias ls='eza -lhF --git --icons --color=always --color-scale --time-style=long-iso --group-directories-first' +test -x "$(command -v eza)" && alias ls='eza -lhF --git --icons --color=always --color-scale --time-style=long-iso --group-directories-first' -[ -x "$(command -v moar)" ] && alias less='moar' +test -x "$(command -v moar)" && alias less='moar' -[ -x "$(command -v nvim)" ] && alias vim='nvim' +test -x "$(command -v nvim)" && alias vim='nvim' -[ -x "$(command -v rmtrash)" ] && alias rm='rmtrash -I --one-file-system' -[ -x "$(command -v rmdirtrash)" ] && alias rmdir='rmdirtrash' +test -x "$(command -v rmtrash)" && alias rm='rmtrash -I --one-file-system' +test -x "$(command -v rmdirtrash)" && alias rmdir='rmdirtrash' -[ ! -x "$(command -v yadm)" ] && alias yadm='git --git-dir="$HOME/.local/share/yadm/repo.git"' +test ! -x "$(command -v yadm)" && alias yadm='git --git-dir="$HOME/.local/share/yadm/repo.git"' -[ -f "$HOME/.config/aliasrc.local" ] && . "$HOME/.config/aliasrc.local" +test -x "$HOME/.config/aliasrc.local" && . "$HOME/.config/aliasrc.local" diff --git a/.config/environment b/.config/environment index d28de46..805283c 100644 --- a/.config/environment +++ b/.config/environment @@ -52,6 +52,6 @@ for additional_env in "$XDG_CONFIG_HOME/env.d/"*; do esac # shellcheck disable=1090 - test -r "$additional_env" && . "$additional_env" + test -x "$additional_env" && . "$additional_env" done unset additional_env diff --git a/.config/yadm/hooks/post_pull b/.config/yadm/hooks/post_pull new file mode 100755 index 0000000..832a719 --- /dev/null +++ b/.config/yadm/hooks/post_pull @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +echo "Running post pull script..." + +autoinstall base diff --git a/.config/yadm/hooks/pre_ci b/.config/yadm/hooks/pre_ci new file mode 120000 index 0000000..3e5a678 --- /dev/null +++ b/.config/yadm/hooks/pre_ci @@ -0,0 +1 @@ +pre_commit \ No newline at end of file diff --git a/.config/yadm/hooks/pre_commit b/.config/yadm/hooks/pre_commit new file mode 100755 index 0000000..e7d8dbc --- /dev/null +++ b/.config/yadm/hooks/pre_commit @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +# Check encrypted files for newer versions +files="$HOME/.config/yadm/encrypt" +archive="$HOME/.local/share/yadm/archive" +new_files=false + +echo "Checking for newer versions of encrypted files..." +while IFS= read -r file +do + if test "$HOME/$file" -nt "$archive" + then + echo "WARNING: ~/$file is newer than the archive!" + new_files=true + fi +done < "$files" + +if $new_files +then + echo "WARNING: There are newer versions of encrypted files!" + echo "WARNING: Please consider re-encrypting them." + printf "Continue? [y/N] " + read -r answer + if [ "$answer" = "n" ] || [ "$answer" = "N" ] + then + exit 1 + fi +else + echo "All encrypted files are up to date." +fi