-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdut_works_messy
executable file
·61 lines (54 loc) · 1.92 KB
/
dut_works_messy
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
#!/bin/bash
# Current bugs: doesn't work for the files with spaces in their names.
rpath="$(realpath $1)"
if [[ -f $rpath ]]; then # If $rpath is a file
echo $rpath
if [[ "$(dirname $rpath)" != "$HOME" ]]; then # If $rpath isn't in home directory
read -p "Are you sure you want to add \""$(basename $rpath)"\" \
file and not the <"$(basename $(dirname $rpath))"> directory? [Y/N] " answer
if [[ "${answer,,}" = "y" ]]; then
#mkdir "~/dot/$(basename $rpath)"
rpath_edited=$(echo $rpath | sed -e "s|$HOME||" -e "s|$(basename $rpath)$||")
#echo $path_edited
dest="$HOME/dot/$(basename $rpath)/$rpath_edited"
mkdir -p $dest
cp $rpath $dest
rm $rpath
cd "$HOME/dot/"
echo "$(basename $rpath)"
stow $(basename $rpath)
elif [[ "${answer,,}" = "n" ]]; then
rpath_edited=$(echo $rpath | sed -e "s|$HOME||" -e "s|$(basename $rpath)$||")
dest="$HOME/dot/$(basename $(dirname $rpath))$rpath_edited"
mkdir -p $dest
echo $dest
echo $rpath_edited
echo "$(dirname $rpath)"
echo $(basename $(dirname $rpath))
cp -r "$(dirname $rpath)"/. "${dest}"
rm -r $(dirname $rpath)
cd "$HOME/dot/"
stow $(basename $(dirname $rpath))
else
echo "invalid input"
exit 1;
fi
else
dest="$HOME/dot/$(basename $1)"
mkdir $dest
cp $rpath $dest
rm $rpath
cd "$HOME/dot"
stow $(basename $1)
fi
elif [[ -d $rpath ]]; then
rpath_edited=$(echo $rpath | sed -e "s|$HOME||")
dest="$HOME/dot/$(basename $rpath)$rpath_edited"
echo $rpath_edited
echo $dest
mkdir -p $dest
cp -r "$rpath/." $dest
rm -r $rpath
cd "$HOME/dot"
stow $(basename $rpath)
fi