Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ It speaks the same format as the web app, so links work in both directions: a li
```bash
secretli share # type or paste the secret, then Ctrl-D
pbpaste | secretli share -e 1h # text from a pipe, gone after an hour
secretli share --from-clipboard -c # the clipboard's text in, the link back on the clipboard
secretli share -c # the clipboard's text in, the link back on the clipboard
secretli share deploy.key notes.pdf # files; -p adds a password, --reusable lets it open more than once
secretli open <link> # text to stdout, files to the current directory; -c copies text instead
secretli open <link> # text to stdout, files to the current directory
secretli open -c # the link from the clipboard, the text back on it
secretli status <link> # what a link points to, without opening it
secretli delete <owner-link> # remove a secret for everyone
secretli send <link> # hand a link to another device with a code like 7-acid-rocket
secretli receive 7-acid-rocket # open what another device sends with a code
secretli share -c --code # the clipboard's text to another device; there: secretli receive <code> -c
```

## Install
Expand Down Expand Up @@ -58,25 +60,36 @@ For shell completion without Homebrew, `secretli completion zsh --help` (or `bas

## Use

**Sharing.** Files are arguments; text comes from a pipe, from a prompt when you are at a terminal, from the clipboard with `--from-clipboard`, or from `-t`. The prompt, the pipe and the clipboard keep the secret out of your shell history; `-t` does not. `--from-clipboard` leaves off the clipboard's final line break, as `open --to-clipboard` does, and with `--name` shares the clipboard as a file; it works with the same clipboard tools as `--to-clipboard`. `-` shares stdin as a file named by `--name`:
**Sharing.** Files are arguments; text comes from a pipe, from a prompt when you are at a terminal, from the clipboard with `-c`, or from `-t`. The prompt, the pipe and the clipboard keep the secret out of your shell history; `-t` does not. `-` shares stdin as a file named by `--name`:

```bash
pg_dump db | gzip | secretli share --name db.sql.gz
```

Links open once and expire after a day unless you say otherwise: `-e` takes `5m`, `10m`, `15m`, `1h`, `4h`, `12h`, `1d`, `3d` or `7d`, and `--reusable` lets a link open again and again until it expires. `-p` asks for a password; `--password-file` and `SECRETLI_PASSWORD` provide one without asking. The server takes ten wrong passwords for a secret and deletes it at the tenth; `open` says after each wrong one how many are left, and at a terminal asks again. `--qr` also draws the link as a QR code, for a phone to scan off the screen, and `-c`/`--copy-link` copies it to the clipboard.
Links open once and expire after a day unless you say otherwise: `-e` takes `5m`, `10m`, `15m`, `1h`, `4h`, `12h`, `1d`, `3d` or `7d`, and `--reusable` lets a link open again and again until it expires. `-p` asks for a password; `--password-file` and `SECRETLI_PASSWORD` provide one without asking. The server takes ten wrong passwords for a secret and deletes it at the tenth; `open` says after each wrong one how many are left, and at a terminal asks again. `--qr` also draws the link as a QR code, for a phone to scan off the screen, and `-c` puts it on the clipboard instead of printing it.

Every share prints two links: the one to hand out, and the owner link, which can delete the secret and, for a reusable one, tells you whether it has been opened. Keep the owner link to yourself.

**Opening.** Text goes to stdout exactly as it was shared. At a terminal, control characters in it, which could steer the terminal, show as `�`, and the command says so; a pipe, a file or `--to-clipboard` gets the exact text. File names and error messages from the server reach the terminal without control characters or direction overrides either. Files are saved to the current directory or to `--out`, and nothing is overwritten unless you pass `--force`; `--stdout` streams a single file instead. When a file of that name exists, a reusable secret is refused before anything is saved, and you can open it again elsewhere; a one-time secret, used up by then, saves that file as `name (2).ext`, or the next number free, and says so. A file's name is made safe first: no path, no control characters, no names Windows reserves for devices, at most 255 bytes. Two files of one secret with the same name are both saved, the second as `name (2).ext`, and the command says so. `--force` replaces a file that exists with a new one, so a link in its place is replaced, never followed. Before anything is opened, the command says what the link points to. Opening a one-time secret uses it up, so for one of those it asks first, and Enter means no; `-y`/`--yes` opens it without asking. Reusable secrets open right away. Without an argument the link is read from stdin, or asked for without showing what you paste, which keeps it out of your shell history and the scrollback too.
**Opening.** Text goes to stdout exactly as it was shared. At a terminal, control characters in it, which could steer the terminal, show as `�`, and the command says so; a pipe, a file or `-c` gets the exact text. File names and error messages from the server reach the terminal without control characters or direction overrides either. Files are saved to the current directory or to `--out`, and nothing is overwritten unless you pass `--force`; `--stdout` streams a single file instead. When a file of that name exists, a reusable secret is refused before anything is saved, and you can open it again elsewhere; a one-time secret, used up by then, saves that file as `name (2).ext`, or the next number free, and says so. A file's name is made safe first: no path, no control characters, no names Windows reserves for devices, at most 255 bytes. Two files of one secret with the same name are both saved, the second as `name (2).ext`, and the command says so. `--force` replaces a file that exists with a new one, so a link in its place is replaced, never followed. Before anything is opened, the command says what the link points to. Opening a one-time secret uses it up, so for one of those it asks first, and Enter means no; `-y`/`--yes` opens it without asking. Reusable secrets open right away. Without an argument the link is read from stdin, or asked for without showing what you paste, which keeps it out of your shell history and the scrollback too.

When a secret holds several files, `open` lists them with their sizes and asks which to save. Enter saves them all; numbers, ranges and names or patterns pick some, as in `2`, `1 3`, `1-2` or `*.jpg`, and a list of more than 30 files shows the first 30, while numbers and patterns reach them all. Of a one-time secret, the files you don't save are gone with it, and it says so before it asks. A secret over 1 MiB is downloaded after the question, which the server allows for 15 minutes after it is opened, so for one of those it also says the time by which the files have to be saved. Only the files you pick count when names are checked against the directory. `--stdout` asks for the one file to write. With `--yes` or `--json`, or where there is no terminal, nothing is asked: every file is saved, and `--stdout` needs a secret of a single file.

`-c`/`--to-clipboard` puts text on the clipboard instead of the terminal, so it doesn't stay in the scrollback. The final line break is left off, so pasting a password doesn't also press Enter. 45 seconds later the clipboard is cleared, unless you copied something else by then. Before anything is opened, `--to-clipboard` checks that there is a clipboard tool (`pbcopy`, `wl-copy`, `xclip`, `xsel` or `clip.exe`) and that the secret is text; should copying still fail, the text is printed after all, so a one-time secret isn't lost.
**The clipboard.** `-c`/`--clipboard` uses the clipboard instead of the terminal, on every command: what you would type comes from it, and what you would read goes to it.

| | from the clipboard | to the clipboard |
|---|---|---|
| `share -c` | the secret, instead of the prompt | the link, instead of printing it |
| `open -c` | the link, instead of the prompt | the text |
| `receive <code> -c` | — (the code is typed) | the text, or with `--link` the link |
| `status -c`, `send -c`, `delete -c` | the link, instead of the prompt | — |

Anything you give explicitly still wins: files, `-t` or a pipe for `share`, a link as an argument or piped in for the others; then only the other side uses the clipboard. An empty pipe is an error, never a reason to share the clipboard. Files of an opened secret are saved as usual, `--json` still prints everything, and with `share --code` the code is printed, since you read it to type it on the other device. Before anything is uploaded or opened, `-c` checks that there is a clipboard tool (`pbcopy`, `wl-copy`, `xclip`, `xsel` or `clip.exe`).

What goes on the clipboard carries a key, so 45 seconds later the clipboard is cleared, unless you copied something else by then. Text goes there without its final line break, so pasting a password doesn't also press Enter, and `share -c` leaves the clipboard's final line break off in the same way, so what one shares, the other gives back. Should copying fail, what was to be copied is printed after all, so a one-time secret isn't lost. A clipboard that holds no link is never shown in the error, as it may hold a secret.

**Handing a link over with a code.** Instead of copying a link to another device, `send` hands it over with a short code like `7-acid-rocket`. On the other device, type the code at the server's `/c` page (`secretli.app/c`) or run `secretli receive 7-acid-rocket`; `secretli share --code` makes a secret and hands it over in one go. The link travels encrypted, and only after the other device has proved it typed the same code; the words never leave the two devices. A code works once and for ten minutes, and a wrong code ends the transfer on both sides. Given an owner link, `send` hands over only the link to hand out. It works both ways with the web app's "Send with a code".

`receive` opens what it receives like `open` does, with the same `--out`, `--stdout`, `--force`, `--yes`, `--to-clipboard` and password options, or prints the link with `--link` (with `--to-clipboard`, it copies the link). If you decline to open a one-time secret, it prints the link instead, since the code is used up by then. Typing is forgiving: `7 acid rocket`, `7-ACID-ROCKET` and `7-aci-roc` all work. Without an argument the code is asked for, and what you type isn't shown; a misspelt word is caught before the code is used.
`receive` opens what it receives like `open` does, with the same `--out`, `--stdout`, `--force`, `--yes`, `-c` and password options, or prints the link with `--link` (with `-c`, it copies the link). If you decline to open a one-time secret, it prints the link instead, since the code is used up by then. Typing is forgiving: `7 acid rocket`, `7-ACID-ROCKET` and `7-aci-roc` all work. Without an argument the code is asked for, and what you type isn't shown; a misspelt word is caught before the code is used.

**Checking and deleting.** `status` describes a secret from its link without opening it: text or files, one-time or reusable, password or not, when it was sent and when it expires, and whether it has been opened. Once a secret is gone, opened, deleted or expired, the server keeps nothing about it, so all `status` can say then is that it is gone, to the owner as to a recipient, as it does for a link to nothing. The exit code is 4 then, and with `--json` the state is `live` or `gone`. `delete` takes the owner link and asks before it deletes, unless you pass `--yes`.

Expand Down
4 changes: 3 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ Links from this command open in the web app and the other way round.`,
secretli status <link> what a link points to, without opening it
secretli delete <owner-link> remove a secret for everyone
secretli send <link> hand a link to another device with a short code
secretli receive 7-acid-rocket open what another device sends with a code`,
secretli receive 7-acid-rocket open what another device sends with a code
secretli share -c --code the clipboard's text, handed over with a code
secretli receive 7-acid-rocket -c and on the other device, back onto the clipboard`,
SilenceUsage: true,
SilenceErrors: true,
Version: version(),
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const clipboardClearAfter = 45 * time.Second
// clipboardTool is the desktop's clipboard.
type clipboardTool interface {
// Available fails when there is no clipboard to copy to, so that
// --to-clipboard is refused before anything is opened.
// --clipboard is refused before anything is opened.
Available() error
Copy(text string) error
Paste() (string, error)
Expand Down
Loading