-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcleanup
More file actions
executable file
·190 lines (164 loc) · 6.12 KB
/
cleanup
File metadata and controls
executable file
·190 lines (164 loc) · 6.12 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
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
#!/usr/bin/env bash
#
# Cleanup home for XDG compliance
#
if [[ -z "$DOTFILES" ]]; then
cd -- "$(dirname "$0")/.." || exit 1
DOTFILES="$PWD"
fi
. "${DOTFILES}/lib/helpers.sh"
. "${DOTFILES}/lib/pretty.bash"
# ============================================================================
# ENV validation
# ============================================================================
if [[ -z "$BDOTDIR" ]] ||
[[ -z "$XDG_CONFIG_HOME" ]] ||
[[ -z "$XDG_DATA_HOME" ]]; then
__dko_err "DOTFILES are not set up, run this after symlinking and restarting"
__dko_err_ "shell"
exit 1
fi
# ============================================================================
# Cleanup functions
# ============================================================================
# Move entire dir or file somewhere else (create dir if needed)
# $1 full path to move (can be file or dir)
# $2 full destination path
__move() {
[[ ! -e "$1" ]] && __dko_ok "${1} not found" && return 0
[[ -e "$2" ]] && __dko_err "${2} exists, cannot move ${1}" && return 1
__dko_status "Move ${1} to ${2}"
dko-maybemkdir "$(dirname "${2}")" || return 1
mv -- "$1" "$2" && __dko_ok "Moved ${1} to ${2}"
}
# Move contents of one dir into another
# $1 source directory, removed on completion
# $2 destination directory, created if needed
__merge_dir() {
[[ ! -d "$1" ]] && __dko_ok "${1} not found" && return 0
__dko_status "Merge ${1} into ${2}"
dko-maybemkdir "$2" || return 1
mv -- "${1}/*" "$2" && __dko_ok "${1}/* moved into ${2}"
mv -- "${1}/.*" "$2" && __dko_ok "${1}/.* moved into ${2}"
[[ -d "$1" ]] && rmdir -- "$1" && __dko_ok "${1} removed"
}
# Remove file or dir completely with confirmation
# $1 path to completely remove
__remove() {
if [[ -f "$1" ]] || [[ -L "$1" ]]; then
rm -i -- "$1" && __dko_ok "${1} removed"
elif [[ -d "$1" ]]; then
rm -I -r -- "$1" && __dko_ok "${1} removed"
fi
[[ ! -e "$1" ]] && __dko_ok "${1} not found" && return 0
}
# Logic for NVM
__clean_nvm() {
[ -d "$FNM_DIR" ] && return 0
[ -z "$NVM_DIR" ] && return 0
[[ "${NVM_DIR}" != "${XDG_CONFIG_HOME}/nvm" ]] && {
__dko_err "NVM_DIR not set properly. Should be ${XDG_CONFIG_HOME}/nvm"
return 1
}
dko-maybemkdir "${NVM_DIR}" || return 1
__move "${XDG_CONFIG_HOME}/.nvm" "$NVM_DIR"
__move "${HOME}/.nvm" "$NVM_DIR"
}
# ============================================================================
# main
# ============================================================================
__move "${HOME}/.ctags.d" "${XDG_CONFIG_HOME}/ctags"
__move "${HOME}/.gimp-2.8" "${XDG_CONFIG_HOME}/GIMP/2.8"
__move "${HOME}/.grip" "${XDG_CONFIG_HOME}/grip"
__move "${HOME}/.fonts.conf" "${XDG_DATA_HOME}/fontconfig/fonts.conf"
__move "${HOME}/.inputrc" "${XDG_CONFIG_HOME}/readline/inputrc"
__move "${HOME}/.parallel" "${XDG_CONFIG_HOME}/parallel"
__move "${HOME}/.pulse-cookie" "${XDG_CONFIG_HOME}/pulse/cookie"
__move "${HOME}/.solargraph" "${XDG_CACHE_HOME}/solargraph"
__move "${HOME}/.vagrant.d" "${XDG_DATA_HOME}/vagrant"
__merge_dir "${HOME}/.fonts" "${XDG_DATA_HOME}/fonts"
[[ -n "$ASDF_DATA_DIR" ]] && __move "${HOME}/.asdf" "${ASDF_DATA_DIR}"
[[ -n "$CARGO_HOME" ]] && __move "${HOME}/.cargo" "$CARGO_HOME"
[[ -n "$COMPOSER_HOME" ]] && __move "${HOME}/.composer" "$COMPOSER_HOME"
[[ -n "$GNUPGHOME" ]] && [[ -d "${HOME}/.gnupg" ]] && {
rmdir "${HOME}/.gnupg" 2>/dev/null || __move "${HOME}/.gnupg" "$GNUPGHOME"
}
[[ -n "$PYLINTHOME" ]] && __move "${HOME}/.pylint.d" "$PYLINTHOME"
[[ -n "$YARN_CACHE_FOLDER" ]] && __move "${HOME}/.yarn-cache" "$YARN_CACHE_FOLDER"
# ==========================================================================
# Removals
# ==========================================================================
# delete shell history not in XDG_STATE_HOME
case $HISTFILE in
"${HOME}/.bash_history" | \
"${HOME}/.zhistory" | \
"${HOME}/.zsh_history" | \
"${HOME}/.local/bash_history" | \
"${HOME}/.local/zsh_history")
dko_warn "Symlink and restart shell to set HISTFILE location properly."
dko_warn "Then run cleanup again to remove old histfile paths."
;;
esac
__remove "${HOME}/.bash_history"
__remove "${HOME}/.zhistory"
__remove "${HOME}/.zsh_history"
__remove "${HOME}/.local/bash_history"
__remove "${HOME}/.local/zsh_history"
! dko-same "${HOME}/.dotfiles/bash/dot.bash_profile" "${HOME}/.bash_profile" &&
__remove "${HOME}/.bash_profile"
! dko-same "${HOME}/.dotfiles/bash/dot.bashrc" "${HOME}/.bashrc" \
__remove "${HOME}/.bashrc"
! dko-same "${HOME}/.dotfiles/zsh/dot.zshenv" "${HOME}/.zshenv" \
__remove "${HOME}/.zshenv"
# support dropped in 2.2.0
__remove "${HOME}/.agignore"
# should be ~/.config/ctags/*.ctags
__remove "${HOME}/.ctags"
# should be in XDG_CONFIG_HOME/fzf/fzf.bash and fzf.zsh or /usr/share/fzf
__remove "${HOME}/.fzf.bash"
__remove "${HOME}/.fzf.zsh"
__remove "${HOME}/.ideavimrc"
# alias points to dotfile
__remove "${HOME}/.mdlrc"
# should be in XDG as of 0.9.0
__remove "${HOME}/.proselint"
# should be "${XDG_DATA_HOME}/forgit"
__remove "${HOME}/.forgit"
# should be symlinked in XDG
__remove "${HOME}/.gitconfig"
# should be symlinked in XDG
__remove "${HOME}/.gitignore"
# garbage, old xdg-utils made it, maybe has .desktop entries
__remove "${HOME}/.gnome"
# i will never use hyper terminal
__remove "${HOME}/.hyper.js"
__remove "${XDG_CONFIG_HOME}/hyper"
# i will never use kitty terminal
__remove "${XDG_CONFIG_HOME}/kitty"
__remove "${XDG_CONFIG_HOME}/markdownlint.json"
# mackup doesn't work any more
__remove "${HOME}/.mackup.cfg"
# should be in .local; probably created on ZSH startup
__remove "${HOME}/.wget-hsts"
# stopped using tern
__remove "${HOME}/.tern-config"
__remove "${HOME}/.tern-project"
# should be ~/.config/tldr
__remove "${HOME}/.tldr"
# Useless
__remove "${HOME}/.zlogin"
__remove "${HOME}/.zprofile"
# Created by /etc/zshrc_Apple_Terminal -- apple's way of sharing session data
# for a shell.
__remove "${HOME}/.zsh_sessions"
# should be ~/.dotfiles/zsh/.zshrc
__remove "${HOME}/.zshrc"
# should be XDG_DATA_HOME/zinit
__remove "${DOTFILES}/zsh/.zinit"
__remove "${DOTFILES}/zsh/.zplugin"
# obsolete
__remove "${XDG_DATA_HOME}/nvim/mason"
__remove "${XDG_DATA_HOME}/zplug"
"${DOTFILES}/bin/dko-fix-git-completion"
# NVM
__clean_nvm