Support OSX iterm2 in preview-tui by using split pane (#1196)

This commit is contained in:
An Phung 2021-10-14 21:07:11 +01:00 committed by GitHub
parent 3091a6f240
commit e20cfd67a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,6 +67,8 @@
# has to be set to `all` or `splits` (the former is the default value). # 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. # 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 # Shell: POSIX compliant
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal # Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
@ -96,6 +98,8 @@ start_preview() {
TERMINAL=tmux TERMINAL=tmux
elif [ -n "$KITTY_LISTEN_ON" ]; then elif [ -n "$KITTY_LISTEN_ON" ]; then
TERMINAL=kitty TERMINAL=kitty
elif [ -z "$TERMINAL" ] && [ "$TERM_PROGRAM" = "iTerm.app" ]; then
TERMINAL=iterm
else else
TERMINAL="${TERMINAL:-xterm}" TERMINAL="${TERMINAL:-xterm}"
fi fi
@ -130,6 +134,24 @@ start_preview() {
--env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" \ --env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" \
--env "BAT_THEME=$BAT_THEME" --env "FIFOPID=$FIFOPID" \ --env "BAT_THEME=$BAT_THEME" --env "FIFOPID=$FIFOPID" \
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;; --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 *) if [ -n "$2" ]; then
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" & QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
else else