From 4b264db47135ce951547b24b770ce596b7b5585c Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sat, 3 Jun 2023 12:44:31 +0200 Subject: [PATCH] zsh: zsh-tab goodness --- .lessfilter | 46 ++++++++++++++++++++++++++++++++++++++++++++++ .zshrc | 9 +++++++++ 2 files changed, 55 insertions(+) create mode 100755 .lessfilter diff --git a/.lessfilter b/.lessfilter new file mode 100755 index 0000000..43d2942 --- /dev/null +++ b/.lessfilter @@ -0,0 +1,46 @@ +#! /usr/bin/env bash +mime=$(file -Lbs --mime-type "$1") +category=${mime%%/*} +kind=${mime##*/} +ext=${1##*.} +if [ "$kind" = json ]; then + if [ "$(command -v jq)" ]; then + jq -Cr . "$1" + fi +elif [ "$kind" = vnd.sqlite3 ]; then + if [ "$(command -v yes)" ] && [ "$(command -v sqlite3)" ] && [ "$(command -v bat)" ]; then + yes .q | sqlite3 "$1" | bat --color=always -plsql + fi +# https://github.com/wofr06/lesspipe/pull/107 +elif [ -d "$1" ]; then + if [ "$(command -v exa)" ]; then + exa --git -hl --color=always --icons "$1" + fi +# https://github.com/wofr06/lesspipe/pull/110 +elif [ "$kind" = pdf ]; then + if [ "$(command -v pdftotext)" ] && [ "$(command -v sed)" ]; then + pdftotext -q "$1" - | sed "s/\f/$(hr ─)\n/g" + fi +# https://github.com/wofr06/lesspipe/pull/115 +elif [ "$kind" = rfc822 ]; then + if [ "$(command -v bat)" ]; then + bat --color=always -lEmail "$1" + fi +# https://github.com/wofr06/lesspipe/pull/106 +elif [ "$category" = image ]; then + if [ "$(command -v chafa)" ]; then + chafa -f symbols "$1" + fi + if [ "$(command -v exiftool)" ]; then + exiftool "$1" | bat --color=always -plyaml + fi +# https://github.com/wofr06/lesspipe/pull/117 +elif [ "$category" = text ]; then + if [ "$(command -v bat)" ]; then + bat --color=always "$1" + elif [ "$(command -v pygmentize)" ]; then + pygmentize "$1" | less + fi +else + exit 1 +fi diff --git a/.zshrc b/.zshrc index 813d841..fde0e43 100644 --- a/.zshrc +++ b/.zshrc @@ -19,7 +19,14 @@ zi load zsh-users/zsh-history-substring-search zi ice wait lucid zi load Aloxaf/fzf-tab zi ice wait lucid +zi load Freed-Wu/fzf-tab-source +zi ice wait lucid +## fzf-tab +zstyle ':fzf-tab:*' fzf-bindings 'tab:accept' +zstyle ':fzf-tab:*' continuous-trigger '/' +zstyle ':fzf-tab:*' fzf-min-height 30 + ## History HISTSIZE=50000 SAVEHIST=50000 @@ -106,6 +113,8 @@ export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) ## Pager export LESS="--mouse --wheel-lines=1 -nRXF" +export LESSCOLORIZER="bat" +export LESSOPEN="|lesspipe.sh %s" export PAGER="bat" export BAT_PAGER="less -r"