An open API service indexing awesome lists of open source software.

https://github.com/mateconpizza/gurl

🔗 Extract URLs from STDIN
https://github.com/mateconpizza/gurl

mutt neomutt st-terminal suckless suckless-terminal urlscan urlview

Last synced: 22 days ago
JSON representation

🔗 Extract URLs from STDIN

Awesome Lists containing this project

README

          


🔗 gurl

Cheer gopher logo



💙 Gopher image by Takuya Ueda


![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/mateconpizza/gurl)
![Linux](https://img.shields.io/badge/-Linux-grey?logo=linux)
![Release](https://img.shields.io/github/v/release/mateconpizza/gurl)
![Go Report Card](https://goreportcard.com/badge/github.com/mateconpizza/gurl)
![GoDoc](https://pkg.go.dev/badge/github.com/mateconpizza/gurl.svg)

**gurl** is a [golang](https://golang.org/) >= `v1.24` program that reads `URLs` and other common identifiers from standard input `(STDIN)`

It is designed to work with any terminal that can `pipe` visible text to external programs, such as [st](https://st.suckless.org/), [alacritty](https://alacritty.org/), [kitty](https://sw.kovidgoyal.net/kitty/), [wezterm](https://wezterm.org/), or similar.

The primary use case is piping the currently visible terminal output into `gurl`.
I'm using [st](https://st.suckless.org/) terminal with [externalpipe](https://st.suckless.org/patches/externalpipe/) patch to `read/pipe` current visible text to this program.

### Features

- Read input from `STDIN`
- Extract `URLs` and other `identifiers`
- Remove `duplicate` results
- Support `custom` regular expressions
- Optional `index` prefix for results
- Optional extractor-based `prefixes`
- Limit number of items

### Built-in Extractors

| Name | Description |
| -------- | -------------------------------------------------------------------------------- |
| email | Email addresses |
| hash | Short hexadecimal identifiers (7–12 chars) |
| hexcolor | HEX colors (CSS/Web) |
| ipv4 | IPv4 addresses |
| ipv6 | IPv6 addresses |
| domain | Domain names |
| mac | MAC addresses |
| path | File paths (absolute, relative, file://) |
| raw | Raw input lines |
| sha | SHA-1 or SHA-256 hashes |
| url | Web URLs (http, https, ftp, www) |
| uuid | UUIDs |
| all | Enable all built-in extractors, including the ones added with the `--regex` flag |

### Installation

```sh
go install github.com/mateconpizza/gurl@latest
```

_To uninstall the program remove the binary in your `go env GOPATH`_

### Usage

```bash
$ gurl -h
Extract URLs from STDIN

Usage:
gurl [options]

Options:
-t, --type STR Comma-separated extractor types (default: url)
-E, --regex NAME=REGEX Register a custom extractor
-l, --list List built-in extractors
-n, --lines Limit number of results
-p, --prefix Prefix results with extractor name
-i, --index Prefix results with index number
-V, --version Show version and exit
-v, --verbose Enable verbose logging
-h, --help Show this help message
```

#### Examples

```sh
$ gurl --prefix --type hash,sha,url,uuid,ipv4,mac < input.txt
hash:865ed41
sha:abb9a11544fbd3d2a283ced39c4400cd66daf3f5
url:https://github.com/mateconpizza/gm
uuid:3510b822-56f4-4f6d-a773-05efc0baa7e2
ipv4:1.1.1.1
mac:ff:ff:ff:ff:ff:ff
...

# Extract short commit hash
$ git log --oneline | fzf --multi | gurl -t hash
46c4bb9
4dada2e
865ed41
...
```

### Using `-E|--regex` Flag

The flag `-E|--regex` can be use for `custom extractor`.

```bash
# list existing remotes
$ gurl -t jira -E jira='^PROJ-\d+$' < data/jira.txt
PROJ-1
PROJ-12
PROJ-123
PROJ-0001
PROJ-99999
...
```

#### Regex Syntax

Custom extractors use Go `RE2` syntax.

- Syntax Reference: [Google RE2
Syntax](https://github.com/google/re2/wiki/Syntax)
- Testing Tool: [regex101](https://regex101.com)

## Configuration

The configuration file is a JSON document where you can define custom regex extractors or modify built-in ones.

Example config.json

```json
{
"extractors": {
"jira": {
"regex": "\\b[A-Z]+-[0-9]+\\b",
"prefix": "jira:",
"description": "JIRA issue keys"
},
"reddit": {
"regex": "^\\s*(\\S+)\\s+/r/",
"prefix": "red:",
"description": "Tuir's reddit users"
}
}
}
```

### ⭐ Related Projects

- [urlscan](https://github.com/firecat53/urlscan) - Designed to integrate with the "mutt" mailreader
- [urlview](https://github.com/sigpipe/urlview) - Extract URLs from a text file and allow the user to select via a menu