2019-12-29 09:21:55 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# yadm - Yet Another Dotfiles Manager
|
2020-02-06 08:53:18 -05:00
|
|
|
# Copyright (C) 2015-2020 Tim Byrne and Martin Zuther
|
2019-12-29 09:21:55 -05:00
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
YADM_CHECKSUMS="$YADM_HOOK_DIR/files.checksums"
|
|
|
|
|
|
|
|
|
|
|
|
# is current directory on yadm's work path?
|
|
|
|
# (adapted from https://unix.stackexchange.com/a/6438/122163)
|
|
|
|
if [ "${PWD##$YADM_HOOK_WORK}" != "$PWD" ]; then
|
|
|
|
ON_WORK_PATH=1
|
|
|
|
else
|
|
|
|
ON_WORK_PATH=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# list all files or only those in the subdirectories below?
|
|
|
|
OPTION_LIST_ALL=0
|
2019-12-29 18:11:36 -05:00
|
|
|
for argument in "${YADM_HOOK_FULL_COMMAND[@]}"; do
|
2019-12-29 09:21:55 -05:00
|
|
|
# mimick git ls-files by displaying all files when not on work
|
|
|
|
# path
|
|
|
|
if [ "$argument" = "-a" ] || [ $ON_WORK_PATH -eq 0 ]; then
|
|
|
|
OPTION_LIST_ALL=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# if there is no checksum file, exit with original status of yadm
|
|
|
|
# command
|
|
|
|
if [ ! -f "$YADM_CHECKSUMS" ]; then
|
|
|
|
exit "$YADM_HOOK_EXIT"
|
|
|
|
fi
|
|
|
|
|
2019-12-29 09:53:01 -05:00
|
|
|
# list encrypted files
|
|
|
|
while IFS= read -r filename; do
|
2019-12-29 09:21:55 -05:00
|
|
|
# remove checksums from file names
|
2019-12-29 09:53:01 -05:00
|
|
|
filename="${filename##[a-zA-Z0-9]* }"
|
2019-12-29 09:21:55 -05:00
|
|
|
|
2019-12-29 09:53:01 -05:00
|
|
|
# list only files in the subdirectories below (i.e. files
|
|
|
|
# whose relative path doesn't begin with "../")
|
|
|
|
if [ $OPTION_LIST_ALL -eq 0 ]; then
|
|
|
|
REL_PATH=$(relative_path "$PWD" "$YADM_HOOK_WORK/$filename")
|
|
|
|
|
|
|
|
if [ "$REL_PATH" = "${REL_PATH##../}" ]; then
|
2019-12-29 18:43:24 -05:00
|
|
|
printf "%s\n" "$REL_PATH"
|
2019-12-29 09:21:55 -05:00
|
|
|
fi
|
2019-12-29 09:53:01 -05:00
|
|
|
# list all files
|
|
|
|
else
|
2019-12-29 18:43:24 -05:00
|
|
|
printf "%s\n" "$filename"
|
2019-12-29 09:53:01 -05:00
|
|
|
fi
|
2019-12-29 18:11:36 -05:00
|
|
|
done < "$YADM_CHECKSUMS"
|
2019-12-29 09:21:55 -05:00
|
|
|
|
|
|
|
# return original exit status of yadm command
|
|
|
|
exit "$YADM_HOOK_EXIT"
|