aboutsummaryrefslogtreecommitdiff
path: root/ranger
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ranger/.config/ranger/colorschemes/z3bratabs.py56
-rw-r--r--ranger/.config/ranger/rc.conf6
-rw-r--r--ranger/.config/ranger/scope.sh158
3 files changed, 189 insertions, 31 deletions
diff --git a/ranger/.config/ranger/colorschemes/z3bratabs.py b/ranger/.config/ranger/colorschemes/z3bratabs.py
index decff9c..7b0ed70 100644
--- a/ranger/.config/ranger/colorschemes/z3bratabs.py
+++ b/ranger/.config/ranger/colorschemes/z3bratabs.py
@@ -4,7 +4,7 @@ from ranger.gui.colorscheme import ColorScheme
from ranger.gui.color import *
class z3bratabs(ColorScheme):
- progress_bar_color = 8
+ progress_bar_color = 6
def use(self, context):
fg, bg, attr = default_colors
@@ -18,87 +18,85 @@ class z3bratabs(ColorScheme):
else:
attr = normal
if context.empty or context.error:
- fg = 7
- bg = 8
+ fg = 6
if context.border:
- fg = 7
+ fg = 6
if context.image:
- fg = 10
+ fg = 6
if context.video:
- fg = 4
+ fg = 6
if context.audio:
fg = 6
if context.document:
- fg = 8
- bg = 7
+ fg = 6
if context.container:
attr |= bold
- fg = 8
+ fg = 6
if context.directory:
attr |= bold
- fg = 7
+ fg = 6
elif context.executable and not \
any((context.media, context.container,
context.fifo, context.socket)):
attr |= bold
- fg = 4
+ fg = 6
if context.socket:
- fg = 3
+ fg = 6
attr |= bold
if context.fifo or context.device:
- fg = 10
+ fg = 6
if context.device:
attr |= bold
if context.link:
- fg = context.good and 7 or 8
- bg = 8
+ fg = context.good and 7 or 6
+ bg = 6
if context.bad:
fg = 1
if context.tag_marker and not context.selected:
attr |= bold
- if fg in (7, 8):
- fg = 8
+ if fg in (7, 6):
+ fg = 6
else:
fg = 1
if not context.selected and (context.cut or context.copied):
fg = 15
- bg = 8
+ bg = 6
if context.main_column:
if context.selected:
attr |= bold
if context.marked:
attr |= bold
- fg = 8
+ fg = 6
if context.badinfo:
if attr & reverse:
- bg = 1
+ bg = 6
else:
fg = 7
elif context.in_titlebar:
attr |= bold
if context.hostname:
- fg = context.bad and 8 or 7
- bg = 8
+ fg = context.bad and 6 or 7
+ bg = 6
elif context.directory:
- fg = 8
+ fg = 6
elif context.tab:
if context.good:
fg = 1
elif context.link:
- fg = 8
+ fg = 6
elif context.in_statusbar:
if context.permissions:
if context.good:
fg = 7
- bg = 8
+ bg = 6
elif context.bad:
- fg = 8
+ fg = 6
bg = 7
if context.marked:
attr |= bold | reverse
- fg = 8
+ fg = 6
if context.message:
if context.bad:
attr |= bold
@@ -119,7 +117,7 @@ class z3bratabs(ColorScheme):
if context.in_taskview:
if context.title:
- fg = 8
+ fg = 6
if context.selected:
attr |= reverse
@@ -159,4 +157,4 @@ class z3bratabs(ColorScheme):
elif context.vcsunknown:
fg = 11
- return fg, bg, attr \ No newline at end of file
+ return fg, bg, attr
diff --git a/ranger/.config/ranger/rc.conf b/ranger/.config/ranger/rc.conf
index 2d58fd0..96ad4cf 100644
--- a/ranger/.config/ranger/rc.conf
+++ b/ranger/.config/ranger/rc.conf
@@ -7,5 +7,7 @@
# ░░░ ░░░░░░░░ ░░░ ░░ ░░░░░ ░░░░░░ ░░░
set show_hidden true
set colorscheme z3bratabs
-set preview_images true
-set draw_borders true \ No newline at end of file
+set preview_images false
+set use_preview_script true
+set preview_script scope.sh
+set draw_borders true
diff --git a/ranger/.config/ranger/scope.sh b/ranger/.config/ranger/scope.sh
new file mode 100644
index 0000000..3c05050
--- /dev/null
+++ b/ranger/.config/ranger/scope.sh
@@ -0,0 +1,158 @@
+#!/usr/bin/env bash
+
+set -o noclobber -o noglob -o nounset -o pipefail
+IFS=$'\n'
+
+# If the option `use_preview_script` is set to `true`,
+# then this script will be called and its output will be displayed in ranger.
+# ANSI color codes are supported.
+# STDIN is disabled, so interactive scripts won't work properly
+
+# This script is considered a configuration file and must be updated manually.
+# It will be left untouched if you upgrade ranger.
+
+# Meanings of exit codes:
+# code | meaning | action of ranger
+# -----+------------+-------------------------------------------
+# 0 | success | Display stdout as preview
+# 1 | no preview | Display no preview at all
+# 2 | plain text | Display the plain content of the file
+# 3 | fix width | Don't reload when width changes
+# 4 | fix height | Don't reload when height changes
+# 5 | fix both | Don't ever reload
+# 6 | image | Display the image `$IMAGE_CACHE_PATH` points to as an image preview
+# 7 | image | Display the file directly as an image
+
+# Script arguments
+FILE_PATH="${1}" # Full path of the highlighted file
+PV_WIDTH="${2}" # Width of the preview pane (number of fitting characters)
+PV_HEIGHT="${3}" # Height of the preview pane (number of fitting characters)
+IMAGE_CACHE_PATH="${4}" # Full path that should be used to cache image preview
+PV_IMAGE_ENABLED="${5}" # 'True' if image previews are enabled, 'False' otherwise.
+
+FILE_EXTENSION="${FILE_PATH##*.}"
+FILE_EXTENSION_LOWER="${FILE_EXTENSION,,}"
+
+# Settings
+HIGHLIGHT_SIZE_MAX=262143 # 256KiB
+HIGHLIGHT_STYLE='pablo'
+PYGMENTIZE_STYLE='autumn'
+
+
+handle_extension() {
+ case "${FILE_EXTENSION_LOWER}" in
+ # Archive
+ a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
+ rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
+ atool --list -- "${FILE_PATH}" && exit 5
+ bsdtar --list --file "${FILE_PATH}" && exit 5
+ exit 1;;
+ rar)
+ # Avoid password prompt by providing empty password
+ unrar lt -p- -- "${FILE_PATH}" && exit 5
+ exit 1;;
+ 7z)
+ # Avoid password prompt by providing empty password
+ 7z l -p -- "${FILE_PATH}" && exit 5
+ exit 1;;
+
+ # PDF
+ pdf)
+ # Preview as text conversion
+ pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - && exit 5
+ exiftool "${FILE_PATH}" && exit 5
+ exit 1;;
+
+ # BitTorrent
+ torrent)
+ transmission-show -- "${FILE_PATH}" && exit 5
+ exit 1;;
+
+ # OpenDocument
+ odt|ods|odp|sxw)
+ # Preview as text conversion
+ odt2txt "${FILE_PATH}" && exit 5
+ exit 1;;
+
+ # HTML
+ htm|html|xhtml)
+ # Preview as text conversion
+ w3m -dump "${FILE_PATH}" && exit 5
+ lynx -dump -- "${FILE_PATH}" && exit 5
+ elinks -dump "${FILE_PATH}" && exit 5
+ ;; # Continue with next handler on failure
+ esac
+}
+
+handle_image() {
+ local mimetype="${1}"
+ case "${mimetype}" in
+ # SVG
+ # image/svg+xml)
+ # convert "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6
+ # exit 1;;
+
+ # Image
+ image/*)
+ # `w3mimgdisplay` will be called for all images (unless overriden as above),
+ # but might fail for unsupported types.
+ exit 7;;
+
+ # Video
+ # video/*)
+ # # Thumbnail
+ # ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
+ # exit 1;;
+ esac
+}
+
+handle_mime() {
+ local mimetype="${1}"
+ case "${mimetype}" in
+ # Text
+ text/* | */xml)
+ # Syntax highlight
+ if [[ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
+ exit 2
+ fi
+ if [[ "$( tput colors )" -ge 256 ]]; then
+ local pygmentize_format='terminal256'
+ local highlight_format='xterm256'
+ else
+ local pygmentize_format='terminal'
+ local highlight_format='ansi'
+ fi
+ highlight --out-format="${highlight_format}" --style="${HIGHLIGHT_STYLE}" -- "${FILE_PATH}" && exit 5
+ # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "${FILE_PATH}" && exit 5
+ exit 2;;
+
+ # Image
+ image/*)
+ # Preview as text conversion
+ # img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4
+ exiftool "${FILE_PATH}" && exit 5
+ exit 1;;
+
+ # Video and audio
+ video/* | audio/*)
+ mediainfo "${FILE_PATH}" && exit 5
+ exiftool "${FILE_PATH}" && exit 5
+ exit 1;;
+ esac
+}
+
+handle_fallback() {
+ echo '----- File Type Classification -----' && file --dereference --brief -- "${FILE_PATH}" && exit 5
+ exit 1
+}
+
+
+handle_extension
+MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )"
+if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then
+ handle_image "${MIMETYPE}"
+fi
+handle_mime "${MIMETYPE}"
+handle_fallback
+
+exit 1