Skip to content
/ url Public

URL builder with URL encoding for CLI and portable shell scripts

License

Notifications You must be signed in to change notification settings

ko1nksm/url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

url

URL builder with URL encoding for CLI and portable shell scripts. It is suitable for building URLs for curl, wget, etc.

Usage

The specification is not yet stable.

Usage: url [-rs]             [-nSN] [--] URLPATH [PARAMETERS]...
Usage: url -p [-j DELIMITER] [-nSN] [--] FORMAT  [ARGUMENTS]...
Usage: url -e [-m]            [-SN] [--] [ARGUMENTS]...
Usage: url -d                  [-S] [--] [ARGUMENTS]...

  URLPATH: url path
  PARAMETERS: [ -KEY VALUE | =STRING | #FRAGMENT ]...

Global options:
  -n                      Do not print the trailing newline character
  -p, --printf            printf mode (default: build mode)
  -e, --encode            URL Encoder mode (accepts stdin)
  -d, --decode            URL Decoder mode (accepts stdin)

Build mode options:
  -s                      Sort keys
  -r                      Remove empty value key

Printf mode options:
  -j, --join DELIMITER    Joins strings with the delimiter (default: '\n')

Encode mode options:
  -m                      Read multiple lines

Character conversion Options:
  -S  Use + instead of %20
  -N  Normalize newline to \r\n

Example

build mode:

$ url "http://example.com/" -param1 あ -param2 "" "#さ"
http://example.com/?param1=%E3%81%82&param2=%E3%81%8B#%E3%81%95

$ url "http://example.com/" =あいうえお
http://example.com/?%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A

printf mode:

$ url --printf "http://example.com/?param1=%s&param2=%s" あ a ア A
http://example.com/?param1=%E3%81%82&param2=%EF%BD%81
http://example.com/?param1=%E3%82%A2&param2=%EF%BC%A1

Use as a library

License is 0BSD. Feel free to copy and use the functions.

urlbuild

urlbuild URLPATH [ARGUMENTS]...
  URLPATH: url path
  ARGUMENTS: [ -KEY VALUE | =STRING | #FRAGMENT ]...

  Variables:
    SHURL_SPACE: A character to use instead of %20
    SHURL_EOL: Characters used on new lines

urlencode

urlencode [ARGUMENTS]...

  ARGUMENTS: argument to be URL-encoded

  Variables:
    SHURL_SPACE: A character to use instead of %20
    SHURL_EOL: Characters used on new lines

urldecode

urldecode [ARGUMENTS]...

  ARGUMENTS: argument to be URL-decoded

  Variables:
    SHURL_SPACE: A character to use instead of %20
    SHURL_EOL: Characters used on new lines

About

URL builder with URL encoding for CLI and portable shell scripts

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages