• Stars
    star
    2,915
  • Rank 14,959 (Top 0.4 %)
  • Language
    C
  • License
    Other
  • Created about 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

trurl is a command line tool for URL parsing and manipulation.

trurl

Command line tool for URL parsing and manipulation

Video presentation

Examples

Replace the host name of a URL:

$ trurl --url https://curl.se --set host=example.com
https://example.com/

Create a URL by setting components:

$ trurl --set host=example.com --set scheme=ftp
ftp://example.com/

Redirect a URL:

$ trurl --url https://curl.se/we/are.html --redirect here.html
https://curl.se/we/here.html

Change port number:

$ trurl --url https://curl.se/we/../are.html --set port=8080
https://curl.se:8080/are.html

Extract the path from a URL:

$ trurl --url https://curl.se/we/are.html --get '{path}'
/we/are.html

Extract the port from a URL:

$ trurl --url https://curl.se/we/are.html --get '{port}'
443

Append a path segment to a URL:

$ trurl --url https://curl.se/hello --append path=you
https://curl.se/hello/you

Append a query segment to a URL:

$ trurl --url "https://curl.se?name=hello" --append query=search=string
https://curl.se/?name=hello&search=string

Read URLs from stdin:

$ cat urllist.txt | trurl --url-file -
...

Output JSON:

$ trurl "https://fake.host/hello#frag" --set user=::moo:: --json
[
  {
    "url": "https://%3a%3amoo%3a%[email protected]/hello#frag",
    "parts": {
      "scheme": "https",
      "user": "::moo::",
      "host": "fake.host",
      "path": "/hello",
      "fragment": "frag"
    }
  }
]

Remove tracking tuples from query:

$ trurl "https://curl.se?search=hey&utm_source=tracker" --trim query="utm_*"
https://curl.se/?search=hey

Show a specific query key value:

$ trurl "https://example.com?a=home&here=now&thisthen" -g '{query:a}'
home

Sort the key/value pairs in the query component:

$ trurl "https://example.com?b=a&c=b&a=c" --sort-query
https://example.com?a=c&b=a&c=b

Work with a query that uses a semicolon separator:

$ trurl "https://curl.se?search=fool;page=5" --trim query="search" --query-separator ";"
https://curl.se?page=5

Accept spaces in the URL path:

$ trurl "https://curl.se/this has space/index.html" --accept-space
https://curl.se/this%20has%20space/index.html

Install

Linux

It's quite easy to compile the C source with GCC:

$ make
cc  -W -Wall -pedantic -g   -c -o trurl.o trurl.c
cc   trurl.o  -lcurl -o trurl

trurl is also available in some Linux distributions. You can try searching for it using the package manager of your preferred distribution.

Windows

  1. Download and run Cygwin installer.
  2. Follow the instructions provided by the installer. When prompted to select packages, make sure to choose the following: curl, libcurl-devel, libcurl4, make and gcc-core.
  3. (optional) Add the Cygwin bin directory to your system PATH variable.
  4. Use make, just like on Linux.

Prerequisites

Development files of libcurl (e.g. libcurl4-openssl-dev or libcurl4-gnutls-dev) are needed for compilation. Requires libcurl version 7.62.0 or newer (the first libcurl to ship the URL parsing API).

trurl also uses CURLUPART_ZONEID added in libcurl 7.81.0 and curl_url_strerror() added in libcurl 7.80.0

It would certainly be possible to make trurl work with older libcurl versions if someone wanted to.

Older libcurls

trurl builds with libcurl older than 7.81.0 but will then not work as good. For all the documented goodness, use a more modern libcurl.

More Repositories

1

curl

A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS. libcurl offers a myriad of powerful features
C
31,356
star
2

everything-curl

The book documenting the curl project, the curl tool, libcurl and more. Simply put: everything curl.
Perl
1,946
star
3

curl-for-win

Reproducible curl binaries for Linux, macOS and Windows
Shell
662
star
4

doh

stand-alone application for DoH (DNS-over-HTTPS) name resolves and lookups
C
367
star
5

curl-cheat-sheet

A single page document with the most important curl options for HTTP explained
344
star
6

h2c

headers 2 curl. Provided a set of HTTP request headers, output the curl command line for generating that set. Try the converter online at
Perl
256
star
7

curl-docker

official docker image for curl
Makefile
163
star
8

curl-www

The curl.se website
HTML
100
star
9

curl-fuzzer

Quality assurance testing for the curl project
C++
82
star
10

stats

Scripts for generating project statistics and for plotting them as graphs.
Perl
59
star
11

curl-up

All things related to the curl up conference series
38
star
12

fcurl

fcurl - fopen, fread, fwrite style functions for URL operations using libcurl
C
35
star
13

curl-container

curl images
Shell
31
star
14

relative

Tools to measure libcurl performance delta between versions
C
16
star
15

curl.dev

The curl.dev website
HTML
10
star
16

build-images

repository for curl build images
Shell
10
star