aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2023-08-23 19:43:08 +0500
committerAnton Bobov <anton@bobov.name>2023-08-23 19:43:08 +0500
commit6dab4cddfaa9ae393301d23b8c7456dee39a0ad8 (patch)
tree63f6e443850cffe020d76c2a81db06d256edb1f9
parent5694227f8d2c4b5c5e6da251a496b808b7b59897 (diff)
[nnn] Add plugins
-rwxr-xr-x.gitignore1
-rwxr-xr-xfiles/.config/nnn/plugins/.nnn-plugin-helper61
-rwxr-xr-xfiles/.config/nnn/plugins/autojump74
-rwxr-xr-xfiles/.config/nnn/plugins/fzopen83
-rwxr-xr-xfiles/.config/nnn/plugins/preview-tui491
-rw-r--r--install.conf.yaml1
6 files changed, 711 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 7b951ed..4984f8f 100755
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@
/files/.config/mpv/watch_later/
files/.config/lazygit/development.log
files/.config/lazygit/state.yml
+files/.config/nnn/bookmarks
diff --git a/files/.config/nnn/plugins/.nnn-plugin-helper b/files/.config/nnn/plugins/.nnn-plugin-helper
new file mode 100755
index 0000000..118e6c7
--- /dev/null
+++ b/files/.config/nnn/plugins/.nnn-plugin-helper
@@ -0,0 +1,61 @@
+#!/usr/bin/env sh
+
+# Description: Helper script for plugins
+#
+# Shell: POSIX compliant
+# Author: Anna Arad
+
+selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
+export selection
+
+## Set CUR_CTX to 1 to open directory in current context
+CUR_CTX=0
+export CUR_CTX
+
+NNN_PREFER_SELECTION="${NNN_PREFER_SELECTION:-0}"
+export NNN_PREFER_SELECTION
+
+## Ask nnn to switch to directory $1 in context $2.
+## If $2 is not provided, the function asks explicitly.
+nnn_cd () {
+ dir="$1"
+
+ if [ -z "$NNN_PIPE" ]; then
+ echo "No pipe file found" 1>&2
+ return
+ fi
+
+ if [ -n "$2" ]; then
+ context=$2
+ elif [ $CUR_CTX -ne 1 ]; then
+ printf "Choose context 1-4 (blank for current): "
+ read -r context
+ fi
+
+ printf "%s" "${context:-0}c$dir" > "$NNN_PIPE"
+}
+
+cmd_exists () {
+ type "$1" > /dev/null 2>&1
+ echo $?
+}
+
+nnn_use_selection() {
+ if ! [ -s "$selection" ]; then
+ return 1
+ fi
+
+ if [ "$NNN_PREFER_SELECTION" -eq 1 ]; then
+ return 0
+ else
+ [ -n "$1" ] && printf "%s " "$1"
+ printf "(s)election/(c)urrent? [default=c] "
+ read -r resp__
+
+ if [ "$resp__" = "s" ]; then
+ return 0
+ else
+ return 1
+ fi
+ fi
+}
diff --git a/files/.config/nnn/plugins/autojump b/files/.config/nnn/plugins/autojump
new file mode 100755
index 0000000..6a24a52
--- /dev/null
+++ b/files/.config/nnn/plugins/autojump
@@ -0,0 +1,74 @@
+#!/usr/bin/env sh
+
+# Description: Navigate to directory using jump/autojump/zoxide/z
+#
+# Dependencies:
+# - jump - https://github.com/gsamokovarov/jump
+# - OR autojump - https://github.com/wting/autojump
+# - OR zoxide - https://github.com/ajeetdsouza/zoxide
+# - OR z - https://github.com/rupa/z (z requires fzf)
+# - OR z (fish) - https://github.com/jethrokuan/z (z requires fzf)
+# - OR z.lua - https://github.com/skywind3000/z.lua (z.lua can enhanced with fzf)
+#
+# Note: The dependencies STORE NAVIGATION PATTERNS
+#
+# to make z.lua work, you need to set $NNN_ZLUA to the path of script z.lua
+#
+# Shell: POSIX compliant
+# Authors: Marty Buchaus, Dave Snider, Tim Adler, Nick Waywood
+
+if [ ! -p "$NNN_PIPE" ]; then
+ printf 'ERROR: NNN_PIPE is not set!'
+ read -r _
+ exit 2
+fi
+
+if type jump >/dev/null 2>&1; then
+ printf "jump to : "
+ IFS= read -r line
+ # shellcheck disable=SC2086
+ odir="$(jump cd ${line})"
+ printf "%s" "0c$odir" > "$NNN_PIPE"
+elif type autojump >/dev/null 2>&1; then
+ printf "jump to : "
+ read -r dir
+ odir="$(autojump "$dir")"
+ printf "%s" "0c$odir" > "$NNN_PIPE"
+elif type zoxide >/dev/null 2>&1; then
+ if type fzf >/dev/null 2>&1; then
+ odir="$(zoxide query -i --)"
+ printf "%s" "0c$odir" > "$NNN_PIPE"
+ else
+ printf "jump to : "
+ read -r dir
+ odir="$(zoxide query -- "$dir")"
+ printf "%s" "0c$odir" > "$NNN_PIPE"
+ fi
+elif type lua >/dev/null 2>&1 && [ -n "$NNN_ZLUA" ]; then
+ printf "jump to : "
+ read -r line
+ if type fzf >/dev/null 2>&1; then
+ odir="$(lua "$NNN_ZLUA" -l "$line" | fzf --nth 2.. --reverse --inline-info --tac +s -e --height 35%)"
+ printf "%s" "0c$(echo "$odir" | awk '{print $2}')" > "$NNN_PIPE"
+ else
+ odir="$(lua "$NNN_ZLUA" -e "$line")"
+ printf "%s" "0c$odir" > "$NNN_PIPE"
+ fi
+else
+ # rupa/z uses $_Z_DATA, jethrokuan/z (=port of z for fish) uses $Z_DATA
+ datafile="${_Z_DATA:-${Z_DATA:-$HOME/.z}}"
+ if type fzf >/dev/null 2>&1 && [ -f "$datafile" ]; then
+ # Read the data from z's file instead of calling
+ # z so the data doesn't need to be processed twice
+ sel=$(awk -F "|" '{print $1}' "$datafile" | fzf | awk '{$1=$1};1')
+
+ # NOTE: Uncomment this line and comment out the line above if
+ # you want to see the weightings of the dir's in the fzf pane
+ # sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | fzf | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1')
+
+ printf "%s" "0c$sel" > "$NNN_PIPE"
+ else
+ printf "No supported autojump script [jump/autojump/zoxide/z (needs fzf)] found"
+ read -r _
+ fi
+fi
diff --git a/files/.config/nnn/plugins/fzopen b/files/.config/nnn/plugins/fzopen
new file mode 100755
index 0000000..17b0585
--- /dev/null
+++ b/files/.config/nnn/plugins/fzopen
@@ -0,0 +1,83 @@
+#!/usr/bin/env sh
+
+# Description: Regular mode:
+# Fuzzy find a file in directory subtree.
+# Opens in $VISUAL or $EDITOR if text.
+# Opens other type of files with xdg-open.
+# Work only with a single file selected.
+#
+# Picker mode:
+# If picker mode output file is passed, it
+# will be overwritten with any picked files.
+# Leaves untouched if no file is picked.
+# Works with single/multiple files selected.
+#
+# Dependencies: fd/find, fzf/skim, xdg-open/open (on macOS)
+#
+# Shell: POSIX compliant
+# Author: Arun Prakash Jana
+
+NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
+USE_NUKE=0
+
+# shellcheck disable=SC1090,SC1091
+. "$(dirname "$0")"/.nnn-plugin-helper
+
+if type fzf >/dev/null 2>&1; then
+ cmd="$FZF_DEFAULT_COMMAND"
+ if type fd >/dev/null 2>&1; then
+ [ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
+ else
+ [ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
+ fi
+ entry="$(eval "$cmd" | fzf -m)"
+ # To show only the file name
+ # entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
+elif type sk >/dev/null 2>&1; then
+ entry=$(find . -type f 2>/dev/null | sk)
+else
+ exit 1
+fi
+
+# Check for picker mode
+if [ "$3" ]; then
+ if [ "$entry" ]; then
+ case "$entry" in
+ /*) fullpath="$entry" ;;
+ *) fullpath="$PWD/$entry" ;;
+ esac
+ if [ "-" = "$3" ]; then
+ printf "%s\n" "$fullpath"
+ else
+ printf "%s\n" "$fullpath" > "$3"
+ fi
+
+ # Tell `nnn` to clear its internal selection
+ printf "%s" "0p" > "$NNN_PIPE"
+ fi
+
+ exit 0
+fi
+
+if [ "$USE_NUKE" -ne 0 ]; then
+ "$NUKE" "$entry"
+ exit 0
+fi
+
+# Open the file (works for a single file only)
+cmd_file=""
+cmd_open=""
+if uname | grep -q "Darwin"; then
+ cmd_file="file -bIL"
+ cmd_open="open"
+else
+ cmd_file="file -biL"
+ cmd_open="xdg-open"
+fi
+
+case "$($cmd_file "$entry")" in
+ *text*)
+ "${VISUAL:-$EDITOR}" "$entry" ;;
+ *)
+ $cmd_open "$entry" >/dev/null 2>&1 ;;
+esac
diff --git a/files/.config/nnn/plugins/preview-tui b/files/.config/nnn/plugins/preview-tui
new file mode 100755
index 0000000..e78b110
--- /dev/null
+++ b/files/.config/nnn/plugins/preview-tui
@@ -0,0 +1,491 @@
+#!/usr/bin/env bash
+
+# Description: Terminal based file previewer
+#
+# Note: This plugin needs a "NNN_FIFO" to work. See man.
+#
+# Dependencies:
+# - Supports 6 independent methods to preview with:
+# - tmux (>=3.0), or
+# - kitty with allow_remote_control and listen_on set in kitty.conf, or
+# - wezterm (https://wezfurlong.org/wezterm), or
+# - QuickLook on WSL (https://github.com/QL-Win/QuickLook), or
+# - Windows Terminal (https://github.com/Microsoft/Terminal | https://aka.ms/terminal) with WSL, or
+# - $NNN_TERMINAL set to a terminal (it's xterm by default).
+# - less or $NNN_PAGER
+# - tree or exa or (GNU) ls
+# - mediainfo or file
+# - mktemp
+# - unzip
+# - tar
+# - man
+# - optional: bsdtar or atool for additional archive preview
+# - optional: bat for code syntax highlighting
+# - optional: ueberzug, kitty terminal, wezterm terminal, viu, catimg or chafa for images
+# - optional: convert(ImageMagick) for playing gif preview (required for kitty image previews)
+# - optional: ffmpegthumbnailer for video thumbnails (https://github.com/dirkvdb/ffmpegthumbnailer)
+# - optional: ffmpeg for audio thumbnails
+# - optional: libreoffce for opendocument/officedocument preview
+# - optional: pdftoppm(poppler) for pdf thumbnails
+# - optional: gnome-epub-thumbnailer for epub thumbnails (https://gitlab.gnome.org/GNOME/gnome-epub-thumbnailer)
+# - optional: fontpreview for font preview (https://github.com/sdushantha/fontpreview)
+# - optional: djvulibre for djvu
+# - optional: glow or lowdown for markdown
+# - optional: w3m or lynx or elinks for html
+# - optional: set/export NNN_ICONLOOKUP as 1 to enable file icons in front of directory previews with .iconlookup
+# Icons and colors are configurable in .iconlookup
+# - optional: scope.sh file viewer from ranger.
+# 1. drop scope.sh executable in $PATH
+# 2. set/export $NNN_SCOPE as 1
+# - optional: pistol file viewer (https://github.com/doronbehar/pistol).
+# 1. install pistol
+# 2. set/export $NNN_PISTOL as 1
+#
+# Usage:
+# You need to set a NNN_FIFO path and a key for the plugin with NNN_PLUG,
+# then start `nnn`:
+#
+# $ nnn -a
+#
+# or
+#
+# $ NNN_FIFO=/tmp/nnn.fifo nnn
+#
+# Then launch the `preview-tui` plugin in `nnn`.
+#
+# If you provide the same NNN_FIFO to all nnn instances, there will be a
+# single common preview window. If you provide different FIFO path (e.g.
+# with -a), they will be independent.
+#
+# The previews will be shown in a tmux split. If that isn't possible, it
+# will try to use a kitty terminal split. And as a final fallback, a
+# different terminal window will be used ($NNN_TERMINAL).
+#
+# Kitty users need something similar to the following in their kitty.conf:
+# - `allow_remote_control yes`
+# - `listen_on unix:$TMPDIR/kitty`
+# - `enabled_layouts splits` (optional)
+# With ImageMagick installed, this terminal can use the icat kitten to display images.
+# Refer to kitty documentation for further details.
+#
+# Wezterm should work out of the box. If `NNN_PREVIEWIMGPROG` is not specified it will use
+# built in iTerm2 image protocol.
+#
+# Note that GNU ls is used for its `--group-directories-first` flag.
+# On MacOS this may be installed with `brew install coreutils`, or the flag can be removed.
+# iTerm2 users are recommended to use viu to view images without getting pixelated.
+#
+# Windows Terminal users can set "Profile termination behavior" under "Profile > Advanced" settings
+# to automatically close pane on quit when exit code is 0.
+#
+# When specifying a different terminal, additional arguments are supported. In particular, you can
+# append a specific title to the terminal and set it to "nofocus" in your WM config.
+# E.g for alacritty and i3, you can set $NNN_TERMINAL to 'alacritty --title preview-tui' and add
+# 'no_focus [title="preview-tui"]' to your i3 config file.
+#
+# Shell: Bash (for environment manipulation through arrays)
+# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal, @WanderLanz
+
+NNN_SPLIT=${NNN_SPLIT:-} # Set permanent split direction
+NNN_TERMINAL=${NNN_TERMINAL:-} # Set external terminal to be used
+NNN_SPLITSIZE=${NNN_SPLITSIZE:-50} # Set previewer split size percentage
+TMPDIR=${TMPDIR:-/tmp}
+NNN_PARENT=${NNN_FIFO#*.}
+[ "$NNN_PARENT" -eq "$NNN_PARENT" ] 2>/dev/null || NNN_PARENT="" # Make empty if non-numeric
+ENVVARS=(
+ "PWD=$PWD"
+ "PATH=$PATH"
+ "NNN_FIFO=$NNN_FIFO"
+ "NNN_SCOPE=${NNN_SCOPE:-0}"
+ "NNN_PISTOL=${NNN_PISTOL:-0}"
+ "NNN_ICONLOOKUP=${NNN_ICONLOOKUP:-0}"
+ "NNN_PAGER=${NNN_PAGER:-less -P?n -R -C}"
+ "NNN_BATTHEME=${NNN_BATTHEME:-ansi}"
+ "NNN_BATSTYLE=${NNN_BATSTYLE:-numbers}"
+ "NNN_PREVIEWWIDTH=${NNN_PREVIEWWIDTH:-1920}"
+ "NNN_PREVIEWHEIGHT=${NNN_PREVIEWHEIGHT:-1080}"
+ "NNN_PREVIEWDIR=${NNN_PREVIEWDIR:-$TMPDIR/nnn/previews}"
+ "NNN_PREVIEWIMGPROG=${NNN_PREVIEWIMGPROG:-}"
+ "FIFOPID=$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
+ "FIFOPATH=$TMPDIR/nnn-preview-tui-fifo.$NNN_PARENT"
+ "PREVIEWPID=$TMPDIR/nnn-preview-tui-previewpid.$NNN_PARENT"
+ "CURSEL=$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT"
+ "FIFO_UEBERZUG=$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
+ "POSOFFSET=$TMPDIR/nnn-preview-tui-posoffset"
+)
+
+trap '' PIPE
+exists() { type "$1" >/dev/null 2>&1 ;}
+pkill() { command pkill "$@" >/dev/null 2>&1 ;}
+prompt() { clear; printf "%b" "$@"; cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" ;}
+pidkill() {
+ if [ -f "$1" ]; then
+ PID="$(cat "$1" 2>/dev/null)" || return 1
+ kill "$PID" >/dev/null 2>&1
+ RET=$?
+ wait "$PID" 2>/dev/null
+ return $RET
+ fi
+ return 1
+}
+
+start_preview() {
+ if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
+ NNN_TERMINAL=tmux
+ elif [ -n "$KITTY_LISTEN_ON" ]; then
+ NNN_TERMINAL=kitty
+ elif [ -n "$WEZTERM_PANE" ]; then
+ NNN_TERMINAL=wezterm
+ elif [ -z "$NNN_TERMINAL" ] && [ "$TERM_PROGRAM" = "iTerm.app" ]; then
+ NNN_TERMINAL=iterm
+ elif [ -n "$WT_SESSION" ]; then
+ NNN_TERMINAL=winterm
+ else
+ NNN_TERMINAL="${NNN_TERMINAL:-xterm}"
+ fi
+
+ if [ -z "$NNN_SPLIT" ] && [ $(($(tput lines) * 2)) -gt "$(tput cols)" ]; then
+ NNN_SPLIT='h'
+ elif [ "$NNN_SPLIT" != 'h' ]; then
+ NNN_SPLIT='v'
+ fi
+
+ ENVVARS+=("NNN_TERMINAL=$NNN_TERMINAL" "NNN_SPLIT=$NNN_SPLIT" "QLPATH=$2" "PREVIEW_MODE=1")
+ case "$NNN_TERMINAL" in
+ iterm|winterm) # need run in separate shell command: escape
+ ENVVARS=("${ENVVARS[@]/#/\\\"}")
+ ENVVARS=("${ENVVARS[@]/%/\\\"}")
+ command="$SHELL -c 'env ${ENVVARS[*]} \\\"$0\\\" \\\"$1\\\"'" ;;
+ esac
+
+ case "$NNN_TERMINAL" in
+ tmux) # tmux splits are inverted
+ ENVVARS=("${ENVVARS[@]/#/-e}")
+ if [ "$NNN_SPLIT" = "v" ]; then split="h"; else split="v"; fi
+ tmux split-window "${ENVVARS[@]}" -d"$split" -p"$NNN_SPLITSIZE" "$0" "$1" ;;
+ kitty) # Setting the layout for the new window. It will be restored after the script ends.
+ ENVVARS=("${ENVVARS[@]/#/--env=}")
+ kitty @ goto-layout splits
+ # Trying to use kitty's integrated window management as the split window.
+ kitty @ launch --no-response --title "preview-tui" --keep-focus \
+ --cwd "$PWD" "${ENVVARS[@]}" --location "${NNN_SPLIT}split" "$0" "$1" ;;
+ wezterm)
+ export "${ENVVARS[@]}"
+ if [ "$NNN_SPLIT" = "v" ]; then split="--horizontal"; else split="--bottom"; fi
+ wezterm cli split-pane --cwd "$PWD" $split --percent "$NNN_SPLITSIZE" "$0" "$1" >/dev/null
+ wezterm cli activate-pane-direction Prev ;;
+ iterm)
+ if [ "$NNN_SPLIT" = "h" ]; then split="horizontally"; else split="vertically"; fi
+ osascript <<-EOF
+ tell application "iTerm"
+ tell current session of current window
+ split $split with default profile command "$command"
+ end tell
+ end tell
+EOF
+ ;;
+ winterm)
+ if [ "$NNN_SPLIT" = "h" ]; then split="H"; else split="V"; fi
+ wt -w 0 sp -$split -s"0.$NNN_SPLITSIZE" "$command" \; -w 0 mf previous 2>/dev/null ;;
+ *) if [ -n "$2" ]; then
+ env "${ENVVARS[@]}" QUICKLOOK=1 "$0" "$1" &
+ else
+ # shellcheck disable=SC2086 # (allow arguments)
+ env "${ENVVARS[@]}" $NNN_TERMINAL -e "$0" "$1" &
+ fi ;;
+ esac
+}
+
+toggle_preview() {
+ export "${ENVVARS[@]}"
+ if exists QuickLook.exe; then
+ QLPATH="QuickLook.exe"
+ elif exists Bridge.exe; then
+ QLPATH="Bridge.exe"
+ fi
+ if pidkill "$FIFOPID"; then
+ [ -p "$NNN_PPIPE" ] && printf "0" > "$NNN_PPIPE"
+ pidkill "$PREVIEWPID"
+ pkill -f "tail --follow $FIFO_UEBERZUG"
+ if [ -n "$QLPATH" ] && stat "$1"; then
+ f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
+ fi
+ else
+ [ -p "$NNN_PPIPE" ] && printf "1" > "$NNN_PPIPE"
+ start_preview "$1" "$QLPATH"
+ fi
+}
+
+fifo_pager() {
+ cmd="$1"
+ shift
+
+ # We use a FIFO to access $NNN_PAGER PID in jobs control
+ mkfifo "$FIFOPATH" || return
+
+ $NNN_PAGER < "$FIFOPATH" &
+ printf "%s" "$!" > "$PREVIEWPID"
+
+ (
+ exec > "$FIFOPATH"
+ if [ "$cmd" = "pager" ]; then
+ if exists bat; then
+ bat --terminal-width="$cols" --decorations=always --color=always \
+ --paging=never --style="$NNN_BATSTYLE" --theme="$NNN_BATTHEME" "$@" &
+ else
+ $NNN_PAGER "$@" &
+ fi
+ else
+ "$cmd" "$@" &
+ fi
+ )
+
+ rm "$FIFOPATH"
+}
+
+# Binary file: show file info inside the pager
+print_bin_info() {
+ printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
+ if exists mediainfo; then
+ mediainfo "$1"
+ else
+ file -b "$1"
+ fi
+}
+
+handle_mime() {
+ case "$2" in
+ image/jpeg) image_preview "$cols" "$lines" "$1" ;;
+ image/gif) generate_preview "$cols" "$lines" "$1" "gif" ;;
+ image/vnd.djvu) generate_preview "$cols" "$lines" "$1" "djvu" ;;
+ image/*) generate_preview "$cols" "$lines" "$1" "image" ;;
+ video/*) generate_preview "$cols" "$lines" "$1" "video" ;;
+ audio/*) generate_preview "$cols" "$lines" "$1" "audio" ;;
+ application/font*|application/*opentype|font/*) generate_preview "$cols" "$lines" "$1" "font" ;;
+ */*office*|*/*document*|*/*msword|*/*ms-excel) generate_preview "$cols" "$lines" "$1" "office" ;;
+ application/zip) fifo_pager unzip -l "$1" ;;
+ text/troff)
+ if exists man; then
+ fifo_pager man -Pcat -l "$1"
+ else
+ fifo_pager pager "$1"
+ fi ;;
+ *) handle_ext "$1" "$3" "$4" ;;
+ esac
+}
+
+handle_ext() {
+ case "$2" in
+ epub) generate_preview "$cols" "$lines" "$1" "epub" ;;
+ pdf) generate_preview "$cols" "$lines" "$1" "pdf" ;;
+ gz|bz2) fifo_pager tar -tvf "$1" ;;
+ md) if exists glow; then
+ fifo_pager glow -s dark "$1"
+ elif exists lowdown; then
+ fifo_pager lowdown -Tterm "$1"
+ else
+ fifo_pager pager "$1"
+ fi ;;
+ htm|html|xhtml)
+ if exists w3m; then
+ fifo_pager w3m "$1"
+ elif exists lynx; then
+ fifo_pager lynx "$1"
+ elif exists elinks; then
+ fifo_pager elinks "$1"
+ else
+ fifo_pager pager "$1"
+ fi ;;
+ 7z|a|ace|alz|arc|arj|bz|cab|cpio|deb|jar|lha|lz|lzh|lzma|lzo\
+ |rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z)
+ if exists atool; then
+ fifo_pager atool -l "$1"
+ elif exists bsdtar; then
+ fifo_pager bsdtar -tvf "$1"
+ fi ;;
+ *) if [ "$3" = "bin" ]; then
+ fifo_pager print_bin_info "$1"
+ else
+ fifo_pager pager "$1"
+ fi ;;
+ esac
+}
+
+preview_file() {
+ clear
+ # Trying to use pistol if it's available.
+ if [ "$NNN_PISTOL" -ne 0 ] && exists pistol; then
+ fifo_pager pistol "$1"
+ return
+ fi
+
+ # Trying to use scope.sh if it's available.
+ if [ "$NNN_SCOPE" -ne 0 ] && exists scope.sh; then
+ fifo_pager scope.sh "$1" "$cols" "$lines" "$(mktemp -d)" "True"
+ return
+ fi
+
+ # Use QuickLook if it's available.
+ if [ -n "$QUICKLOOK" ]; then
+ stat "$1" && f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
+ return
+ fi
+
+ # Detecting the exact type of the file: the encoding, mime type, and extension in lowercase.
+ encoding="$(file -bL --mime-encoding -- "$1")"
+ mimetype="$(file -bL --mime-type -- "$1")"
+ ext="${1##*.}"
+ [ -n "$ext" ] && ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
+ lines=$(tput lines)
+ cols=$(tput cols)
+
+ # Otherwise, falling back to the defaults.
+ if [ -d "$1" ]; then
+ cd "$1" || return
+ if [ "$NNN_ICONLOOKUP" -ne 0 ] && [ -f "$(dirname "$0")"/.iconlookup ]; then
+ [ "$NNN_SPLIT" = v ] && BSTR="\n"
+ # shellcheck disable=SC2012
+ ls -F --group-directories-first | head -n "$((lines - 3))" | "$(dirname "$0")"/.iconlookup -l "$cols" -B "$BSTR" -b " "
+ elif exists tree; then
+ fifo_pager tree --filelimit "$(find . -maxdepth 1 | wc -l)" -L 3 -C -F --dirsfirst --noreport
+ elif exists exa; then
+ exa -G --group-directories-first --colour=always
+ else
+ fifo_pager ls -F --group-directories-first --color=always
+ fi
+ cd ..
+ elif [ "${encoding#*)}" = "binary" ]; then
+ handle_mime "$1" "$mimetype" "$ext" "bin"
+ else
+ handle_mime "$1" "$mimetype" "$ext"
+ fi
+}
+
+generate_preview() {
+ if [ -n "$QLPATH" ] && stat "$3"; then
+ f="$(wslpath -w "$3")" && "$QLPATH" "$f" &
+ elif [ ! -f "$NNN_PREVIEWDIR/$3.jpg" ] || [ -n "$(find -L "$3" -newer "$NNN_PREVIEWDIR/$3.jpg")" ]; then
+ mkdir -p "$NNN_PREVIEWDIR/${3%/*}"
+ case $4 in
+ audio) ffmpeg -i "$3" -filter_complex "scale=iw*min(1\,min($NNN_PREVIEWWIDTH/iw\,ih)):-1" "$NNN_PREVIEWDIR/$3.jpg" -y ;;
+ epub) gnome-epub-thumbnailer "$3" "$NNN_PREVIEWDIR/$3.jpg" ;;
+ font) fontpreview -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" ;;
+ gif) if [ -p "$FIFO_UEBERZUG" ] && exists convert; then
+ frameprefix="$NNN_PREVIEWDIR/$3/${3##*/}"
+ if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then
+ mkdir -p "$NNN_PREVIEWDIR/$3"
+ convert -coalesce -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$3" "$frameprefix.jpg" ||
+ MAGICK_TMPDIR="/tmp" convert -coalesce -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$3" "$frameprefix.jpg"
+ fi
+ frames=$(($(find "$NNN_PREVIEWDIR/$3" | wc -l) - 2))
+ [ $frames -lt 0 ] && return
+ while true; do
+ for i in $(seq 0 $frames); do
+ image_preview "$1" "$2" "$frameprefix-$i.jpg"
+ sleep 0.1
+ done
+ done &
+ printf "%s" "$!" > "$PREVIEWPID"
+ return
+ else
+ image_preview "$1" "$2" "$3"
+ return
+ fi ;;
+ image) if exists convert; then
+ convert "$3" -flatten -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$NNN_PREVIEWDIR/$3.jpg"
+ else
+ image_preview "$1" "$2" "$3" && return
+ fi ;;
+ office) libreoffice --convert-to jpg "$3" --outdir "$NNN_PREVIEWDIR/${3%/*}"
+ filename="$(printf "%s" "${3##*/}" | cut -d. -f1)"
+ mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;;
+ pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;;
+ djvu) ddjvu -format=ppm -page=1 "$3" "$NNN_PREVIEWDIR/$3.jpg" ;;
+ video) ffmpegthumbnailer -m -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
+ esac
+ fi
+ if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
+ image_preview "$1" "$2" "$NNN_PREVIEWDIR/$3.jpg"
+ else
+ fifo_pager print_bin_info "$3"
+ fi
+} >/dev/null 2>&1
+
+image_preview() {
+ clear
+ exec >/dev/tty
+ if [ "$NNN_TERMINAL" = "kitty" ] && [ -z "$NNN_PREVIEWIMGPROG" ]; then
+ kitty +kitten icat --silent --scale-up --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" &
+ elif [ "$NNN_TERMINAL" = "wezterm" ] && [ -z "$NNN_PREVIEWIMGPROG" ]; then
+ wezterm imgcat "$3" &
+ elif exists ueberzug && { [ -z "$NNN_PREVIEWIMGPROG" ] || [ "$NNN_PREVIEWIMGPROG" = "ueberzug" ] ;}; then
+ ueberzug_layer "$1" "$2" "$3" && return
+ elif exists catimg && { [ -z "$NNN_PREVIEWIMGPROG" ] || [ "$NNN_PREVIEWIMGPROG" = "catimg" ] ;}; then
+ catimg "$3" &
+ elif exists viu && { [ -z "$NNN_PREVIEWIMGPROG" ] || [ "$NNN_PREVIEWIMGPROG" = "viu" ] ;}; then
+ viu -t "$3" &
+ elif exists chafa && { [ -z "$NNN_PREVIEWIMGPROG" ] || [ "$NNN_PREVIEWIMGPROG" = "chafa" ] ;}; then
+ chafa "$3" &
+ else
+ fifo_pager print_bin_info "$3" && return
+ fi
+ printf "%s" "$!" > "$PREVIEWPID"
+}
+
+ueberzug_layer() {
+ [ -f "$POSOFFSET" ] && read -r x y < "$POSOFFSET"
+ printf '{"action": "add", "identifier": "nnn_ueberzug", "x": %d, "y": %d, "width": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n'\
+ "${x:-0}" "${y:-0}" "$1" "$2" "$3" > "$FIFO_UEBERZUG"
+}
+
+ueberzug_remove() {
+ printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBERZUG"
+}
+
+winch_handler() {
+ clear
+ pidkill "$PREVIEWPID"
+ if [ -p "$FIFO_UEBERZUG" ]; then
+ pkill -f "tail --follow $FIFO_UEBERZUG"
+ tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
+ fi
+ preview_file "$(cat "$CURSEL")"
+}
+
+preview_fifo() {
+ while read -r selection; do
+ if [ -n "$selection" ]; then
+ pidkill "$PREVIEWPID"
+ [ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
+ [ "$selection" = "close" ] && break
+ preview_file "$selection"
+ printf "%s" "$selection" > "$CURSEL"
+ fi
+ done < "$NNN_FIFO"
+ sleep 0.1 # make sure potential preview by winch_handler is killed
+ pkill -P "$$"
+}
+
+if [ "$PREVIEW_MODE" -eq 1 ] 2>/dev/null; then
+ if [ "$NNN_TERMINAL" != "kitty" ] && exists ueberzug; then
+ mkfifo "$FIFO_UEBERZUG"
+ tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
+ fi
+
+ preview_file "$PWD/$1"
+ preview_fifo &
+ printf "%s" "$!" > "$FIFOPID"
+ printf "%s" "$PWD/$1" > "$CURSEL"
+ trap 'winch_handler; wait' WINCH
+ trap 'rm "$PREVIEWPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" "$POSOFFSET" 2>/dev/null' INT HUP EXIT
+ wait "$!" 2>/dev/null
+ exit 0
+else
+ if [ ! -r "$NNN_FIFO" ]; then
+ prompt "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')\nPlease read Usage in '$0'."
+ elif [ "$KITTY_WINDOW_ID" ] && [ -z "$TMUX" ] && [ -z "$KITTY_LISTEN_ON" ]; then
+ prompt "\$KITTY_LISTEN_ON not set!\nPlease read Usage in '$0'."
+ else
+ toggle_preview "$1" &
+ fi
+fi
diff --git a/install.conf.yaml b/install.conf.yaml
index 5828fcb..52e4d63 100644
--- a/install.conf.yaml
+++ b/install.conf.yaml
@@ -52,6 +52,7 @@
~/.config/mpv: files/.config/mpv
~/.config/yamllint: files/.config/yamllint
~/.config/lazygit: files/.config/lazygit
+ ~/.config/nnn: files/.config/nnn
- shell:
- [git submodule update --init --recursive, Installing submodules]