-
Notifications
You must be signed in to change notification settings - Fork 39
/
rmshit.py
executable file
·125 lines (105 loc) · 2.9 KB
/
rmshit.py
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
#! /usr/bin/env python3
import os
import shutil
from pathlib import Path
import yaml
DEFAULT_CONFIG = """
- ~/.adobe # Flash crap
- ~/.macromedia # Flash crap
- ~/.recently-used
- ~/.local/share/recently-used.xbel
- ~/.thumbnails
- ~/.gconfd
- ~/.gconf
- ~/.local/share/gegl-0.2
- ~/.FRD/log/app.log # FRD
- ~/.FRD/links.txt # FRD
- ~/.objectdb # FRD
- ~/.gstreamer-0.10
- ~/.pulse
- ~/.esd_auth
- ~/.config/enchant
- ~/.spicec # contains only log file; unconfigurable
- ~/.dropbox-dist
- ~/.parallel
- ~/.dbus
- ~/ca2 # WTF?
- ~/ca2~ # WTF?
- ~/.distlib/ # contains another empty dir, don't know which software creates it
- ~/.bazaar/ # bzr insists on creating files holding default values
- ~/.bzr.log
- ~/.nv/
- ~/.viminfo # configured to be moved to ~/.cache/vim/viminfo, but it is still sometimes created...
- ~/.npm/ # npm cache
- ~/.java/
- ~/.swt/
- ~/.oracle_jre_usage/
- ~/.openjfx/
- ~/.org.jabref.gui.JabRefMain/
- ~/.org.jabref.gui.MainApplication/
- ~/.jssc/
- ~/.tox/ # cache directory for tox
- ~/.pylint.d/
- ~/.qute_test/
- ~/.QtWebEngineProcess/
- ~/.qutebrowser/ # created empty, only with webengine backend
- ~/.asy/
- ~/.cmake/
- ~/.gnome/
- ~/unison.log
- ~/.texlive/
- ~/.w3m/
- ~/.subversion/
- ~/nvvp_workspace/ # created empty even when the path is set differently in nvvp
- ~/.ansible/
- ~/.fltk/
- ~/.vnc/
- ~/.local/share/Trash/ # VSCode puts deleted files here
"""
def read_config():
"""
Reads the list of shitty files from a YAML config.
"""
config_dir = os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config/"))
config_path = Path(config_dir) / "rmshit.yaml"
# write default config if it does not exist
if not config_path.exists():
with open(config_path, "w") as f:
print(DEFAULT_CONFIG.strip(), file=f)
with open(config_path, "r") as f:
return yaml.safe_load(f)
def yesno(question, default="n"):
"""
Asks the user for YES or NO, always case insensitive.
Returns True for YES and False for NO.
"""
prompt = "%s (y/[n]) " % question
ans = input(prompt).strip().lower()
if not ans:
ans = default
if ans == "y":
return True
return False
def rmshit():
shittyfiles = read_config()
print("Found shittyfiles:")
found = []
for f in shittyfiles:
absf = os.path.expanduser(f)
if os.path.exists(absf):
found.append(absf)
print(" %s" % f)
if len(found) == 0:
print("No shitty files found :)")
return
if yesno("Remove all?", default="n"):
for f in found:
if os.path.isfile(f):
os.remove(f)
else:
shutil.rmtree(f)
print("All cleaned")
else:
print("No file removed")
if __name__ == "__main__":
rmshit()