-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatilusHider.py
84 lines (48 loc) · 1.36 KB
/
natilusHider.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
from pathlib import Path
import os, sys
if sys.version_info<(3,6):
raise Exception("Python version 3.6 or above is required")
exec_loc = sys.executable
filePatternToHide = [
"*.out",
]
home = str(Path.home())
rootDir = f"{home}/.local/share/nautilus/scripts/nhider"
os.makedirs(rootDir,exist_ok=True)
hidFile = f"{rootDir}/hide.py"
unhidFile = f"{rootDir}/unhideAll.py"
hidallFile = f"{rootDir}/hideAll.py"
# create a `.hidden` file and hide the selected files
with open(hidFile,'w') as f:
f.write(f'''#!{exec_loc}
import os, sys
hidPath = f"{{os.getcwd()}}/.hidden"
filesToHide ='\\n' + '\\n'.join(sys.argv[1:])
with open(hidPath, 'a' if os.path.exists(hidPath) else 'w') as f:
f.write(filesToHide)
''')
# just delet the `.hidden` file
with open(unhidFile,'w') as f:
f.write(f'''#!{exec_loc}
import os
hidPath = f"{{os.getcwd()}}/.hidden"
if os.path.exists(hidPath):
os.remove(hidPath)
''')
# glob the pattern and hide
with open(hidallFile,'w') as f:
f.write(f'''#!{exec_loc}
import os
from glob import glob
hidPath = f"{{os.getcwd()}}/.hidden"
filePtrn = {filePatternToHide}
ff = []
for p in filePtrn:
ff += glob(p)
filesToHide ='\\n' + '\\n'.join(ff)
with open(hidPath, 'a' if os.path.exists(hidPath) else 'w') as f:
f.write(filesToHide)
''')
os.chmod(hidFile,0o766)
os.chmod(unhidFile,0o766)
os.chmod(hidallFile,0o766)