Created
February 1, 2023 12:25
-
-
Save wolfiex/52cca9af5f740ab00d18b0a49ee4ad52 to your computer and use it in GitHub Desktop.
Script to node_modules from a computer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
nmrm.py | |
A script to remove node modules folders on Unix-like machines. | |
Author: Daniel Ellis | |
code @ danielellisresearch . com | |
Installation: | |
pip3 install cutie halo numpy | |
''' | |
from halo import Halo | |
import numpy as np | |
import os, cutie | |
######################## | |
# get the node modules | |
######################## | |
spinner = Halo(text='Fiinding node_modules', spinner='dots') | |
spinner.start() | |
modules = os.popen('find . -name "node_modules" -type d -prune').read().split() | |
spinner.stop() | |
selected = [] | |
######################## | |
# select what to remove | |
######################## | |
splitmodules = np.array_split(modules,len(modules)//20) | |
for i,subset in enumerate(splitmodules): | |
print( f'\n\n(Selecting from group {i} out of {len(splitmodules)}.\n Previous" {len(selected)} selections\n Use arrow keys to move [], and space to select.\n When done press ENTER.\n') | |
selected.extend(subset[cutie.select_multiple( | |
subset, | |
deselected_unticked_prefix=" KEEP ", | |
selected_unticked_prefix="[ KEEP ]", | |
selected_ticked_prefix="[ --REMOVE-- ]", | |
ticked_indices=[], | |
deselected_confirm_label=" [[[[ --REMOVE-- ]]]] ", | |
selected_confirm_label="[ [[[[ --REMOVE-- ]]]] ]" | |
)]) | |
######################## | |
# Irreversably delete | |
######################## | |
print( '\nYou have selected:') | |
for i in selected: print(f' - {i}') | |
print(''' | |
######################## | |
# Irreversably delete | |
########################''') | |
if cutie.prompt_yes_or_no("Type 'Yes' to delete."): | |
spinner.start() | |
for s in selected: | |
spinner.text = 'Deleting '+s | |
os.system('rm -rf '+s) | |
spinner.stop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment