-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfm
More file actions
executable file
·82 lines (67 loc) · 1.86 KB
/
Copy pathdfm
File metadata and controls
executable file
·82 lines (67 loc) · 1.86 KB
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
#!/bin/sh
# _ ___
# _| | _|_____
# | . | _| |
# |___|_| |_|_|_|
# dotfile manager
# TO-DO:
# integrate git commands
# use case instead of the weird double test statements, maybe(?)
# add man page
sources=~/.dfmrc
. $sources
prompt(){
printf "overwrite (y/N): "
read -r confirm
confirm=$(echo "$confirm" | tr '[:upper:]' '[:lower:]')
if [ "$confirm" = 'y' ] || [ "$confirm" = 'yes' ]; then
return 0
else
return 1
fi
}
if [ "$1" = "c" ] || [ "$1" = "collect" ]; then
printf "Destination: $targetdir\n"
for f in $configloc; do
printf "Copying $f from .config\n"
cp -r "$HOME/.config/$f" "$targetdir/"
done
for g in $homeloc; do
printf "Copying $g from home\n"
cp -r "$HOME/$g" "$targetdir/"
done
elif [ "$1" = "d" ] || [ "$1" = "distribute" ]; then
printf "Source: $targetdir\n"
for f in $configloc; do
printf "Copying $f to .config\n"
if [ -e "$HOME/.config/$f" ]; then
if prompt; then
cp -r "$targetdir/$f" "$HOME/.config/"
printf "File was overwritten\n\n"
else
printf "File was not overwritten\n\n"
fi
fi
done
for g in $homeloc; do
printf "Copying $g to home\n"
if [ -e "$HOME/$g" ]; then
if prompt; then
cp -r "$targetdir/$g" "$HOME/"
printf "File was overwritten\n\n"
else
printf "File was not overwritten\n\n"
fi
fi
done
elif [ "$1" = "s" ] || [ "$1" = "source" ]; then
$EDITOR $sources
elif [ "$1" = "i" ] || [ "$1" = "info" ]; then
printf "Target directory: $targetdir\n\n"
printf "Selected files/folders in .config:\n$(echo $configloc | sed 's/ /, /g')\n\n"
printf "Selected files/folders in home:\n$(echo $homeloc | sed 's/ /, /g')\n"
elif [ -z "$1" ]; then
printf "Usage:\n c : collect dotfiles\n d : distribute dotfiles\n s : open configuration file\n i : print info about sources\n"
else
printf "Command not recognized: $1\nRun dfm without arguments for usage info\n"
fi