From e20cfd67a1c3de635a1f562420bfe15e37296dd9 Mon Sep 17 00:00:00 2001 From: An Phung Date: Thu, 14 Oct 2021 21:07:11 +0100 Subject: [PATCH] Support OSX iterm2 in preview-tui by using split pane (#1196) --- plugins/preview-tui | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/preview-tui b/plugins/preview-tui index 2731476a..3116a889 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -67,6 +67,8 @@ # has to be set to `all` or `splits` (the former is the default value). # This terminal is also able to show images without extra dependencies. # +# Iterm2 users are recommended to use viu to view images without getting pixelated. +# # Shell: POSIX compliant # Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal @@ -96,6 +98,8 @@ start_preview() { TERMINAL=tmux elif [ -n "$KITTY_LISTEN_ON" ]; then TERMINAL=kitty + elif [ -z "$TERMINAL" ] && [ "$TERM_PROGRAM" = "iTerm.app" ]; then + TERMINAL=iterm else TERMINAL="${TERMINAL:-xterm}" fi @@ -130,6 +134,24 @@ start_preview() { --env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" \ --env "BAT_THEME=$BAT_THEME" --env "FIFOPID=$FIFOPID" \ --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;; + iterm) + command="$SHELL -c 'cd $PWD; \ + PATH=\\\"$PATH\\\" NNN_FIFO=\\\"$NNN_FIFO\\\" PREVIEW_MODE=1 PAGER=\\\"$PAGER\\\" \ + USE_SCOPE=\\\"$USE_SCOPE\\\" SPLIT=\\\"$SPLIT\\\" TERMINAL=\\\"$TERMINAL\\\" \ + PREVIEWPID=\\\"$PREVIEWPID\\\" CURSEL=\\\"$CURSEL\\\" TMPDIR=\\\"$TMPDIR\\\" \ + ICONLOOKUP=\\\"$ICONLOOKUP\\\" NNN_PREVIEWHEIGHT=\\\"$NNN_PREVIEWHEIGHT\\\" \ + NNN_PREVIEWWIDTH=\\\"$NNN_PREVIEWWIDTH\\\" NNN_PREVIEWDIR=\\\"$NNN_PREVIEWDIR\\\" \ + USE_PISTOL=\\\"$USE_PISTOL\\\" BAT_STYLE=\\\"$BAT_STYLE\\\" \ + BAT_THEME=\\\"$BAT_THEME\\\" FIFOPID=\\\"$FIFOPID\\\" \\\"$0\\\" \\\"$1\\\"'" + if [ "$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 + ;; *) if [ -n "$2" ]; then QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" & else