Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Links: a click opens a file with the system app only when that runs nothing
razorback16eb82bd5758b8
diff --git a/docs/usage.md b/docs/usage.mdindex a15f9f6..46b2c12 100644--- a/docs/usage.md+++ b/docs/usage.md@@ -136,6 +136,13 @@ With picture select, the links, file paths, commands and code block copy buttons- **Drag** from a link, path or command to select text as usual.- If the open fails, the mod copies the target and the toast says so.+- A path is live only when it is a regular file. A folder (for example an `.app`) or a symbolic link is not.+- **System app.** With `/iui editor default`, or with `auto` and no editor on the PATH, only some file types open:+ - Pictures and PDFs (`png`, `jpg`, `jpeg`, `gif`, `webp`, `svg`, `pdf`) open in their app (`open`, `xdg-open`).+ - Text and code files (`md`, `txt`, `json`, `ts`, `py` and the other types that Intelligent UI finds as paths) open in the text editor on macOS (`open -t`). On Linux, they open with `xdg-open`, but scripts (`sh`, `py`, `rb`, `pl`, `js` and similar), `html`, `xml` and `ipynb` files do not.+ - The mod does not open other files, because the system app can run some of them (for example `.command`, `.app`, `.webloc`, `.jar` or `.desktop`). It copies the path, and the toast says "copied the path (this file type does not open on click)".+ - An editor (`auto`, a name or your command) opens all file types as text.+- The rows under the pictures (on the main screen, or with picture select off) show a file as a `file://` link only if it is a picture, a PDF or a text file that `xdg-open` opens. The terminal opens a `file://` link with the system app. Other files show as plain text with `·` before them, so a click on the row does not run them.- Over ssh, a click copies, because a program would run on the remote computer.**Which editor.** `/iui editor` sets the editor for file paths. With `auto` (the default), the mod uses the first editor it finds on the PATH, in the order in [Commands](#commands). If it finds none, it uses the system default app. The setting is kept for later sessions.diff --git a/hooks/lib/draw.tsx b/hooks/lib/draw.tsxindex 0e1eefd..6b5bc62 100644--- a/hooks/lib/draw.tsx+++ b/hooks/lib/draw.tsx@@ -10,10 +10,11 @@ import { INLINE_KEPT, inlined, keep, linkFiles, ownCopy, S, type Cell, type Lookimport { DEFAULT_GRID, gridFirstRow, type GridMetrics } from './grid'import { FENCE, imagePathOf } from './markdown'import { linksOf, type LinkItem } from './links'+import { opensPlain } from './open'import { fitBox, fitsInline, roomColumns } from './terminal'import { clickLinks, selectOn } from './select'import { noteSite } from './blit'-import { exists, cat, copy, uiResolve, toast } from './api'+import { stat, cat, copy, uiResolve, toast } from './api'// FNV-1a over the parts, twice with different offsets: 16 hex digits.export function hashOf(parts: readonly (string | number)[]): string {@@ -291,7 +292,8 @@ export const fileHref = (path: string) => `file://${encodeURI(path).replace(/[?#// The items as link rows: each file path made absolute from `base` (the// folder relative paths start from; `~/` is the home folder) and kept only-// when it is a file now (each path checked once: linkFiles).+// when it is a regular file now: no folder (an .app), no symbolic link+// (each path checked once: linkFiles).export async function resolveLinks($: EngineInterface, items: readonly LinkItem[], base: string, home = S.env?.home ?? ''): Promise<ShownLink[]> {const shown: ShownLink[] = []for (const item of items) {@@ -302,7 +304,8 @@ export async function resolveLinks($: EngineInterface, items: readonly LinkItem[const path = home && item.path.startsWith('~/') ? `${home.replace(/\/+$/, '')}${item.path.slice(1)}` : imagePathOf(item.path, base)let isFile = linkFiles.get(path)if (isFile === undefined) {- isFile = await exists($, path).catch(() => false)+ const st = await stat($, path).catch(() => null)+ isFile = st?.kind === 'file' && !st.isLinkkeep(linkFiles, path, isFile, LINK_FILES_KEPT)}if (isFile) shown.push({ kind: 'file', label: item.label, path, href: fileHref(path) })@@ -344,6 +347,8 @@ export function drawLinks($: EngineInterface, e: ResolveInput<RenderComponent, ')}const href = link.href+ // A file a plain open could run (the terminal opens a file:// link so): its path, no link.+ if (link.kind === 'file' && !opensPlain(link.path)) return <Text dimColor wrap="truncate-end">· {link.label}</Text>return (<Text dimColor wrap="truncate-end">↗ <Link href={href}>{link.label}</Link>diff --git a/hooks/lib/links.ts b/hooks/lib/links.tsindex 5b119b1..0ffd8cc 100644--- a/hooks/lib/links.ts+++ b/hooks/lib/links.ts@@ -33,7 +33,7 @@ const PATH = String.raw`((?:~\/|\.{1,2}\/|\/)?(?:\.?[\w@+-][\w.@+-]*\/)*\.?[\w@+const FILE = new RegExp(`^${PATH}$`)const BARE_FILE = new RegExp(`(?<![\\w./~@+:-])${PATH}(?![\\w/])`, 'g')const HOST = /^[\w-]+(?:\.[\w-]+)+$/-const EXTS = new Set(+export const EXTS = new Set(('ts tsx js jsx mjs cjs json jsonc md mdx markdown txt rst adoc py pyi rb go rs java kt kts swift c h cc cpp cxx hpp hh cs fs php ' +'sh bash zsh fish ps1 lua pl scala clj ex exs erl hs ml sql html htm css scss sass less vue svelte astro yml yaml toml ini cfg conf ' +'xml csv tsv lock log typ tex bib png jpg jpeg gif svg webp pdf ipynb gradle proto graphql dart zig nim tf hcl patch diff').split(' '),diff --git a/hooks/lib/open.ts b/hooks/lib/open.tsindex 8cf19b3..e338ea0 100644--- a/hooks/lib/open.ts+++ b/hooks/lib/open.ts@@ -1,11 +1,13 @@// A click's target opened (register.tsx clickAt): a web link in the// browser, a file in an editor at its line and column, or in the system's-// app for it. The pure parts: the known editors, the `/iui editor` setting,-// the program a click uses and its argv. And the PATH lookups, cached in S.+// app for it when that runs nothing (appArgv). The pure parts: the known+// editors, the `/iui editor` setting, the program a click uses and its argv.+// And the PATH lookups, cached in S.// No argument goes through a shell.import type { EngineInterface } from 'claude-code'import { exec } from './api'+import { EXTS } from './links'import { S } from './state'import type { Target } from './targets'@@ -107,15 +109,44 @@ function commandArgv(words: readonly string[], bin: string, f: Place): string[]})}+// The file types the system app opens, by extension (lower case). A plain+// `open` or `xdg-open` runs some files (on macOS a .command, .tool or+// .terminal file, an .app, the URL of a .webloc or .fileloc, a .jar; on+// Linux a .desktop file or a script), so only these open; another file+// copies its path. Pictures and PDFs: a plain open, in their viewer.+export const VIEW_EXTS: ReadonlySet<string> = new Set('png jpg jpeg gif webp svg pdf'.split(' '))+// Text and code (links.ts EXTS less pictures): on macOS `open -t`, the text editor, which runs nothing.+export const TEXT_EXTS: ReadonlySet<string> = new Set([...EXTS].filter(ext => !VIEW_EXTS.has(ext)))+// Text that a default app may run or show as a web page (scripts, notebooks, HTML).+const RUNS = new Set('sh bash zsh fish ps1 py pyi rb pl php lua js mjs cjs html htm xml ipynb'.split(' '))+// The files a plain open does not run (Linux has no `-t`): pictures, PDFs, and text and code less RUNS.+export const PLAIN_EXTS: ReadonlySet<string> = new Set([...VIEW_EXTS, ...[...TEXT_EXTS].filter(ext => !RUNS.has(ext))])++// A path's extension in lower case ('' none).+export const extOf = (path: string) => /\.([^./]+)$/.exec(path)?.[1]!.toLowerCase() ?? ''+// Whether a plain open (`open`, `xdg-open`, a terminal's file:// link) of a file runs nothing.+export const opensPlain = (path: string) => PLAIN_EXTS.has(extOf(path))++// The system app's argv for a file: a picture or PDF in its viewer; text+// or code in the text editor on macOS (`open -t`), with xdg-open on Linux+// when it is in PLAIN_EXTS. Null for any other file (it copies).+function appArgv(path: string, isMac: boolean): string[] | null {+ const ext = extOf(path)+ if (VIEW_EXTS.has(ext)) return [isMac ? 'open' : 'xdg-open', path]+ if (isMac) return TEXT_EXTS.has(ext) ? ['open', '-t', path] : null+ return PLAIN_EXTS.has(ext) ? ['xdg-open', path] : null+}+// The argv that opens a target: a web link with the system's opener (`open`// on macOS, `xdg-open` on Linux), a file with `use` (the system app: with no-// line). Null for a command or code (those copy).+// line, and only the types of appArgv). Null for a command, code or a file+// the system app does not open (those copy).export function openArgv(target: Target, o: { isMac: boolean; use: Use }): string[] | null {const opener = o.isMac ? 'open' : 'xdg-open'if (target.kind === 'web') return [opener, target.href]if (target.kind !== 'file') return nullconst { use } = o- if (use.kind === 'app') return [opener, target.path]+ if (use.kind === 'app') return appArgv(target.path, o.isMac)if (use.kind === 'command') return commandArgv(use.words, use.bin, target)const form = EDITORS.find(([name]) => name === use.name)?.[1] ?? 'suffix'return knownArgv(form, use.bin, target)diff --git a/hooks/register.tsx b/hooks/register.tsxindex 5e2dc42..145fa71 100644--- a/hooks/register.tsx+++ b/hooks/register.tsx@@ -771,18 +771,23 @@ async function openTarget($: EngineInterface, target: Target, surface: RenderSurconst got = argv ? await exec($, detachedArgv(argv), { timeoutMs: OPEN_TIMEOUT_MS }).catch(() => null) : nullif (S.debug) traceDebug($, `select: open ${argv?.join(' ') ?? 'none'} exit ${got ? got.exitCode : 'failed'}`)if (got?.exitCode === 0) return void toast($, openedText(target, use))+ // No argv for a file: the system app could run it (openArgv), so it only copies.+ const why = argv ? 'failed' : 'type'if (!(await claim(turn)) || !(await isNewest($, turn))) {- return void toast($, `Intelligent UI: could not open the ${target.kind === 'web' ? 'link' : 'file'}`)+ return void toast($, `Intelligent UI: ${why === 'type' ? NO_OPEN : `could not open the ${target.kind === 'web' ? 'link' : 'file'}`}`)}- await copyTarget($, target, surface, true)+ await copyTarget($, target, surface, why)}+const NO_OPEN = 'this file type does not open on click'+// A target's text on the clipboard (clickAt), with its toast; `notOpened`:-// it is copied as an open of it failed.-async function copyTarget($: EngineInterface, target: Target, surface: RenderSurface, notOpened = false) {+// it is copied as an open of it failed, or as its file type does not open.+async function copyTarget($: EngineInterface, target: Target, surface: RenderSurface, notOpened?: 'failed' | 'type') {const text = target.kind === 'web' ? target.href : target.kind === 'file' ? target.path : target.textconst name = target.kind === 'web' ? 'link' : target.kind === 'file' ? 'path' : target.kind === 'code' ? 'code' : 'command'const copied = await copyOwn($, { text, surface })+ if (notOpened === 'type') return void toast($, `Intelligent UI: ${copied.isCopied ? `copied the path (${NO_OPEN})` : `${NO_OPEN}, and the copy failed: ${copied.reason}`}`)const failed = notOpened ? `could not open the ${target.kind === 'web' ? 'link' : 'file'}` : ''const done = failed ? `${failed}, so copied ${target.kind === 'web' ? 'it' : 'its path'}` : `copied the ${name}`toast($, copied.isCopied ? `Intelligent UI: ${done}` : `Intelligent UI: ${failed ? `${failed}, and ` : ''}the copy failed: ${copied.reason}`)diff --git a/tests/copy.test.ts b/tests/copy.test.tsindex c2a4315..2e4bcc7 100644--- a/tests/copy.test.ts+++ b/tests/copy.test.ts@@ -1812,13 +1812,18 @@ test('picture select: with no perl the first frame write fails, is logged once a// src/a.ts a file in the session's folder /w. Its targets (targets.test.ts):// the link "the docs" row 3 columns 4 to 11, the bare URL row 3 16 to 45,// `! ls -la` row 4 50 to 58, src/a.ts row 6 5 to 13, the bash block's copy-// button row 8 8 to 15 (its code rows 11 and 12: no target).-async function drawTargets($: any, on: any, o: { env?: Record<string, string>; marks?: readonly object[]; noBridge?: boolean } = {}, isFullscreen: boolean | null = true) {- const w = world(on, { tty: TTY, marks: TARGETS_MARKS, ...o })+// button row 8 8 to 15 (its code rows 11 and 12: no target). `file`: src/a.ts+// named `name` instead (in the text and the probe), and its stat.+async function drawTargets($: any, on: any, o: { env?: Record<string, string>; marks?: readonly object[]; noBridge?: boolean; file?: { name: string; kind?: string; isLink?: boolean } } = {}, isFullscreen: boolean | null = true) {+ const name = o.file?.name ?? 'a.ts'+ const marks = (o.marks ?? TARGETS_MARKS).map((m: any) => (m.code === 'src/a.ts' ? { ...m, code: `src/${name}`, ...(m.t === 'a.ts' ? { t: name } : {}) } : m))+ const w = world(on, { tty: TTY, ...o, marks })on('session.cwd', async () => ({ value: '/w' }))- on('fs.exists', async ($: any, e: any) => ({ value: e.path === '/w/src/a.ts' }))+ on('fs.exists', async ($: any, e: any) => ({ value: e.path === `/w/src/${name}` }))+ on('fs.stat', async ($: any, e: any, next: any) =>+ e.path === `/w/src/${name}` ? { value: { kind: o.file?.kind ?? 'file', size: 1, mtimeMs: 1, isLink: !!o.file?.isLink } } : next(e))await $.command.run({ command: 'iui', args: '' } as any)- const ui = await drawAnswer($, w, 'ans-1', TARGETS_MD, isFullscreen)+ const ui = await drawAnswer($, w, 'ans-1', TARGETS_MD.replace('src/a.ts', `src/${name}`), isFullscreen)await settle(w)return { w, ui }}@@ -1903,7 +1908,7 @@ test('picture select: a click opens a link or a file and copies a command; an alawait settle(w)await click(ui, 52, 4)await settle(w)- expect(w.opens).toEqual([['open', 'https://example.com'], ['open', '/w/src/a.ts']])+ expect(w.opens).toEqual([['open', 'https://example.com'], ['open', '-t', '/w/src/a.ts']])expect(w.copies).toEqual(['ls -la'])expect(w.toasts.filter(t => /^Intelligent UI: (opened|copied) /.test(t))).toEqual(['Intelligent UI: opened the link', 'Intelligent UI: opened a.ts in the default app', 'Intelligent UI: copied the command',@@ -1941,6 +1946,46 @@ test('picture select: a link or a file that does not open is copied, and the toaexpect(w.toasts).toContain('Intelligent UI: could not open the file, so copied its path')})+test('picture select: with the system app, a file it could run (.command) is not opened: its path is copied, and the toast says why', async ($, on) => {+ const { w, ui } = await drawTargets($, on, { file: { name: 'setup.command' } })+ await click(ui, 8, 6)+ await settle(w)+ expect(w.opens).toEqual([])+ expect(w.copies).toEqual(['/w/src/setup.command'])+ expect(w.toasts).toContain('Intelligent UI: copied the path (this file type does not open on click)')+})++test('picture select: with the system app, a picture opens with a plain open', async ($, on) => {+ const { w, ui } = await drawTargets($, on, { file: { name: 'shot.png' } })+ await click(ui, 8, 6)+ await settle(w)+ expect(w.opens).toEqual([['open', '/w/src/shot.png']])+ expect(w.copies).toEqual([])+})++test('picture select: a folder (an .app) is no file target: a click opens nothing and copies its code text', async ($, on) => {+ const { w, ui } = await drawTargets($, on, { file: { name: 'Tool.app', kind: 'dir' } })+ await click(ui, 8, 6)+ await settle(w)+ expect(w.opens).toEqual([])+ expect(w.copies).toEqual(['src/Tool.app'])+})++test('picture select: a symbolic link is no file target, even to a picture: a click opens nothing', async ($, on) => {+ const { w, ui } = await drawTargets($, on, { file: { name: 'link.png', isLink: true } })+ await click(ui, 8, 6)+ await settle(w)+ expect(w.opens).toEqual([])+ expect(w.copies).toEqual(['src/link.png'])+})++test('picture select: on the main screen a file a plain open could run is a row with no file:// link', async ($, on) => {+ const { ui } = await drawTargets($, on, { file: { name: 'run.command' } }, false)+ const drawn = tree(await ui.drawn())+ expect(drawn.filter(n => n.type === 'Link').map(n => n.props.href)).toEqual(['https://example.com', 'https://typst.app/docs/reference'])+ expect(drawn.some(n => n.type === 'Text' && JSON.stringify(n.children ?? []).includes('src/run.command'))).toBe(true)+})+test('picture select: a link whose open fails late is not copied over a newer copy', async ($, on) => {const { w, ui } = await drawTargets($, on)w.openFails = truediff --git a/tests/draw.test.ts b/tests/draw.test.tsindex 40e8fb6..50a8721 100644--- a/tests/draw.test.ts+++ b/tests/draw.test.ts@@ -6,7 +6,7 @@ import {} from '../hooks/register'import { TABLE_GRID } from './table-fixture'// This file's own copy of the drawing code, called with a fake `$`.-import { drawPages, linksFor } from '../hooks/lib/draw'+import { drawLinks, drawPages, linksFor } from '../hooks/lib/draw'// ---- Where pictures draw ----------------------------------------------------@@ -267,6 +267,8 @@ function world(on: any, vars: Record<string, string>, head = HEAD, stored: Recor})on('fs.stat', async ($: any, e: any, next: any) => {calls.push('fs.stat')+ // The project's files (the link rows' paths): the ones written.+ if (e.path.startsWith('/w/app/')) return files.has(e.path) ? { value: { kind: 'file', size: 1, mtimeMs: 1, isLink: false } } : { deny: 'ENOENT' }return next(e)})const toasts: string[] = []@@ -904,9 +906,20 @@ const all = (tree: any, type: string): any[] =>tree && typeof tree === 'object' ? [...(tree.type === type ? [tree] : []), ...(tree.children ?? []).flatMap((c: any) => all(c, type))] : []const textOf = (tree: any): string => (typeof tree === 'string' ? tree : (tree?.children ?? []).map(textOf).join(''))+// A fake `$.fs.stat`: `kinds` the paths there (a kind, or 'link' a symbolic link to a file); others ENOENT.+function statOf(kinds: Record<string, string>, asked: string[] = []) {+ const stat = async (path: string) => {+ asked.push(path)+ const kind = kinds[path]+ if (!kind) throw new Error('ENOENT')+ return { kind: kind === 'link' ? 'file' : kind, size: 1, mtimeMs: 1, isLink: kind === 'link' }+ }+ return { fs: { stat } } as any+}+test('a file path is made absolute and kept only when it is a file; ~/ is the home folder; the href is encoded', async () => {const asked: string[] = []- const $ = { fs: { exists: async (path: string) => (asked.push(path), path !== '/w/app/gone.ts') } } as any+ const $ = statOf({ '/w/app/src/a b.ts': 'file', '/h/x#1.md': 'file', '/abs/y.md': 'file' }, asked)const items = [{ kind: 'web', label: 'Docs', href: 'https://typst.app/docs' },{ kind: 'file', label: 'src/a b.ts:42', path: 'src/a b.ts' },@@ -929,6 +942,23 @@ test('a file path is made absolute and kept only when it is a file; ~/ is the hoexpect(fileHref('/a/b?c.md')).toBe('file:///a/b%3Fc.md')})+test('a folder (an .app bundle, a folder named like a file) or a symbolic link is no file link', async () => {+ const $ = statOf({ '/k/Tool.app': 'dir', '/k/docs.md': 'dir', '/k/pic.png': 'link', '/k/odd.png': 'other', '/k/ok.png': 'file' })+ const items = ['Tool.app', 'docs.md', 'pic.png', 'odd.png', 'ok.png'].map(name => ({ kind: 'file', label: name, path: `/k/${name}` }) as const)+ expect((await resolveLinks($, items, '/k', '/h')).map(l => l.label)).toEqual(['ok.png'])+})++test('a link row of a file a plain open could run has no file:// link; a picture or plain text has one', () => {+ const $ = { ui: { resolve: () => ({ Box: 'Box', Text: 'Text', Link: 'Link', Button: 'Button' }) } } as any+ const e = { viewport: { columns: 100, rows: 40 } } as any+ const row = (name: string) => ({ kind: 'file', label: `[x](${name})`, path: `/k/${name}`, href: fileHref(`/k/${name}`) }) as const+ const names = ['setup.command', 'run.tool', 'Go.terminal', 'a.webloc', 'a.fileloc', 'a.inetloc', 'x.jar', 'a.desktop', 'a.sh', 'a.py', 'a.html', 'shot.png', 'doc.pdf', 'notes.md', 'a.ts']+ const rows: any[] = drawLinks($, e, names.map(row), '') as any+ const hrefs = rows.flatMap(r => all(r, 'Link')).map(l => l.props.href)+ expect(hrefs).toEqual(['file:///k/shot.png', 'file:///k/doc.pdf', 'file:///k/notes.md', 'file:///k/a.ts'])+ expect(textOf(rows[0])).toBe('· [x](setup.command)')+})+const LINKED = ['See [Typst docs](https://typst.app/docs) and https://github.com/o/r/pull/42.','',@@ -997,7 +1027,7 @@ test('a press on a command row that cannot copy toasts the reason, or none', asy})test('the link rows of a text are none when a file check throws', async () => {- const $ = { fs: { exists: () => { throw new Error('gone') } } } as any+ const $ = { fs: { stat: () => { throw new Error('gone') } } } as anyexpect(await linksFor($, 'See `src/never-checked.ts`.', '/w')).toEqual([])})diff --git a/tests/open.test.ts b/tests/open.test.tsindex 9b049aa..7037e25 100644--- a/tests/open.test.ts+++ b/tests/open.test.ts@@ -1,7 +1,7 @@import { expect, test } from 'claude-code/testing'import {- autoOf, DETACH_SH, detachedArgv, editorNow, EDITOR_NAMES, findAuto, findOnPath, openArgv, openedText, parseEditor, pathsOf, useOf, type Use,+ autoOf, DETACH_SH, detachedArgv, editorNow, EDITOR_NAMES, extOf, findAuto, findOnPath, openArgv, openedText, opensPlain, parseEditor, pathsOf, useOf, type Use,} from '../hooks/lib/open'import type { Target } from '../hooks/lib/targets'import { S } from '../hooks/lib/state'@@ -48,9 +48,52 @@ test('JetBrains IDEs take --line and --column before the path', () => {expect(argv(BARE, known('idea'))).toEqual(['/bin/idea', '/w/README.md'])})-test('the system app opens a file with no line: open on macOS, xdg-open on Linux', () => {- expect(argv(FILE, { kind: 'app' })).toEqual(['open', '/w/hooks/lib/copy.ts'])- expect(argv(FILE, { kind: 'app' }, false)).toEqual(['xdg-open', '/w/hooks/lib/copy.ts'])+const at = (path: string): Target => ({ kind: 'file', path })+const APP: Use = { kind: 'app' }+// Files a plain `open` or `xdg-open` could run, follow or launch.+const RUN = ['/w/scripts/setup.command', '/w/run.tool', '/w/Go.terminal', '/w/a.webloc', '/w/a.fileloc', '/w/a.inetloc', '/w/x.jar', '/w/Tool.app', '/w/a.desktop', '/w/a.exe', '/w/a.pkg', '/w/setup', '/w/.bashrc', '/w/a.unknownext']++test('the system app opens code and text with no line: open -t (the text editor) on macOS, xdg-open on Linux', () => {+ expect(argv(FILE, APP)).toEqual(['open', '-t', '/w/hooks/lib/copy.ts'])+ expect(argv(FILE, APP, false)).toEqual(['xdg-open', '/w/hooks/lib/copy.ts'])+ for (const path of ['/w/README.md', '/w/NOTES.MD', '/w/a.txt', '/w/a.json', '/w/c.yaml', '/w/c.toml', '/w/d.csv', '/w/x.log', '/w/m.rs']) {+ expect(argv(at(path), APP)).toEqual(['open', '-t', path])+ expect(argv(at(path), APP, false)).toEqual(['xdg-open', path])+ }+})++test('the system app opens a picture or a PDF with a plain open (open, xdg-open)', () => {+ for (const path of ['/w/shot.png', '/w/a.JPG', '/w/a.jpeg', '/w/a.gif', '/w/a.webp', '/w/a.svg', '/w/doc.pdf']) {+ expect(argv(at(path), APP)).toEqual(['open', path])+ expect(argv(at(path), APP, false)).toEqual(['xdg-open', path])+ }+})++test('the system app does not open a file it could run (.command, .app, .fileloc, .desktop, no extension, unknown): null, so it copies', () => {+ for (const path of RUN) {+ expect(argv(at(path), APP)).toBe(null)+ expect(argv(at(path), APP, false)).toBe(null)+ }+ // A missed editor setting that fell back to the system app: the same.+ expect(argv(at('/w/scripts/setup.command'), { kind: 'app', missed: 'code' })).toBe(null)+})++test('on Linux xdg-open does not open scripts, notebooks or web pages (an app may run them); on macOS open -t does', () => {+ for (const path of ['/w/a.sh', '/w/a.bash', '/w/a.zsh', '/w/a.fish', '/w/a.ps1', '/w/a.py', '/w/a.rb', '/w/a.pl', '/w/a.js', '/w/a.html', '/w/a.ipynb']) {+ expect(argv(at(path), APP, false)).toBe(null)+ expect(argv(at(path), APP)).toEqual(['open', '-t', path])+ }+})++test('an editor takes any file as an argument: a .command opens in it as text', () => {+ expect(argv(at('/w/scripts/setup.command'), known('code'))).toEqual(['/bin/code', '-g', '/w/scripts/setup.command'])+ expect(argv(at('/w/setup'), { kind: 'command', words: ['hx', '{path}'], bin: '/bin/hx' }, false)).toEqual(['/bin/hx', '/w/setup'])+})++test('a plain open runs nothing only for pictures, PDFs and plain text or code', () => {+ for (const path of ['/w/a.png', '/w/a.pdf', '/w/a.md', '/w/a.ts', '/w/a.json']) expect(opensPlain(path)).toBe(true)+ for (const path of [...RUN, '/w/a.sh', '/w/a.py', '/w/a.html']) expect(opensPlain(path)).toBe(false)+ expect([extOf('/w/a.B/C'), extOf('/w/x.tar.GZ'), extOf('/w/a.')]).toEqual(['', 'gz', ''])})test('a command puts in its placeholders; a word whose placeholder has no value is left out', () => {