@lexjs/web 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +800 -0
- package/dist/actions/core-actions.js +6 -0
- package/dist/actions/npm-actions.js +38 -0
- package/dist/actions/permission-actions.js +21 -0
- package/dist/api/browser/browser.js +111 -0
- package/dist/api/browser/browser.types.js +1 -0
- package/dist/api/matchers/matchers.js +9 -0
- package/dist/api/site/site.js +248 -0
- package/dist/api/site/site.types.js +1 -0
- package/dist/api/utils/extract-protocol.js +10 -0
- package/dist/api/utils/remove-protocol.js +8 -0
- package/dist/api/utils/return-type-guard.js +7 -0
- package/dist/api/utils/slash.js +21 -0
- package/dist/command/args/config-args.js +9 -0
- package/dist/command/args/data-args.js +110 -0
- package/dist/command/args/invalid-args.js +11 -0
- package/dist/command/args/query-args.js +121 -0
- package/dist/command/args/validate-args.js +126 -0
- package/dist/command/options.js +58 -0
- package/dist/config/config-file.js +66 -0
- package/dist/config/config-flags.js +42 -0
- package/dist/config/file-editor.js +26 -0
- package/dist/config/handle-config.js +12 -0
- package/dist/constants.js +15 -0
- package/dist/create-app/main.js +121 -0
- package/dist/create-app/paths.js +24 -0
- package/dist/create-app/schema/base.json +21 -0
- package/dist/create-app/schema/browsers.json +60 -0
- package/dist/create-app/schema/sites.json +71 -0
- package/dist/create-app/script-contents.js +18 -0
- package/dist/create-app/tree.js +25 -0
- package/dist/data/app-data.js +12 -0
- package/dist/data/config-data.js +35 -0
- package/dist/data/defaults.js +22 -0
- package/dist/data/initial-sites.js +36 -0
- package/dist/data/sort-config-data.js +17 -0
- package/dist/helpers/find-browser.js +9 -0
- package/dist/helpers/find-config-item.js +23 -0
- package/dist/helpers/find-nested.js +24 -0
- package/dist/helpers/find-profile.js +11 -0
- package/dist/helpers/find-site.js +15 -0
- package/dist/helpers/get-browser-name.js +9 -0
- package/dist/helpers/get-query-profiles.js +34 -0
- package/dist/main.js +19 -0
- package/dist/query/get-profiles-config.js +10 -0
- package/dist/query/get-query-browsers.js +33 -0
- package/dist/query/get-query-sites.js +49 -0
- package/dist/query/get-urls.js +85 -0
- package/dist/query/open-urls.js +30 -0
- package/dist/query/print-query.js +24 -0
- package/dist/query/query.js +19 -0
- package/dist/types/arg.types.js +1 -0
- package/dist/types/config.types.js +1 -0
- package/dist/types/primitive.type.js +1 -0
- package/dist/types/query.types.js +1 -0
- package/dist/types/utility.types.js +1 -0
- package/dist/utils/get-package-info.js +10 -0
- package/dist/utils/logger.js +15 -0
- package/dist/utils/parse-data.js +15 -0
- package/dist/utils/transform-text.js +7 -0
- package/dist/utils/yaml-files.js +6 -0
- package/package.json +88 -0
package/README.md
ADDED
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD029 -->
|
|
2
|
+
# `@lexjs/web`
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
CLI for making browser web searches from the shell.
|
|
9
|
+
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Keywords](#keywords)
|
|
13
|
+
- [URLs](#urls)
|
|
14
|
+
- [Options](#options)
|
|
15
|
+
- [Value options](#value-options)
|
|
16
|
+
- [Boolean options](#boolean-options)
|
|
17
|
+
- [Placement](#placement)
|
|
18
|
+
- [Site Options](#site-options):
|
|
19
|
+
- [`site`](#site)
|
|
20
|
+
- [`query`](#query)
|
|
21
|
+
- [`delimiter`](#delimiter)
|
|
22
|
+
- [`resource`](#resource)
|
|
23
|
+
- [`port`](#port)
|
|
24
|
+
- [`http`](#http)
|
|
25
|
+
- [Browser Options](#browser-options):
|
|
26
|
+
- [`browser`](#browser)
|
|
27
|
+
- [`profile`](#profile)
|
|
28
|
+
- [`incognito`](#incognito)
|
|
29
|
+
- [Other Options](#other-options):
|
|
30
|
+
- [`split`](#split)
|
|
31
|
+
- [`dry-run`](#dry-run)
|
|
32
|
+
- [Custom Flags](#custom-flags)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
**Step 1**. Run one of the following commands from any directory.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx @lexjs/web
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm dlx @lexjs/web
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
yarn dlx @lexjs/web
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
bunx @lexjs/web
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Step 2**. Follow the prompts to set up the command.
|
|
57
|
+
|
|
58
|
+
**Step 3**. Once the installation process is complete, add the following lines to your shell configuration file.
|
|
59
|
+
|
|
60
|
+
- For POSIX-compatible shells like bash or zsh
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# ~/.bashrc or ~/.zshrc
|
|
64
|
+
|
|
65
|
+
test -f ~/.lexjs/web/start.sh && . ~/.lexjs/web/start.sh
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- For PowerShell
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
# C:\Program Files\PowerShell\7\profile.ps1
|
|
72
|
+
|
|
73
|
+
if (Test-Path -Path "$env:HOMEPATH\.lexjs\web\bin") {
|
|
74
|
+
$env:Path = "$env:HOMEPATH\.lexjs\web\bin;$env:Path"
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
> 💡 To get the path of your PowerShell configuration file, type `$PROFILE.` and tab through the available options to choose the necessary profile.
|
|
79
|
+
|
|
80
|
+
**Step 4**. Restart your shell. The command should now be available.
|
|
81
|
+
|
|
82
|
+
The command name you set up during the installation is ready for use without any additional setup (we'll use `web` throughout the docs).
|
|
83
|
+
|
|
84
|
+
<pre><code>web hello world</code></pre>
|
|
85
|
+
|
|
86
|
+
> `https://google.com/search?q=hello%20world`
|
|
87
|
+
|
|
88
|
+
<pre><code>web Array.prototype.at <em>--mdn</em></code></pre>
|
|
89
|
+
|
|
90
|
+
> `https://developer.mozilla.org/search?q=Array.prototype.at`
|
|
91
|
+
|
|
92
|
+
<pre><code>web typescript tutorial <em>--youtube</em></code></pre>
|
|
93
|
+
|
|
94
|
+
> `https://youtube.com/results?search_query=typescript+tutorial`
|
|
95
|
+
|
|
96
|
+
To get help with command options, use the `--help` option:
|
|
97
|
+
|
|
98
|
+
<pre><code>web <em>--help</em></code></pre>
|
|
99
|
+
|
|
100
|
+
To check the installed version, use the `--version` option:
|
|
101
|
+
|
|
102
|
+
<pre><code>web <em>--version</em></code></pre>
|
|
103
|
+
|
|
104
|
+
## Usage
|
|
105
|
+
|
|
106
|
+
To perform basic web queries, provide **_space-separated values_**
|
|
107
|
+
|
|
108
|
+
<pre><code>web <em><values></em></code></pre>
|
|
109
|
+
|
|
110
|
+
The CLI will then construct 1 or more queries and open them in the browser.
|
|
111
|
+
|
|
112
|
+
There are 2 types of values:
|
|
113
|
+
|
|
114
|
+
1. Keywords
|
|
115
|
+
2. URLs
|
|
116
|
+
|
|
117
|
+
### Keywords
|
|
118
|
+
|
|
119
|
+
When providing keywords, only 1 web query is created using the values as a search term:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
web hello world
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
> `https://google.com/search?q=hello%20world`
|
|
126
|
+
|
|
127
|
+
In the absence of [_options_](#options), the CLI uses the **_default site_** to construct a web query, and opens it in the **_default browser_**:
|
|
128
|
+
|
|
129
|
+
- After installation, there is a set of initial sites you can use as search engines (default - Google).
|
|
130
|
+
- The operating system's default browser is used to open the web queries.
|
|
131
|
+
|
|
132
|
+
You can change these defaults and add new sites and browsers by setting up [_config_](#configuration).
|
|
133
|
+
|
|
134
|
+
#### _Initial sites_
|
|
135
|
+
|
|
136
|
+
| Site | Option Value |
|
|
137
|
+
| ------------- | :-----------------: |
|
|
138
|
+
| Google | `google` |
|
|
139
|
+
| DuckDuckGo | `duckduckgo` `duck` |
|
|
140
|
+
| GitHub | `github` |
|
|
141
|
+
| MDN | `mdn` |
|
|
142
|
+
| YouTube | `youtube` |
|
|
143
|
+
| NPM | `npm` |
|
|
144
|
+
|
|
145
|
+
The option value can be either supplied to the [`--site`](#site) option or used as a [_custom flag_](#custom-flags).
|
|
146
|
+
|
|
147
|
+
### URLs
|
|
148
|
+
|
|
149
|
+
When providing a URL value, the default behavior is to open it directly:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
web github.com
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
> `https://github.com`
|
|
156
|
+
|
|
157
|
+
If multiple URLs are provided, each URL creates a separate web query:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
web github.com npmjs.com developer.mozilla.org
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
> `https://github.com`
|
|
164
|
+
> `https://npmjs.com`
|
|
165
|
+
> `https://developer.mozilla.org`
|
|
166
|
+
|
|
167
|
+
#### _Keywords and URLs together_
|
|
168
|
+
|
|
169
|
+
If both keywords and URLs are provided, all values are treated as search term keywords:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
web most starred repos on github.com
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
> `https://google.com/search?q=most%20starred%20repos%20on%20github.com`
|
|
176
|
+
|
|
177
|
+
## Options
|
|
178
|
+
|
|
179
|
+
You can use options to override the CLI's defaults when constructing search queries.
|
|
180
|
+
|
|
181
|
+
<pre>
|
|
182
|
+
<code>web <em>--option</em></code>
|
|
183
|
+
<code>web <em>-x</em></code>
|
|
184
|
+
</pre>
|
|
185
|
+
|
|
186
|
+
Some options require a value (see [_value options_](#value-options)):
|
|
187
|
+
|
|
188
|
+
<pre>
|
|
189
|
+
<code>web <em>--option value</em></code>
|
|
190
|
+
</pre>
|
|
191
|
+
|
|
192
|
+
1-letter flags can be combined together with a single dash `-` as long as their combination is valid:
|
|
193
|
+
|
|
194
|
+
<pre><code>web <em>-xyz</em></code></pre>
|
|
195
|
+
|
|
196
|
+
which is equivalent to:
|
|
197
|
+
|
|
198
|
+
<pre><code>web <em>-x</em> <em>-y</em> <em>-z</em></code></pre>
|
|
199
|
+
|
|
200
|
+
> ⚠️ Combining 1-letter aliases of multiple [_value options_](#value-options) will result in invalid queries when such combinations are followed by a value. It is recommended to combine only the [_boolean options_](#boolean-options) which can be built-in or custom. If you want to add a 1-letter value option, it must be placed at the very end of the combination. If the value option is placed in the middle, the value argument will not get assigned to it.
|
|
201
|
+
|
|
202
|
+
### Value options
|
|
203
|
+
|
|
204
|
+
The following are built-in options that require a value:
|
|
205
|
+
|
|
206
|
+
| Option | Alias | Description |
|
|
207
|
+
| ----------------------- | :--------------: | ------------------------------------------ |
|
|
208
|
+
| [`browser`](#browser) | [`b`](#browser) | _Browser app to open_ |
|
|
209
|
+
| [`profile`](#profile) | [`p`](#profile) | _Browser profile to use_ |
|
|
210
|
+
| [`site`](#site) | [`s`](#site) | _Website to search_ |
|
|
211
|
+
| [`query`](#query) | [`q`](#query) | _Site's query string to use for searching_ |
|
|
212
|
+
| [`resource`](#resource) | [`r`](#resource) | _Site's resource to access_ |
|
|
213
|
+
| [`port`](#port) | [`:`](#port) | _Port number to add to the URL_ |
|
|
214
|
+
|
|
215
|
+
All value options work without any initial configuration but most options' usage can be enhanced by setting up the config. Refer to each option for more details.
|
|
216
|
+
|
|
217
|
+
### Boolean options
|
|
218
|
+
|
|
219
|
+
The following are built-in boolean options:
|
|
220
|
+
|
|
221
|
+
| Option | Alias | Description |
|
|
222
|
+
| ------------------------- | :---------------: | ----------------------------------------------------- |
|
|
223
|
+
| [`incognito`](#incognito) | [`i`](#incognito) | _Open in incognito / private mode_ |
|
|
224
|
+
| [`split`](#split) | ❌ | _Create a separate web query for each value argument_ |
|
|
225
|
+
| [`http`](#http) | ❌ | _Use the HTTP (non-secure) protocol_ |
|
|
226
|
+
| [`dry-run`](#dry-run) | [`n`](#dry-run) | _Display the output without opening browser tabs_ |
|
|
227
|
+
|
|
228
|
+
> ⚠️ Boolean options can be assigned values `true` and `false`. Using a boolean option in the command automatically sets its value to **_"true"_** but the option will still accept a boolean value that's placed after it. Therefore, make sure not to accidentally assign **_"true"_** or **_"false"_** to a flag if you do not intend it. Doing so will result in your web query missing the keyword **_"true"_** or **_"false"_** from the search term.
|
|
229
|
+
|
|
230
|
+
With browsers and sites configuration set up, you can also use [_custom flags_](#custom-flags) which are created from the keys and aliases of _browsers_, _browser profiles_, and _sites_ from the config file. Custom flags simplify your web queries by being a convenient substitute for value options.
|
|
231
|
+
|
|
232
|
+
### Placement
|
|
233
|
+
|
|
234
|
+
Options can be placed anywhere in the command:
|
|
235
|
+
|
|
236
|
+
<pre><code>web <em>--browser=firefox</em> this is <em>--incognito</em> an example <em>--site=duckduckgo</em> search query</code></pre>
|
|
237
|
+
|
|
238
|
+
<pre><code>web <em>-b=firefox</em> this is <em>-i</em> an example <em>-s=duckduckgo</em> search query</code></pre>
|
|
239
|
+
|
|
240
|
+
> Typically, you would place the options where they make sense visually such as at the start or the end of the command. This example just shows you that their placement does not impact the constructed queries.
|
|
241
|
+
|
|
242
|
+
The above command will do the following:
|
|
243
|
+
|
|
244
|
+
- construct a web query using
|
|
245
|
+
- keywords **_"this is an example search query"_**
|
|
246
|
+
- the **_DuckDuckGo_** search engine (`--site=duckduckgo`)
|
|
247
|
+
- open the constructed query in a new **_Firefox_** tab (`--browser=firefox`)
|
|
248
|
+
- in **_incognito / private mode_** (`--incognito`)
|
|
249
|
+
|
|
250
|
+
## Configuration
|
|
251
|
+
|
|
252
|
+
Creating configuration allows you to customize the CLI usage and enhance many of the built-in options.
|
|
253
|
+
|
|
254
|
+
<pre><code>web <em>--config</em></code></pre>
|
|
255
|
+
|
|
256
|
+
### Sites configuration
|
|
257
|
+
|
|
258
|
+
<pre><code>web <em>--config sites</em></code></pre>
|
|
259
|
+
|
|
260
|
+
### Browsers configuration
|
|
261
|
+
|
|
262
|
+
<pre><code>web <em>--config browsers</em></code></pre>
|
|
263
|
+
|
|
264
|
+
> The `--config` option can match the correct config by accepting partial values indicating the beginning of the option's value like `site`, `s`, `brow`, `br` and any other.
|
|
265
|
+
|
|
266
|
+
The CLI uses VS Code to open config files by default. To update the editor command that opens config files, run this:
|
|
267
|
+
|
|
268
|
+
<pre><code>web <em>--config editor</em></code></pre>
|
|
269
|
+
|
|
270
|
+
Each config file includes a reference to a schema that helps you write valid configuration, with editor autocompletion and inline validation so mistakes get flagged as you type.
|
|
271
|
+
|
|
272
|
+
## Site Options
|
|
273
|
+
|
|
274
|
+
## `site`
|
|
275
|
+
|
|
276
|
+
Specifies what website or search engine to query.
|
|
277
|
+
|
|
278
|
+
⚡ Takes a value.
|
|
279
|
+
⚙️ Allows configuration.
|
|
280
|
+
|
|
281
|
+
### Options
|
|
282
|
+
|
|
283
|
+
`--site` `-s`
|
|
284
|
+
|
|
285
|
+
### Usage
|
|
286
|
+
|
|
287
|
+
<pre><code>web <em>--site=value</em></code></pre>
|
|
288
|
+
|
|
289
|
+
`value` is one of the following:
|
|
290
|
+
|
|
291
|
+
1. **_Site key or alias in the config._** For example, `google`, `npm`, `duckduckgo`, or `duck`
|
|
292
|
+
|
|
293
|
+
```yaml
|
|
294
|
+
google:
|
|
295
|
+
url: google.com
|
|
296
|
+
query: search?q=
|
|
297
|
+
|
|
298
|
+
npm:
|
|
299
|
+
url: npmjs.com
|
|
300
|
+
query: search?q=
|
|
301
|
+
|
|
302
|
+
duckduckgo:
|
|
303
|
+
url: duckduckgo.com
|
|
304
|
+
delimiter: "+"
|
|
305
|
+
alias: duck
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
> 💡 Each site definition in the config must have a `url` property pointing to the site's base URL (protocol is not required)
|
|
309
|
+
|
|
310
|
+
> 💡 Setting up sites config allows using site keys and aliases as the option's value and as [custom flags](#custom-flags).
|
|
311
|
+
|
|
312
|
+
<pre><code>web @lexjs/web <em>--site npm</em></code></pre>
|
|
313
|
+
|
|
314
|
+
> `https://npmjs.com/search?q=@lexjs/web`
|
|
315
|
+
|
|
316
|
+
When supplying URL values to the command, this option overrides the default behavior of opening the URLs. Instead, they are treated as search term keywords for the provided site. For example:
|
|
317
|
+
|
|
318
|
+
<pre><code>web github.com <em>--site google</em></code></pre>
|
|
319
|
+
|
|
320
|
+
> `https://google.com/search?q=github.com`
|
|
321
|
+
|
|
322
|
+
2. **_An arbitrary URL string_** like `google.com/search?q=` or `example.com`
|
|
323
|
+
|
|
324
|
+
<pre><code>web @lexjs/web <em>--site npmjs.com/search?q=</em></code></pre>
|
|
325
|
+
|
|
326
|
+
> `https://npmjs.com/search?q=@lexjs/web`
|
|
327
|
+
|
|
328
|
+
> ⚠️ Non-URL values are not allowed.
|
|
329
|
+
|
|
330
|
+
When using the option with an arbitrary URL, it behaves in the same way as any other site from the config, meaning that you can use other options such as `--query`, `--resource`, `--port`, `--split`, or `--http`.
|
|
331
|
+
|
|
332
|
+
Note that since a URL value is a basic string, the CLI will simply append it with whatever keywords are supplied. If the URL has no query string that ends with an equals sign (`=`), the values will be added after a forward-slash (`/`), e.g.
|
|
333
|
+
|
|
334
|
+
<pre><code>web <em>--site example.com</em> hello world</code></pre>
|
|
335
|
+
|
|
336
|
+
> `https://example.com/hello%20world`
|
|
337
|
+
|
|
338
|
+
## `query`
|
|
339
|
+
|
|
340
|
+
Specifies what **_query string_** to use for searching a site. This query string is a URL segment that is appended to the site's base URL and allows to _search_ that site with the provided keywords. There could be multiple ways to search a site and this option allows to specify it.
|
|
341
|
+
|
|
342
|
+
⚡ Takes a value.
|
|
343
|
+
🛠️ Requires a `--site` option.
|
|
344
|
+
🛠️ Requires keywords.
|
|
345
|
+
⚙️ Allows configuration.
|
|
346
|
+
|
|
347
|
+
### Options
|
|
348
|
+
|
|
349
|
+
`--query` `-q`
|
|
350
|
+
|
|
351
|
+
### Usage
|
|
352
|
+
|
|
353
|
+
This option must be used with the `--site` option and keywords.
|
|
354
|
+
|
|
355
|
+
- If the site is not specified, validation will fail and the web query will not be performed.
|
|
356
|
+
- If keywords are not provided, only the base URL will be opened (i.e. the query `value` is not added).
|
|
357
|
+
|
|
358
|
+
<pre><code>web <em>--query=value</em> <em>--site=site</em> <keywords></code></pre>
|
|
359
|
+
|
|
360
|
+
`value` is one of the following:
|
|
361
|
+
|
|
362
|
+
1. **_URL segment string._** For example, `search?q=` or `?q=`
|
|
363
|
+
|
|
364
|
+
<pre><code>web <em>--query ?q=</em> <em>--site duckduckgo.com</em> hello world</code></pre>
|
|
365
|
+
|
|
366
|
+
> `https://duckduckgo.com/?q=hello%20world`
|
|
367
|
+
|
|
368
|
+
2. **_Query key in the site's "query" config._** For example, `main`, `images`, `bar`, or `deep`
|
|
369
|
+
|
|
370
|
+
```yaml
|
|
371
|
+
example:
|
|
372
|
+
url: example.com
|
|
373
|
+
query:
|
|
374
|
+
main: search?q=
|
|
375
|
+
images: images?q=
|
|
376
|
+
foo:
|
|
377
|
+
bar: foobar?q=
|
|
378
|
+
baz:
|
|
379
|
+
deep: foobaz?q=
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
> ⚠️ Using keys like `foo` and `baz` that do not point to a string value is not valid.
|
|
383
|
+
|
|
384
|
+
> 💡 The `query` property itself can be a string in the config.
|
|
385
|
+
|
|
386
|
+
Most of the time when querying a site, the `--query` option will not be provided. In these cases, it defaults to either the string value or the `main` property's value, depending on how the `query` config is set up.
|
|
387
|
+
|
|
388
|
+
### Multiple options
|
|
389
|
+
|
|
390
|
+
Supplying multiple `--query` options will create a separate URL for each value.
|
|
391
|
+
|
|
392
|
+
## `delimiter`
|
|
393
|
+
|
|
394
|
+
Specifies the delimiter character used by the site to separate keywords.
|
|
395
|
+
|
|
396
|
+
⚡ Takes a value.
|
|
397
|
+
🛠️ Requires a `--site` option.
|
|
398
|
+
❌ No configuration.
|
|
399
|
+
|
|
400
|
+
### Options
|
|
401
|
+
|
|
402
|
+
`--delimiter` `-d`
|
|
403
|
+
|
|
404
|
+
### Usage
|
|
405
|
+
|
|
406
|
+
This option only works in conjunction with the `--site` option where the site is specified as a URL. If this option is used with a site that **_is_** defined in the config, then the option has no effect.
|
|
407
|
+
|
|
408
|
+
<pre><code>web typescript docs <em>--delimiter=+</em> <em>--site duckduckgo.com</em> <em>--query=?q=</em></code></pre>
|
|
409
|
+
|
|
410
|
+
> `https://duckduckgo.com/?q=typescript+docs`
|
|
411
|
+
|
|
412
|
+
When the delimiter option is not specified and the site is not defined in the config, the delimiter defaults to a single whitespace character.
|
|
413
|
+
|
|
414
|
+
<pre><code>web typescript docs <em>--site duckduckgo.com</em> <em>--query=?q=</em></code></pre>
|
|
415
|
+
|
|
416
|
+
> `https://duckduckgo.com/?q=typescript%20docs`
|
|
417
|
+
|
|
418
|
+
## `resource`
|
|
419
|
+
|
|
420
|
+
Overrides the default behavior of _searching_ a site by specifying the site's route to be accessed directly.
|
|
421
|
+
|
|
422
|
+
⚡ Takes a value.
|
|
423
|
+
🛠️ Requires an `--site` option.
|
|
424
|
+
⚙️ Allows configuration.
|
|
425
|
+
|
|
426
|
+
### Options
|
|
427
|
+
|
|
428
|
+
`--resource` `-r`
|
|
429
|
+
|
|
430
|
+
### Usage
|
|
431
|
+
|
|
432
|
+
This option must be used with the `--site` option.
|
|
433
|
+
|
|
434
|
+
- If the site is not specified, validation will fail and the web query will not be performed.
|
|
435
|
+
|
|
436
|
+
<pre><code>web <em>--resource=value</em> <em>--site=site</em></code></pre>
|
|
437
|
+
|
|
438
|
+
`value` is one of the following:
|
|
439
|
+
|
|
440
|
+
1. **_URL segment string._** For example
|
|
441
|
+
|
|
442
|
+
<pre><code>web <em>--resource teapot</em> <em>--site google.com</em></code></pre>
|
|
443
|
+
|
|
444
|
+
> `https://google.com/teapot`
|
|
445
|
+
|
|
446
|
+
<pre><code>web <em>--resource path/to/resource</em> <em>--site example.com</em></code></pre>
|
|
447
|
+
|
|
448
|
+
> `https://example.com/path/to/resource`
|
|
449
|
+
|
|
450
|
+
2. **_Resource key in the site's "resources" config._** For example, `test`, `bar`, `baz` or `example`
|
|
451
|
+
|
|
452
|
+
```yaml
|
|
453
|
+
example:
|
|
454
|
+
url: example.com
|
|
455
|
+
resources:
|
|
456
|
+
test: path/to/resource
|
|
457
|
+
foo:
|
|
458
|
+
bar: "?foo=bar"
|
|
459
|
+
baz: "?foo=baz"
|
|
460
|
+
deeply:
|
|
461
|
+
nested:
|
|
462
|
+
example: deeply/nested/example/resource
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
> ⚠️ Using keys like `foo`, `deeply`, or `nested` that do not point to a string value is not valid.
|
|
466
|
+
|
|
467
|
+
### Command values
|
|
468
|
+
|
|
469
|
+
When supplying command values, each value is used in a separate web query as a URL path segment after the provided resource.
|
|
470
|
+
|
|
471
|
+
For example, the following creates 3 distinct web queries:
|
|
472
|
+
|
|
473
|
+
<pre><code>web typescript react @lexjs/web <em>--resource package</em> <em>--site npmjs.com</em></code></pre>
|
|
474
|
+
|
|
475
|
+
> `https://npmjs.com/package/typescript`
|
|
476
|
+
> `https://npmjs.com/package/react`
|
|
477
|
+
> `https://npmjs.com/package/@lexjs/web`
|
|
478
|
+
|
|
479
|
+
### Combining resources
|
|
480
|
+
|
|
481
|
+
You can combine multiple resources together to create a single search query by using the `::` separator. Each resource can be either a key from the site's `resources` config or an arbitrary string.
|
|
482
|
+
|
|
483
|
+
Let's examine some scenarios using the following GitHub site config:
|
|
484
|
+
|
|
485
|
+
```yaml
|
|
486
|
+
github:
|
|
487
|
+
url: github.com
|
|
488
|
+
query: search?q=
|
|
489
|
+
resources:
|
|
490
|
+
profile: LexBorisoff
|
|
491
|
+
tabs:
|
|
492
|
+
repos: "?tab=repositories"
|
|
493
|
+
projects: "?tab=projects"
|
|
494
|
+
stars: "?tab=stars"
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
#### _Combining resource keys_
|
|
498
|
+
|
|
499
|
+
You can generate a URL that accesses a profile's repositories page:
|
|
500
|
+
|
|
501
|
+
<pre><code>web <em>--resource profile::repos</em> <em>--site github</em></code></pre>
|
|
502
|
+
|
|
503
|
+
> `https://github.com/LexBorisoff?tab=repositories`
|
|
504
|
+
|
|
505
|
+
To use a string literally in situations where it has the same value as the resource key, you can escape it with a `/`:
|
|
506
|
+
|
|
507
|
+
<pre><code>web <em>--resource profile::/repos</em> <em>--site github</em></code></pre>
|
|
508
|
+
|
|
509
|
+
> `https://github.com/LexBorisoff/repos`
|
|
510
|
+
|
|
511
|
+
In some shells, to escape the first resource key you also need to escape the forward slash:
|
|
512
|
+
|
|
513
|
+
<pre><code>web <em>--resource //profile::/repos</em> <em>--site github</em></code></pre>
|
|
514
|
+
|
|
515
|
+
> `https://github.com/profile/repos`
|
|
516
|
+
|
|
517
|
+
#### _Combining a resource key with an arbitrary string_
|
|
518
|
+
|
|
519
|
+
You can generate a URL that accesses a profile's arbitrary repository:
|
|
520
|
+
|
|
521
|
+
<pre><code>web <em>--resource profile::web</em> <em>--site github</em></code></pre>
|
|
522
|
+
|
|
523
|
+
> `https://github.com/LexBorisoff/web`
|
|
524
|
+
|
|
525
|
+
#### _Combining an arbitrary string with a resource key_
|
|
526
|
+
|
|
527
|
+
You can generate a URL that accesses a repositories page of an arbitrary profile:
|
|
528
|
+
|
|
529
|
+
<pre><code>web <em>--resource username::repos</em> <em>--site github</em></code></pre>
|
|
530
|
+
|
|
531
|
+
> `https://github.com/username?tab=repositories`
|
|
532
|
+
|
|
533
|
+
#### _Combining arbitrary strings_
|
|
534
|
+
|
|
535
|
+
<pre><code>web <em>--resource LexBorisoff::web</em> <em>--site github</em></code></pre>
|
|
536
|
+
|
|
537
|
+
> `https://github.com/LexBorisoff/web`
|
|
538
|
+
|
|
539
|
+
This scenario is essentially the same as providing a single resource value with `/`
|
|
540
|
+
|
|
541
|
+
<pre><code>web <em>--resource LexBorisoff/web</em> <em>--site github</em></code></pre>
|
|
542
|
+
|
|
543
|
+
> `https://github.com/LexBorisoff/web`
|
|
544
|
+
|
|
545
|
+
#### _Combining more resources_
|
|
546
|
+
|
|
547
|
+
You can combine as many resources as you want and each one will be resolved to its:
|
|
548
|
+
|
|
549
|
+
- config value found by the provided resource key, or
|
|
550
|
+
- literal value if
|
|
551
|
+
- the config does not contain the provided resource key, or
|
|
552
|
+
- the resource key is escaped with a forward slash `/`.
|
|
553
|
+
|
|
554
|
+
## `port`
|
|
555
|
+
|
|
556
|
+
Adds the provided port number to the URL.
|
|
557
|
+
|
|
558
|
+
⚡ Requires a number value.
|
|
559
|
+
❌ No configuration.
|
|
560
|
+
|
|
561
|
+
### Options
|
|
562
|
+
|
|
563
|
+
`--port` `-:`
|
|
564
|
+
|
|
565
|
+
### Usage
|
|
566
|
+
|
|
567
|
+
<pre><code>web <em>--port 3000</em> example.com</code></pre>
|
|
568
|
+
|
|
569
|
+
> `https://example.com:3000/`
|
|
570
|
+
|
|
571
|
+
If multiple ports are supplied, each one will open a separate query:
|
|
572
|
+
|
|
573
|
+
<pre><code>web <em>-: 3000 -: 5000</em> example.com</code></pre>
|
|
574
|
+
|
|
575
|
+
> `https://example.com:3000/`
|
|
576
|
+
> `https://example.com:5000/`
|
|
577
|
+
|
|
578
|
+
The CLI recognizes if a site or a URL already includes a port and checks if it matches the option's value when building the final list of URLs:
|
|
579
|
+
|
|
580
|
+
<pre><code>web <em>-: 3000 -: 5000</em> example.com:3000/api/users</code></pre>
|
|
581
|
+
|
|
582
|
+
> `https://example.com:3000/api/users`
|
|
583
|
+
> `https://example.com:5000/api/users`
|
|
584
|
+
|
|
585
|
+
## `http`
|
|
586
|
+
|
|
587
|
+
Uses the non-secure HTTP protocol when constructing web queries.
|
|
588
|
+
|
|
589
|
+
🚩 Flag option - no value is required.
|
|
590
|
+
❌ No configuration.
|
|
591
|
+
|
|
592
|
+
### Options
|
|
593
|
+
|
|
594
|
+
`--http`
|
|
595
|
+
|
|
596
|
+
### Usage
|
|
597
|
+
|
|
598
|
+
<pre><code>web <em>--http</em> https://google.com</code></pre>
|
|
599
|
+
|
|
600
|
+
> `http://google.com/`
|
|
601
|
+
|
|
602
|
+
## Browser Options
|
|
603
|
+
|
|
604
|
+
## `browser`
|
|
605
|
+
|
|
606
|
+
Specifies the browser app to open.
|
|
607
|
+
|
|
608
|
+
⚡ Takes a value.
|
|
609
|
+
⚙️ Allows configuration.
|
|
610
|
+
|
|
611
|
+
### Options
|
|
612
|
+
|
|
613
|
+
`--browser` `-b`
|
|
614
|
+
|
|
615
|
+
### Usage
|
|
616
|
+
|
|
617
|
+
<pre><code>web <em>--browser=value</em></code></pre>
|
|
618
|
+
|
|
619
|
+
`value` is one of the following:
|
|
620
|
+
|
|
621
|
+
1. **_Browser app name on your machine_**, e.g. `chrome`, `firefox`, `brave`, `edge`, etc.
|
|
622
|
+
|
|
623
|
+
<pre><code>web <em>--browser chrome</em></code></pre>
|
|
624
|
+
|
|
625
|
+
> ⚠️ The command will not prevent you from specifying a value that refers to an invalid browser or to another non-browser application on your machine. Any value provided to the `browser` option is a possible browser app, so it will attempt to open it.
|
|
626
|
+
|
|
627
|
+
2. **_Browser key or alias in the config._** For example, `chrome`, `edge`, `e`, `firefox`, `f`, or `ff`
|
|
628
|
+
|
|
629
|
+
```yaml
|
|
630
|
+
chrome:
|
|
631
|
+
|
|
632
|
+
edge:
|
|
633
|
+
alias: e
|
|
634
|
+
|
|
635
|
+
firefox:
|
|
636
|
+
alias: [f, ff]
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
<pre><code>web <em>--browser ff</em></code></pre>
|
|
640
|
+
|
|
641
|
+
### Multiple options
|
|
642
|
+
|
|
643
|
+
You can specify multiple browsers:
|
|
644
|
+
|
|
645
|
+
<pre><code>web <em>--browser chrome</em> <em>--browser firefox</em> ...</code></pre>
|
|
646
|
+
|
|
647
|
+
### Configuration
|
|
648
|
+
|
|
649
|
+
Setting up browsers config allows using browser keys and aliases as the option's value and as [custom flags](#custom-flags).
|
|
650
|
+
|
|
651
|
+
## `profile`
|
|
652
|
+
|
|
653
|
+
Specifies what browser profile to use when opening a new browser tab.
|
|
654
|
+
|
|
655
|
+
⚡ Takes a value.
|
|
656
|
+
⚙️ Allows configuration.
|
|
657
|
+
|
|
658
|
+
The option works only if the browser application supports profiles functionality. Otherwise, it has no effect on the opened search query. Some browsers (such as Chrome) have the functionality to create and use multiple browser profiles. When a browser has multiple profiles, it typically keeps the data used by each profile in a **_directory_** stored somewhere on your machine. For example, Chrome stores this information in `~/AppData/Local/Google/Chrome/User Data` on a Windows machine. Here, you can find profile directories such as "Profile 1", "Profile 2", etc. These are the names that you need to use with this option or assign to the `profiles` property in the config.
|
|
659
|
+
|
|
660
|
+
### Options
|
|
661
|
+
|
|
662
|
+
`--profile` `-p`
|
|
663
|
+
|
|
664
|
+
### Usage
|
|
665
|
+
|
|
666
|
+
This option relies on the provided `browser` option or the config:
|
|
667
|
+
|
|
668
|
+
- If the `browser` option is not provided, the CLI will use the config's **_default browser_**.
|
|
669
|
+
- If the `browser` option is not provided and there is no browser config, the query will not be opened.
|
|
670
|
+
|
|
671
|
+
<pre><code>web <em>--profile=value</em></code></pre>
|
|
672
|
+
|
|
673
|
+
`value` is one of the following:
|
|
674
|
+
|
|
675
|
+
1. **_Profile directory name._** For example `Profile 1`
|
|
676
|
+
|
|
677
|
+
<pre><code>web <em>--profile "Profile 1"</em></code></pre>
|
|
678
|
+
|
|
679
|
+
> For this scenario to work, make sure that you either provide the `--browser` option or define a browser in the config, for example:
|
|
680
|
+
|
|
681
|
+
```yaml
|
|
682
|
+
chrome:
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
> 💡 A browser definition in the config does not have any required properties.
|
|
686
|
+
|
|
687
|
+
2. **_Property key in the `profiles` object of the browser config._** For example, `dev` or `personal`
|
|
688
|
+
|
|
689
|
+
```yaml
|
|
690
|
+
chrome:
|
|
691
|
+
profiles:
|
|
692
|
+
dev: Profile 1
|
|
693
|
+
personal:
|
|
694
|
+
directory: Profile 2
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
<pre><code>web <em>--profile personal</em></code></pre>
|
|
698
|
+
|
|
699
|
+
3. **_Value of a profile's `alias` property._** For example, `d`, `p`, or `second`
|
|
700
|
+
|
|
701
|
+
```yaml
|
|
702
|
+
chrome:
|
|
703
|
+
profiles:
|
|
704
|
+
dev:
|
|
705
|
+
directory: Profile 1
|
|
706
|
+
alias: d
|
|
707
|
+
personal:
|
|
708
|
+
directory: Profile 2
|
|
709
|
+
alias: [p, second]
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
<pre><code>web <em>--profile p</em></code></pre>
|
|
713
|
+
|
|
714
|
+
### Multiple options
|
|
715
|
+
|
|
716
|
+
You can specify multiple profiles:
|
|
717
|
+
|
|
718
|
+
<pre><code>web <em>--profile dev</em> <em>--profile personal</em> ...</code></pre>
|
|
719
|
+
|
|
720
|
+
### Configuration
|
|
721
|
+
|
|
722
|
+
Setting up browsers config allows using
|
|
723
|
+
|
|
724
|
+
- profile keys and aliases as the option's value
|
|
725
|
+
- profile keys and multi-letter aliases as custom flags (1-letter aliases cannot be used)
|
|
726
|
+
|
|
727
|
+
## `incognito`
|
|
728
|
+
|
|
729
|
+
Opens web queries in a private / incognito mode.
|
|
730
|
+
|
|
731
|
+
🚩 Flag option - no value is required.
|
|
732
|
+
❌ No configuration.
|
|
733
|
+
|
|
734
|
+
### Options
|
|
735
|
+
|
|
736
|
+
`--incognito` `-i`
|
|
737
|
+
|
|
738
|
+
### Usage
|
|
739
|
+
|
|
740
|
+
<pre><code>web <em>--incognito</em></code></pre>
|
|
741
|
+
|
|
742
|
+
## Other Options
|
|
743
|
+
|
|
744
|
+
## `split`
|
|
745
|
+
|
|
746
|
+
Creates a separate web query for each value argument.
|
|
747
|
+
|
|
748
|
+
🚩 Flag option - no value is required.
|
|
749
|
+
❌ No configuration.
|
|
750
|
+
|
|
751
|
+
### Options
|
|
752
|
+
|
|
753
|
+
`--split`
|
|
754
|
+
|
|
755
|
+
### Usage
|
|
756
|
+
|
|
757
|
+
<pre><code>web Object Symbol class <em>--site mdn</em> <em>--split</em></code></pre>
|
|
758
|
+
|
|
759
|
+
> `https://developer.mozilla.org/search?q=Object`
|
|
760
|
+
> `https://developer.mozilla.org/search?q=Symbol`
|
|
761
|
+
> `https://developer.mozilla.org/search?q=class`
|
|
762
|
+
|
|
763
|
+
## `dry-run`
|
|
764
|
+
|
|
765
|
+
Prevents opening browser tabs and only displays the output.
|
|
766
|
+
|
|
767
|
+
🚩 Flag option - no value is required.
|
|
768
|
+
❌ No configuration.
|
|
769
|
+
|
|
770
|
+
### Options
|
|
771
|
+
|
|
772
|
+
`--dry-run` `-n`
|
|
773
|
+
|
|
774
|
+
### Usage
|
|
775
|
+
|
|
776
|
+
<pre><code>web [values] [options] <em>--dry-run</em></code></pre>
|
|
777
|
+
|
|
778
|
+
## Custom Flags
|
|
779
|
+
|
|
780
|
+
When config is set up, certain keys and alias values automatically become _boolean options_. You can use these custom flags as substitutes for `site`, `browser`, and `profile` options.
|
|
781
|
+
|
|
782
|
+
For example, the following command with value options
|
|
783
|
+
|
|
784
|
+
<pre><code>web <em>--browser chrome --profile dev --site mdn</em></code></pre>
|
|
785
|
+
|
|
786
|
+
can be rewritten using custom flags:
|
|
787
|
+
|
|
788
|
+
<pre><code>web <em>--chrome --dev --mdn</em></code></pre>
|
|
789
|
+
|
|
790
|
+
> ⚠️ If a custom flag conflicts with a built-in [_option_](#options) or its alias, the built-in takes precedence.
|
|
791
|
+
|
|
792
|
+
### How custom flags are created
|
|
793
|
+
|
|
794
|
+
The following config items are used to create custom flags:
|
|
795
|
+
|
|
796
|
+
| | keys | alias values | 1-letter alias values |
|
|
797
|
+
| ------- | :--: | :----------: | :-------------------: |
|
|
798
|
+
| site | ✅ | ✅ | ✅ |
|
|
799
|
+
| browser | ✅ | ✅ | ✅ |
|
|
800
|
+
| profile | ✅ | ✅ | ❌ |
|