-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy
executable file
·204 lines (183 loc) · 6.61 KB
/
copy
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/copy
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/copy
## https://davoudarsalani.ir
source "$HOME"/main/scripts/gb
source "$HOME"/main/scripts/gb-color
title="${0##*/}"
function copy {
local remove_propmt
action_now 'removing'
[ -d "$dest_dir" ] || {
red "no such dir as $dest_dir"
exit
}
readarray -t files < <(find "$dest_dir" -mindepth 1 -maxdepth 1 ! -iname '*0-path.txt' | sort)
printf '%s\n' "${files[@]##*/}" | column
remove_propmt="$(get_single_input 'remove these?')" && printf '\n'
case "$remove_propmt" in
y )
rm -rf "${files[@]}" ;;
* )
exit ;;
esac
action_now 'copying'
cp -r "$@" "$dest_dir" && \
accomplished
}
heading "$title"
main_items=( 'sublime' 'awesome' 'bash' 'tmux' 'fzf' 'lf' 'ranger' 'xfce4-terminal' 'vim' 'cava' 'rofi' 'greenclip' 'grub' 'uget' 'kdenlive' 'mutt' 'lightdm' 'highlight' 'picom' 'kid3' 'audacious' 'vlc' 'irssi' 'git' 'tor' 'kdeconnect' 'torsocks' 'handbrake' 'vsftpd' 'ssh' 'aria2' 'mpv' 'vifm' 'gpicview' 'htop' 'qutebrowser' 'optimus-manager' 'wget' 'netrc' 'pacman.conf' 'gtk-2.0' 'gtk-3.0' 'fstab' 'mkinitcpio' '99-sysctl' 'dhcpcd' 'xorg.conf' 'xinitrc' 'mirrorlist' 'firefox' '/var/cache/pacman/pkg' )
main_item="$(pipe_to_fzf "${main_items[@]}")" && wrap_fzf_choice "$main_item" || exit 37
dest_dir="$HOME"/main/linux/cfg-"$main_item"
case "$main_item" in
sublime )
copy "$HOME"/.config/sublime-text/* ;;
awesome )
copy "$HOME"/.config/awesome/* ;;
bash )
copy "$HOME"/.bashrc \
"$HOME"/.bash_history \
/etc/{bash.bashrc,environment,inputrc,profile} ;;
tmux )
copy "$HOME"/.tmux* ;;
fzf )
copy "$HOME"/.fzf/ ;;
lf )
copy "$HOME"/.config/lf/lfrc \
"$HOME"/.local/share/lf/{marks,history} ;;
ranger )
## first, check if the version of os python and ranger python are different
ranger_python="$(ranger --version | \grep -i 'python version' | awk '{print $3}')"
os_python="$(python --version | awk '{print $NF}')"
[ "$os_python" == "$ranger_python" ] || {
red "different python versions. ranger python: ${ranger_python}, os python: ${os_python})"
exit
}
## now check if python version has changed from 3.9.*
regex='3.9.*'
[[ "$os_python" =~ $regex ]] || {
red "python version changed ($os_python)"
exit
}
copy "$HOME"/.config/ranger/{colorschemes,plugins,commands.py,commands_full.py,rc.conf,rifle.conf,scope.sh} \
/usr/lib/python3.9/site-packages/ranger/container/fsobject.py ;;
xfce4-terminal )
copy "$HOME"/.config/xfce4/* ;;
vim )
copy "$HOME"/{.vim,.vimrc} ;;
cava )
copy "$HOME"/.config/cava/config ;;
rofi )
copy "$HOME"/.config/rofi/* ;;
greenclip )
copy "$HOME"/.config/greenclip.toml ;;
grub )
copy /etc/default/grub ;;
uget )
copy "$HOME"/.config/uGet/Setting.json ;;
kdenlive )
copy "$HOME"/.config/kdenliverc ;;
mutt )
copy "$HOME"/.muttrc ;;
lightdm )
copy /etc/lightdm/* ;;
highlight )
copy "$HOME"/.config/highlight/anotherdark.theme \
/usr/share/highlight/* ;;
picom )
copy "$HOME"/.config/picom/picom.conf ;;
kid3 )
copy "$HOME"/.config/kid3rc ;;
audacious )
copy "$HOME"/.config/audacious/* ;;
vlc )
copy "$HOME"/.config/vlc/* ;;
irssi )
copy "$HOME"/.irssi/* ;;
git )
copy "$HOME"/{.gitconfig,.git-credentials} ;;
tor )
copy /etc/tor/torrc ;;
kdeconnect )
copy "$HOME"/.config/kdeconnect/* ;;
torsocks )
copy /etc/tor/torsocks.conf ;;
handbrake )
copy "$HOME"/.config/ghb/preferences.json ;;
vsftpd )
copy /etc/vsftpd.conf ;;
ssh )
copy /etc/ssh/{ssh_config,sshd_config} \
"$HOME"/.ssh/{config,id_rsa*,known_hosts*} ;;
aria2 )
copy "$HOME"/.aria2/aria2.conf ;;
mpv )
copy "$HOME"/.config/mpv/* ;;
vifm )
copy "$HOME"/.config/vifm/* ;;
gpicview )
copy "$HOME"/.config/gpicview/gpicview.conf ;;
htop )
copy "$HOME"/.config/htop/htoprc ;;
qutebrowser )
copy "$HOME"/.config/qutebrowser/config.py ;;
optimus-manager )
copy /etc/optimus-manager/optimus-manager.conf \
/etc/X11/xorg.conf.d/10-optimus-manager.conf ;;
wget )
copy /etc/wgetrc ;;
## os pkgs ----------------------------------------------------------------
netrc )
copy "$HOME"/.netrc ;;
pacman.conf )
copy /etc/pacman.conf ;;
gtk-2.0 )
[ -f "$HOME"/.gtkrc-2.0 ] || {
red "${HOME}/.gtkrc-2.0 does not exist"
exit
}
copy "$HOME"/.gtkrc-2.0 \
"$HOME"/.config/gtk-2.0/gtkfilechooser.ini ;;
gtk-3.0 )
copy "$HOME"/.config/gtk-3.0/* ;;
fstab )
copy /etc/fstab ;;
mkinitcpio )
copy /etc/mkinitcpio.conf ;;
99-sysctl )
copy /etc/sysctl.d/99-sysctl.conf ;;
dhcpcd )
copy /etc/dhcpcd.conf ;;
xorg.conf )
copy /etc/X11/xorg.conf ;;
xinitrc )
copy "$HOME"/.xinitrc ;;
mirrorlist )
copy /etc/pacman.d/mirrorlist ;;
## pkgs with exceptional removing/copying procedures -------------------------------
## removes chrome dir only
firefox )
action_now 'removing chrome dir only'
rm -r "$dest_dir"/chrome
action_now 'copying chrome dir only'
cp -r "$HOME"/.mozilla/firefox/*.default-release/chrome "$dest_dir" && accomplished ;;
## has a different dest_dir
/var/cache/pacman/pkg )
dest_dir="$HOME"/main/linux-pkg
dest_kaddy_dir="$(get_kaddy_counterpart "$dest_dir")"
readarray -t pkgs < <(find /var/cache/pacman/pkg/ -mindepth 1 -maxdepth 1 -type f)
if [ "$pkgs" ]; then
action_now "copying from /var/cache/pacman/pkg to ${dest_dir/$HOME/\~}"
cp -r "${pkgs[@]}" "$dest_dir"
action_now "copying from /var/cache/pacman/pkg to ${dest_kaddy_dir/$HOME/\~}"
cp -r "${pkgs[@]}" "$dest_kaddy_dir"
action_now 'removing pkgs in /var/cache/pacman/pkg'
sudo rm "${pkgs[@]}"
action_now 'checking if there are older pkgs to remove'
remove_older_pkgs
else
red 'nothing to copy'
fi && accomplished ;;
esac