You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Name: Rename script files to match their name// Description: Renames script file names to match their name (// Name: Foo Bar -> foo-bar.ts)import"@johnlindquist/kit"import{stripName}from"@johnlindquist/kit"import*asfsfrom"fs/promises"importdedentfrom"dedent"// just for documentation purposesletexampleScript={"command": "rename-script-files-to-match-their-name","filePath": "/Users/strajk/.kenv/scripts/rename-script-files-to-match-their-name.ts","id": "/Users/strajk/.kenv/scripts/rename-script-files-to-match-their-name.ts","name": "Rename script files to match their name","timestamp": 1732375034783,"type": "Prompt"// ...}letscripts=awaitgetScripts()for(letscriptofscripts){letnormalizedName=stripName(script.name)letextname=path.extname(script.filePath)letbasename=path.basename(script.filePath,extname)if(basename!==script.command){console.log(dedent` This should never happen, basename and command should be the same: basename: ${basename} command: ${script.command} `)notify(`basename: ${basename} command: ${script.command}`)exit()}if(normalizedName!==basename){console.log(dedent` "${script.name}": current: ${basename} normalized: ${normalizedName} `)letconfirmed=awaitarg({placeholder: `Rename "${basename}" to "${normalizedName}"`,choices: [{name: "Yes",value: true},{name: "No",value: false}]})if(!confirmed){continue}console.log(`Renaming "${basename}" to: ${normalizedName}`)letnewPath=path.join(path.dirname(script.filePath),normalizedName+extname)awaitfs.rename(script.filePath,newPath)}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Open rename-script-files-to-match-their-name in Script Kit
Beta Was this translation helpful? Give feedback.
All reactions