-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck
executable file
·89 lines (73 loc) · 1.81 KB
/
check
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
info() {
ls -dl --full-time "${HOME}/${1}" 2>/dev/null
}
print_linked() {
local from=$( echo "${1}" | awk '{ print $9 }' )
local to=$( echo "${1}" | awk '{ print $11 }' )
local type=F
if [ -d "${to}" ]; then
type=D
fi
printf "%s %-60s %-60s\n" "${type}" "${from}" "${to}"
}
print_missing() {
local to="${1}"
local type=F
local from="$( echo "${1}" | sed 's/\.dotfiles\/home\///' )"
if [ -d "${to}" ]; then
type=D
fi
local cmd=" ln -s ${to} ${from}"
echo -ne "\e[31m"
printf "%s %-60s %-60s\n" "${type}" "${missing}" "${to}"
echo -ne "\e[0m"
echo -ne "\e[33m"
echo "Use this command to create:"
echo " ln -s ${to} ${from}"
echo "Apply?"
read answer
if [ "${answer}" == "y" ]; then
${cmd}
fi
echo -ne "\e[0m"
}
list_tracked_dotfiles() {
echo "Tracked files/directories:"
echo
for item in $( cat tracked ); do
if [ -e "${HOME}/${item}" ]; then
print_linked "$( info "${item}" )"
else
print_missing "${HOME}/.dotfiles/home/${item}"
fi
done
}
list_untracked_dotfiles() {
local tmp_file=$( mktemp )
local tmp_file2=$( mktemp )
# List all files belonging to home directory
# These files are expected to be tracked.
( cd home && find -type f ) >> "${tmp_file}"
( cd home && find -type l ) >> "${tmp_file}"
# Remove all files that are tracked or belong to a tracked directory
for item in $( cat tracked ); do
cp -f "${tmp_file}" "${tmp_file2}"
grep -v "/$item" "${tmp_file2}" > "${tmp_file}"
done
# If there are any files left, they are untracked
if [ -s "${tmp_file}" ]; then
echo
echo -ne "\e[33m"
echo "Untracked files:"
echo -ne "\e[0m"
echo
cat "${tmp_file}"
fi
rm "${tmp_file}" "${tmp_file2}"
}
main() {
list_tracked_dotfiles
list_untracked_dotfiles
}
main