Skip to content

staticaland/go-whaturl

Repository files navigation

whaturl

Build Vale Lint CUE Release Version Docs

About

whaturl replaces URLs found in text with a markup hyperlink with the contents of the <title> tag in the HTML of the URL. It works like a typical Unix filter:

echo "I like https://github.com" | whaturl
I like [GitHub: Where the world builds software · GitHub](https://github.com)

Inspired by Titler by Brett Terpstra for Mac OS and org-cliplink for Emacs.

Installation

Check out releases for pre-built binaries.

A Homebrew formula is included at Formula/whaturl.rb.

brew tap staticaland/go-whaturl https://github.com/staticaland/go-whaturl
brew install whaturl

If you watch the project (Watch → Custom → Releases) you can easily upgrade to the latest version when notified:

brew upgrade whaturl

To uninstall:

brew uninstall whaturl
brew untap staticaland/go-whaturl

Usage

Usage of whaturl:
  -format string
    	Specify link format (default "markdown")
  -list
    	Create list of links
  -relaxed
    	Process URLs without a schema

If you run the program, it will wait for input from stdin.

whaturl

You can write lines to it and get a result by pressing enter. To finish, press Ctrl+D to communicate end-of-transmission. However, the more common use-case is to pipe something directly:

cat urls | whaturl

Editor integration

Emacs

I use reformatter.el (see my reformatter.el configuration here). You may also want to check out Apheleia. Otherwise, shell-command-on-region (docs) is what you are looking for. Read Executing Shell Commands in Emacs to learn more.

Vim

nnoremap <leader>l :%!whaturl<CR>
vnoremap <leader>l :!whaturl<CR>

This is reminiscent of the Vim Kōan Master Wq and the Markdown acolyte.

Build and run

Build

go build whaturl.go
go run whaturl.go

Tests

Build

You can find some table driven tests in whaturl_test.go.

go test

Similar projects

See also

Bookmarklets

Org Mode:

javascript:(
    function(){
        prompt(
            '',
            '[['
                +location.href
                +']['
                +document.title.replace(/ [-,|].*$/,'')
                +']]'
        )
    }
)()

Markdown:

javascript:(
    function(){
        prompt(
            '',
            '['
                +[location.href](<document.title.replace(/ [-,|].*$/,'')>)
                +']('
                +location.href
                +')'
        )
    }
)()