-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvscode_cleaner.sh
executable file
·61 lines (51 loc) · 1.56 KB
/
vscode_cleaner.sh
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
#!/bin/bash
# Visual Studio Code creates heavy hidden directoiries .vscode/ipch when working on C/C++ projects.
# IPCH (IntelliSense Precompiled Header) is cache directory left by IntelliSense
# This script searches for them, and removes after user confirmation.
#
# (c) 2019 ppelikan
# https://github.com/ppelikan
dira1=".vscode" #first folder name
dira2="ipch" #name of folder inside the first one
dirb1=".vscode-cpptools"
dirb2="ipch"
done=0
del_dir() {
rm -r $1 #remove dir recursively
echo " Deleted!"
((done++))
}
ask_dir() {
res=0
sz="$(du -hs $1)" #get size of the given folder
echo "$sz"
echo -n 'Delete? [Y/N] '
read -n 1 CTN #wait for keypress
case $CTN in
y|Y)del_dir $1 ;;
q|Q)res=1 ;;
*) echo " Skipped..." ;;
esac
return 0
}
all=0
#nl='find xxxxx 2>dev/null' #hide unwanted output of find
found_dirs="$(find -name ${dira1} -type d -exec find '{}' -name ${dira2} -type d \;)" #find all dirs1 that contain dirs2
found_dirs+=$'\n'
found_dirs+="$(find -name ${dirb1} -type d -exec find '{}' -name ${dirb2} -type d \;)"
echo " "
IFS=$'\n' #allow to iterate found_dirs separated only by \n not by spaces
for i in $found_dirs; do
all+=1
ask_dir $i #ask user for response
if (("$res" == 1)); then #abandon task if user pressed Q
echo " Aborted."
break
fi
done
if (("$all" == 0)); then
echo "No directories found."
fi
if (("$done" != 0)); then
echo "Deleted: $done directories"
fi