-
Notifications
You must be signed in to change notification settings - Fork 0
/
wstow
executable file
·74 lines (71 loc) · 2.89 KB
/
wstow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# source :- https://stackoverflow.com/a/8574392/17843293
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
case "${1}" in
"dry") for i in "${@: 4}" ; do
! [[ -d "${3}/${i}" ]] && mkdir -p "${3}/${i}"
stow -n -v --no-folding -t "${3}/${i}" -d "$2" -S "$i";
done
exit 0 ;;
"copy") for i in "${@: 4}" ; do
cp "$2"/"${i}" "${3}"/ ;
done
exit 0 ;;
"file") for i in "${@: 4}" ; do
! [[ -d "${3}/${i}" ]] && mkdir -p "${3}/${i}"
stow -v --no-folding -t "${3}/${i}" -d "$2" -S "$i";
done
exit 0 ;;
"folder") for i in "${@: 4}" ; do
! [[ -d "${3}/${i}" ]] && mkdir -p "${3}/${i}"
stow -v -t "${3}/${i}" -d "$2" -S "$i";
done
exit 0 ;;
"delete") for i in "${@: 4}" ; do
stow -v -t "${3}/${i}" -d "$2" -D "$i";
done
exit 0 ;;
"restow") for i in "${@: 4}" ; do
stow -v -t "${3}/${i}" -d "$2" -R "$i";
done
exit 0 ;;
"ignore") readarray -td '\n' myArray3 < <(find "${2}" -maxdepth 1 -not -path "${2}" -type d -printf "%f")
myArray1=( $(find "${2}" -maxdepth 1 -not -path "${2}" -type d -printf "%f ") )
myArray2=( "$@" )
location="${3}"
if test "${location: -1}" != "/"
then
location="$location/"
fi
for pack in "${myArray1[@]}" ; do
if ! containsElement "${pack}" "${myArray2[@]}" ; then
[[ ! -d "${location}${pack}" ]] && mkdir -p "${location}${pack}" ;
stow -v --no-folding -t "${location}${pack}" -d "$2" -S "${pack}"
fi
done
exit 0 ;;
"fignore") readarray -d '' myArray3 < <(find "${2}" -maxdepth 1 -not -path "${2}" -type d -printf "%f\n")
myArray1=( $(find "${2}" -maxdepth 1 -not -path "${2}" -type d -printf "%f ") )
myArray2=( "$@" )
location="${3}"
if test "${location: -1}" != "/"
then
location="$location/"
fi
for pack in "${myArray1[@]}" ; do
if ! containsElement "${pack}" "${myArray2[@]}" ; then
[[ ! -d "${location}${pack}" ]] && mkdir -p "${location}${pack}" ;
stow -v -t "${location}${pack}" -d "$2" -S "${pack}"
fi
done
exit 0 ;;
*) echo "dstow {options} <package_directory_parent> <target_dir_parent> [ <package names> | <ignore names> ]";
echo "Options : dry, copy, file, folder, delete, restow, ignore, fignore";
exit 1 ;;
esac
# vim: ft=bash: