Skip to content

Commit

Permalink
trurl.md: extend the component sections with more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Sep 13, 2024
1 parent 7f9495b commit 3af9aef
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions trurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,56 @@ separator. It cannot be specified URL encoded.
A URL cannot exist without a scheme, but unless **--no-guess-scheme** is used
trurl guesses what scheme that was intended if none was provided.

Examples:

$ trurl https://odd/ -g '{scheme}'
https

$ trurl odd -g '{scheme}'
http

$ trurl odd -g '{scheme}' --no-guess-scheme
trurl note: Bad scheme [odd]

## user

After the scheme separator, there can be a username provided. If it ends with
a colon (`:`), there is a password provided. If it ends with an at character
(`@`) there is no password provided in the URL.

Example:

$ trurl https://user%3a%40:secret@odd/ -g '{user}'
user:@

## password

If the password ends with a semicolon (`;`) there is an options field
following. This field is only accepted by trurl for URLs using the IMAP
scheme.

Example:

$ trurl https://user:secr%65t@odd/ -g '{password}'
secret

## options

This field can only end with an at character (`@`) that separates the options
from the hostname.

$ trurl 'imap://user:pwd;giraffe@odd' -g '{options}'
giraffe

If the scheme is not IMAP, the `giraffe` part is instead considered part of
the password:

$ trurl 'sftp://user:pwd;giraffe@odd' -g '{password}'
pwd;giraffe

We strongly advice users to %-encode `;`, `:` and `@` in URLs of course to
reduce the risk for confusions.

## host

The host component is the hostname or a numerical IP address. If a hostname is
Expand Down Expand Up @@ -384,6 +417,11 @@ numbers separated with dots and they can use decimal, octal and hexadecimal.
If the provided host is an IPv6 address, it might contain a specific zoneid. A
number or a network interface name normally.

Example:

$ trurl 'http://[2001:9b1::f358:1ba4:7b97:364b%enp3s0]/' -g '{zoneid}'
enp3s0

## port

If the host ends with a colon (`:`) then a port number follows. It is a 16 bit
Expand Down Expand Up @@ -485,6 +523,12 @@ them first at least increases the chances of it working:
$ trurl "http://alpha/?one=real&two=fake&three=alsoreal" --sort-query
http://alpha/?one=real&three=alsoreal&two=fake

Remove name/value pairs from the URL by specifying exact name or wildcard
pattern with **--trim**:

$ trurl 'https://example.com?a12=hej&a23=moo&b12=foo' --trim 'query=a*'
https://example.com/?b12=foo

## fragment

The fragment part does not include the leading hash sign (`#`) separator when
Expand All @@ -509,6 +553,11 @@ trurl supports **url** as a named component for **--get** to allow for more
powerful outputs, but of course it is not actually a "component"; it is the
full URL.

Example:

$ trurl ftps://example.com:2021/p%61th -g '{url}'
ftps://example.com:2021/path

# JSON output format

The *--json* option outputs a JSON array with one or more objects. One for
Expand Down

0 comments on commit 3af9aef

Please sign in to comment.