MyNixOS website logo
Description

Open files or URLs using associated programs.

The opn command lets you open files and URLs with associated programs. It's intended to "just work" and to be trivial to configure. See the README at https://github.com/akc/opn for further info.

  ____  ____  ____
 / __ \/ __ \/ __ \
/ /_/ / /_/ / / / /
\____/ .___/_/ /_/
    /_/            

Build Status

The opn command lets you open files and URLs with associated programs. It's intended to "just work" and to be trivial to configure. Its configuration resides in ~/.opnconfig; here's an example:

[browser]
browser: chromium

[associations]
mupdf:    .pdf
emacs:    .lhs .hs .py .c
chromium: .png .jpg .html .txt
mpv:      .avi .mpg .mp4
djview:   .djvu

With this configuration, PDFs would open in mupdf; Haskell, Python and C source files in emacs, etc. If asked to open a file with no matching extension, or a file without an extension, opn tries to be a bit smart. If, for example, one runs

opn foo.h

then the header file foo.h would be opened in emacs. The reason is that such files have mime type text/x-c, and, as files with the extension '.c' shares this mime type, opn "guesses" that '.h' files also should be opened with emacs.

Both [browser] and [associations] sections must be present and nonempty in ~/.opnconfig. The [browser] section should in fact always have exactly one key, namely browser. So a (close to) minimal configuration looks something like this:

[browser]
browser: chromium

[associations]
chromium: html

The browser is used for URLs and as a fallback, so with this configuration all files and URLs would open in chromium.

Talking of chromium: on Linux chromium opens downloads using xdg-open. This works pretty well if you are using a full desktop environment like GNOME, KDE or Xfce, but less so if you are running a light window manager such as i3 or xmonad. We can, however, exploit a behavior of xdg-open to effectively replace it with opn. As a fallback, when no supported desktop session is running, xdg-open uses $BROWSER. Thus putting

export BROWSER=opn

in your .bashrc, or something similar for your favorite shell, will "trick" chromium and xdg-open into using opn. This is my own main use for opn.

For further info see the man page: https://github.com/akc/opn/blob/master/opn.md.

Metadata

Version

0.1.3

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows