From f4a3779b04289764dc5f9b73f651902fc183c29f Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 24 Aug 2021 03:12:30 +0200 Subject: [PATCH] Manager: Implement path filtering to pushing and pulling It now possible to filter the pushing and pulling functions on zero, one or multiple files and/or directories. --- dotfiles.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/dotfiles.sh b/dotfiles.sh index d17b117..edb7f3a 100755 --- a/dotfiles.sh +++ b/dotfiles.sh @@ -128,7 +128,7 @@ getFileList() | awk -v e="^./($excludeFiles)" '$0 !~ e { print $0 }')" } -getFilteredFileLists() +separateFileList() { [ -z "$fileList" ] && getFileList @@ -143,6 +143,17 @@ getFilteredFileLists() | awk -v m="$match" '$0 ~ m { print substr($0, 3) }')" } +filterFileList() +{ + if [ -z "$homeFileList" ] || [ -z "$systemFileList" ]; then + separateFileList + fi + + # Filter on provided file name + homeFileListLoop="$(echo "$homeFileList" | grep "^$1")" + systemFileListLoop="$(echo "$systemFileList" | grep "^$1")" +} + fileAdd() { [ -z "$1" ] && exit 1 @@ -164,16 +175,14 @@ fileAdd() filePull() { - if [ -z "$homeFileList" ] || [ -z "$systemFileList" ]; then - getFilteredFileLists - fi + filterFileList "$1" - for file in $homeFileList; do + for file in $homeFileListLoop; do # /home// -> dotfiles/ cp -a "$HOME/$file" "$(pwd)/$file" done - for file in $systemFileList; do + for file in $systemFileListLoop; do # / -> dotfiles/ sudo cp -a "/$file" "$(pwd)/$file" done @@ -181,17 +190,15 @@ filePull() filePush() { - if [ -z "$homeFileList" ] || [ -z "$systemFileList" ]; then - getFilteredFileLists - fi + filterFileList "$1" - for file in $homeFileList; do + for file in $homeFileListLoop; do # dotfiles/ -> /home// mkdir -p "$(dirname "$HOME/$file")" cp -a "$(pwd)/$file" "$HOME/$file" done - for file in $systemFileList; do + for file in $systemFileListLoop; do # dotfiles/ -> / sudo mkdir -p "$(dirname "/$file")" sudo cp -a "$(pwd)/$file" "/$file" @@ -387,8 +394,6 @@ while true; do esac done -# @Todo: -# push function to push just one file # Target parsing # --------------------------------------