fcbertoldi / file-uri

POSIX shell tool to convert a path to the file URI format (file:///path)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

file-uri

file-uri is a shell script that converts input paths into file URIs.

Some terminal emulators, such as alacritty, support clickable URI links. You can use file-uri f.ex. in a script or shell one-liner to output a file path with the file:// scheme where you can open in the web browser.

Examples

Converting a relative path:

$ mkdir /tmp/foo && cd /tmp/foo
$ file-uri a
file:///tmp/foo/a

Multiple params:

$ file-uri a b c
file:///tmp/foo/a
file:///tmp/foo/b
file:///tmp/foo/c

Converting absolute paths:

$ file-uri /usr/bin
file:///usr/bin

Percent-encodes reserved URI ASCII characters:

$ file-uri "with whitespace"
file:///tmp/foo/with%20whitespace

Handling stdin:

$ touch c d e
$ ls | file-uri
file:///tmp/foo/c
file:///tmp/foo/d
file:///tmp/foo/e

Passing the computer host as param:

$ file-uri -n localhost a
file://localhost/tmp/a

Usage

Usage:
  file-uri [-z | --no-hostname] [-n <hostname> | --host=<hostname>] [-t] <path>...
  file-uri [-z | --no-hostname] [-n <hostname> | --host=<hostname>] [-t] [-]
  file-uri -h | --help

Options:
  -z --no-hostname      do not output hostname prefix (file:/path).
  -n --host=<hostname>  use <hostname> in the host part
  -t                    do not output the trailing newline

Arguments:
  <path>  file path

About

POSIX shell tool to convert a path to the file URI format (file:///path)

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Shell 84.1%Language:Perl 13.6%Language:Makefile 2.4%