Skip to content

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

License

Notifications You must be signed in to change notification settings

fcbertoldi/file-uri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published