Browse Source

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.
master
Riyyi 3 years ago
parent
commit
f4a3779b04
  1. 31
      dotfiles.sh

31
dotfiles.sh

@ -128,7 +128,7 @@ getFileList()
| awk -v e="^./($excludeFiles)" '$0 !~ e { print $0 }')" | awk -v e="^./($excludeFiles)" '$0 !~ e { print $0 }')"
} }
getFilteredFileLists() separateFileList()
{ {
[ -z "$fileList" ] && getFileList [ -z "$fileList" ] && getFileList
@ -143,6 +143,17 @@ getFilteredFileLists()
| awk -v m="$match" '$0 ~ m { print substr($0, 3) }')" | 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() fileAdd()
{ {
[ -z "$1" ] && exit 1 [ -z "$1" ] && exit 1
@ -164,16 +175,14 @@ fileAdd()
filePull() filePull()
{ {
if [ -z "$homeFileList" ] || [ -z "$systemFileList" ]; then filterFileList "$1"
getFilteredFileLists
fi
for file in $homeFileList; do for file in $homeFileListLoop; do
# /home/<user>/<file> -> dotfiles/<file> # /home/<user>/<file> -> dotfiles/<file>
cp -a "$HOME/$file" "$(pwd)/$file" cp -a "$HOME/$file" "$(pwd)/$file"
done done
for file in $systemFileList; do for file in $systemFileListLoop; do
# /<file> -> dotfiles/<file> # /<file> -> dotfiles/<file>
sudo cp -a "/$file" "$(pwd)/$file" sudo cp -a "/$file" "$(pwd)/$file"
done done
@ -181,17 +190,15 @@ filePull()
filePush() filePush()
{ {
if [ -z "$homeFileList" ] || [ -z "$systemFileList" ]; then filterFileList "$1"
getFilteredFileLists
fi
for file in $homeFileList; do for file in $homeFileListLoop; do
# dotfiles/<file> -> /home/<user>/<file> # dotfiles/<file> -> /home/<user>/<file>
mkdir -p "$(dirname "$HOME/$file")" mkdir -p "$(dirname "$HOME/$file")"
cp -a "$(pwd)/$file" "$HOME/$file" cp -a "$(pwd)/$file" "$HOME/$file"
done done
for file in $systemFileList; do for file in $systemFileListLoop; do
# dotfiles/<file> -> /<file> # dotfiles/<file> -> /<file>
sudo mkdir -p "$(dirname "/$file")" sudo mkdir -p "$(dirname "/$file")"
sudo cp -a "$(pwd)/$file" "/$file" sudo cp -a "$(pwd)/$file" "/$file"
@ -387,8 +394,6 @@ while true; do
esac esac
done done
# @Todo:
# push function to push just one file
# Target parsing # Target parsing
# -------------------------------------- # --------------------------------------

Loading…
Cancel
Save