A simple script that asks the user what permissions to grant to a file/folder and creates a chmod command with those permissions

Chmod Calculator

// 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)