forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript-command.template.js
executable file
·61 lines (50 loc) · 1.97 KB
/
script-command.template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
// Raycast Script Command Template
//
// Dependency: This script requires Nodejs.
// Install Node: https://nodejs.org/en/download/
//
// Duplicate this file and remove ".template" from the filename to get started.
// See full documentation here: https://github.com/raycast/script-commands
//
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title My First Script
// @raycast.mode fullOutput
// @raycast.packageName Raycast Scripts
//
// Optional parameters:
// @raycast.icon 🤖
// @raycast.argument1 { "type": "text", "placeholder": "js, css, html", "optional": true}
// @raycast.argument2 { "type": "text", "placeholder": "query" }
//
// Documentation:
// @raycast.description Write a nice and descriptive summary about your script command here
// @raycast.author Your name
// @raycast.authorURL An URL for one of your social medias
/*
ABOUT THIS TEMPLATE:
This template is meant to be a quick starting point for creating a script command using Nodejs.
This template demonstrates the following ideas:
* Extracting passed arguments.
* Using both required and optional arguments
* URI Encoding
* Outputting result to Raycast
* Opening a url using exec and the unix open command
* Use of destructuring
* Use of template literals
*/
const { exec } = require('child_process')
// Use destructuring to grab arguments.
// Use slice to start from position 3.
let [topic, query] = process.argv.slice(2)
let uri = `https://developer.mozilla.org/search?topic=${topic}&q=${encodeURIComponent(query)}`
// console.log() displays output in fullOutput mode.
console.log(`The arguments are: \n ${process.argv.join('\n ')}\n`)
console.log(`Your topic is "${topic}"`)
console.log(`Your query is "${query}"`)
console.log(`Your query uri encoded is "${encodeURIComponent(query)}"`)
console.log(`The uri is "${uri}"`)
// Uncomment the exec line below to open this query in your web browser.
// Use double quotes around the uri to avoid processing issues.
//exec(`open "${uri}"`)