Ricardo Bassete

Ricardo Bassete

// Name: Cron Builder
// Description: Prompts user for desired intervals, creates a cron schedule based on user input, and describes it
// Author: Ricardo Gonçalves Bassete
import "@johnlindquist/kit"
import cronstrue from 'cronstrue';
const commonValues = [
'------------------------------',
'* = any value',
', = value list separator',
'- = range of values',
'/ = step values',
]
const minuteValues = [
"Allowed Values = 0 - 59",
...commonValues,
]
const hourValues = [
"Allowed Values = 0 - 23",
...commonValues,
]
const dayMonthValues = [
"Allowed Values = 1 - 31",
...commonValues,
]
const monthValues = [
"Allowed Values = 1 - 12",
...commonValues,
]
const dayWeekValues = [
"Allowed Values = 0 - 6",
'------------------------------',
"0 = Sunday",
"1 = Monday",
"2 = Tuesday",
"3 = Wednesday",
"4 = Thursday",
"5 = Friday",
"6 = Saturday",
...commonValues
]
const minute = await arg({
placeholder: 'Minute interval, default is *',
alwaysOnTop: true,
hint: minuteValues.join('\n')
}).then(input => input === '' ? '*' : input)
const hour = await arg({
placeholder: 'Hour interval, default is *',
alwaysOnTop: true,
hint: hourValues.join('\n')
}).then(input => input === '' ? '*' : input)
const dayMonth = await arg({
placeholder: 'Day of the month interval, default is *',
alwaysOnTop: true,
hint: dayMonthValues.join('\n')
}).then(input => input === '' ? '*' : input)
const month = await arg({
placeholder: 'Month interval, default is *',
alwaysOnTop: true,
hint: monthValues.join('\n')
}).then(input => input === '' ? '*' : input)
const dayWeek = await arg({
placeholder: 'Day of the week interval, default is *',
alwaysOnTop: true,
hint: dayWeekValues.join('\n')
}).then(input => input === '' ? '*' : input)
const result = `${minute} ${hour} ${dayMonth} ${month} ${dayWeek}`
await div({
alwaysOnTop: true,
enter: 'Press Enter to paste result',
html: `
<div class="p-5 prose prose-sm">
<h1>${cronstrue.toString(result)}</h1>
<p>${result}</p>
</div>
`,
onSubmit: () => setSelectedText(result)
})

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