Ricardo Bassete

Ricardo Bassete

// Name: Chmod Calculator
// Description: Asks the user what permissions to grant to a file/folder and creates a chmod command with those permissions
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
const permissions = ['read', 'write', 'execute']
function getValue(permissions: string[]) {
const r = permissions.includes('read') ? 4 : 0
const w = permissions.includes('write') ? 2 : 0
const x = permissions.includes('execute') ? 1 : 0
return r+w+x
}
const ownerPermissions: string[] = await select({
placeholder: 'Owner permissions',
alwaysOnTop: true,
strict: true,
}, permissions)
const groupPermissions: string[] = await select({
placeholder: 'Group permissions',
alwaysOnTop: true,
strict: true,
}, permissions)
const publicPermissions: string[] = await select({
placeholder: 'Public permissions',
alwaysOnTop: true,
strict: true,
}, permissions)
const command = `chmod ${getValue(ownerPermissions)}${getValue(groupPermissions)}${getValue(publicPermissions)}`
setSelectedText(command)

// Name: Clear Downloads Folder
// Description: Lists files and folders within your downloads folder and asks which items you want to remove
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
const downloadsFolder = home('Downloads')
const items = await readdir(downloadsFolder)
const itemsToRemove: string[] = await select({
placeholder: 'Select the items you want to remove',
alwaysOnTop: true,
strict: true,
}, items)
const wishToRemove = await arg({
placeholder: 'This will remove all selected items, do you want to continue?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false }
],
strict: true
})
if(wishToRemove) {
itemsToRemove.forEach(item => {
const itemPath = path.resolve(downloadsFolder, item)
remove(itemPath)
})
}