Skip to content

Instantly share code, notes, and snippets.

@wolfiex
Created February 1, 2023 12:25
Show Gist options
  • Save wolfiex/52cca9af5f740ab00d18b0a49ee4ad52 to your computer and use it in GitHub Desktop.
Save wolfiex/52cca9af5f740ab00d18b0a49ee4ad52 to your computer and use it in GitHub Desktop.
Script to node_modules from a computer.
'''
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