Skip to content

Add opn plugin #2005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
| [nmount](nmount) | Toggle mount status of a device as normal user | sh | pmount (optional), udisks2 |
| [nuke](nuke) | Sample file opener (CLI-only by default) | sh | _see in-file docs_ |
| [oldbigfile](oldbigfile) | List large files by access time | sh | find, sort |
| [opn](opn) | Open selected file with the associated application, application picker | bash | [opn](https://github.com/MatthiasKunnen/opn) |
| [openall](openall) | Open selected files together or one by one [✓] | bash | - |
| [organize](organize) | Auto-organize files in directories by file type [✓] | sh | file |
| [pdfread](pdfread) | Read a PDF or text file aloud | sh | pdftotext, mpv,<br>pico2wave |
Expand Down
36 changes: 36 additions & 0 deletions plugins/opn
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# Use the CLI file opener program "opn" which allows selecting the application to open the
# file with based on the XDG Desktop and MimeApps Specification.
# See https://github.com/MatthiasKunnen/opn
#
# Integration with nnn:
# 1. Export the required config (change the path if necessary):
# export NNN_OPENER=/usr/share/nnn/plugins/opn
# 2. Run nnn with the program option to indicate a CLI opener
# nnn -c
# The -c program option overrides option -e
#
# Required configuration of opn:
# 1. Install opn, see https://github.com/MatthiasKunnen/opn/blob/master/Install.md
# 2. Set OPN_TERM_CMD to configure your preferred terminal.
# E.g. "foot" or "gnome-terminal --".
# See https://github.com/MatthiasKunnen/opn?tab=readme-ov-file#terminal-applications

set -uo pipefail

FPATH="$1"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
clear -x
fi

opn file "${FPATH}"
status=$?

if [ $status -eq 0 ]; then
exit 0
fi

# Show any error message to the user
read -rsn1 -p"Press any key to return to nnn";echo
Loading