Configs/Lib.sh

66 lines
918 B
Bash
Raw Normal View History

2023-04-14 18:47:33 +02:00
#!/bin/sh
2023-05-19 19:54:24 +02:00
ScopePath=""
SetScope(){
2023-09-06 13:56:08 +02:00
if [ "$1" = "Root" ]
then ScopePath="/"
elif [ "$1" = "Home" ]
then ScopePath="${HOME}/"
#else ScopePath="$1/"
fi
2023-05-19 19:54:24 +02:00
}
2023-04-14 18:47:33 +02:00
mkcd(){
2023-05-19 19:54:24 +02:00
mkdir -vp "./$1" && \
2023-04-14 18:47:33 +02:00
cd "$1"
}
2023-04-14 22:15:31 +02:00
2023-05-21 18:54:02 +02:00
CpItem(){
[ -f "${ScopePath}$1" ] && cpfile "$1"
[ -d "${ScopePath}$1" ] && cpdir "$1"
}
CpItems(){
for p in $@
2023-08-04 23:43:57 +02:00
do CpItem "$p"
2023-05-21 18:54:02 +02:00
done
}
CpSub(){
LBase="$1"; shift
RBase="$1"; shift
for s in $@
2023-09-06 13:56:08 +02:00
do
PathBack="${PWD}"
cd "${ScopePath}"
# Here will happen any wildcard expansion
for i in ${LBase}${s}${RBase}
do
cd "${PathBack}"
CpItem "${i}"
done
2023-05-21 18:54:02 +02:00
done
}
CpSufx(){
Base="$1"; shift
CpSub "$Base" "" $@
}
2023-05-19 19:54:24 +02:00
cpfile(){
2023-08-29 17:40:07 +02:00
if [ -f "${ScopePath}$1" ]
then
echo "$1"
rm -rf "./$1" && \
mkdir -p "./$1" && \
rm -rf "./$1" && \
cp --no-target-directory "${ScopePath}$1" "./$1"
fi
2023-05-19 19:54:24 +02:00
}
2023-04-14 22:15:31 +02:00
cpdir(){
2023-05-19 19:54:24 +02:00
echo "$1"
mkdir -p "./$1" && \
cp --recursive --no-target-directory "${ScopePath}$1" "./$1"
2023-04-14 22:15:31 +02:00
}