From b2615b20c363dcfdfda9a009d2628da5e701a95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20=C3=87olako=C4=9Flu?= Date: Fri, 26 Mar 2021 00:27:41 +0300 Subject: [PATCH] Added lf as well, not as great as ranger but very useful when acccessing network drives --- install.sh | 1 + misc/lf/diricons | 234 ++++++++++++++++++++++++++++++++++ misc/lf/lfrc | 106 +++++++++++++++ misc/profile | 10 ++ scripts/lf-ueberzug | 17 +++ scripts/lf-ueberzug-cleaner | 8 ++ scripts/lf-ueberzug-previewer | 123 ++++++++++++++++++ zsh/aliases | 1 + zsh/cmds | 1 - zsh/zshrc | 3 + 10 files changed, 503 insertions(+), 1 deletion(-) create mode 100644 misc/lf/diricons create mode 100644 misc/lf/lfrc create mode 100755 scripts/lf-ueberzug create mode 100755 scripts/lf-ueberzug-cleaner create mode 100755 scripts/lf-ueberzug-previewer diff --git a/install.sh b/install.sh index 4bf67569..6dcb11ad 100755 --- a/install.sh +++ b/install.sh @@ -105,6 +105,7 @@ ln -s ~/.dotfiles/misc/termite/ ~/.config/termite ln -s ~/.dotfiles/misc/vdirsyncer ~/.vdirsyncer ln -s ~/.dotfiles/misc/systemd ~/.config/systemd ln -s ~/.dotfiles/misc/ranger ~/.config/ranger +ln -s ~/.dotfiles/misc/lf ~/.config/lf ln -s ~/.dotfiles/misc/neofetch ~/.config/neofetch ln -s ~/.dotfiles/misc/profile ~/.config/.profile ln -s ~/.dotfiles/misc/htop ~/.config/htop diff --git a/misc/lf/diricons b/misc/lf/diricons new file mode 100644 index 00000000..c5958a51 --- /dev/null +++ b/misc/lf/diricons @@ -0,0 +1,234 @@ +# -*- mode: conf-space -*- icon config file for [[https://github.com/gokcehan/lf/wiki/Icons][lf]] using mostly [[https://www.nerdfonts.com/cheat-sheet][nerdfonts]]. + +## Basic File Types +tw  +st  +ow  +dt  +di  +fi  +ln  +or  +ex  + +## Misc +.config  +webpack.config.*  + +## Full Matches +README  +LICENSE  +.DS_Store  +.Dockerfile  +CMakeLists.txt  +.gitlab-ci.yml  + +## Extension Associations +*.git  +*.edn  +*.pdf  +*.db  +*.hs  +*.vim  +*.org  +*.frm  +*.myd  +*.myi  +*.mkd  +*.ddf  +*.sqlite  +*.bib  +*.part  +*.torrent  +*.url  +*.link  +*.ass  +*.srt  +*.nfo  +*.psb  +*.psd  +*.xlsx  + +## Languages +*.c  +*.cpp  +*.cc  +*.h  +*.hh  +*.hpp  +*.css  +*.scss  +*.el  +*.clj  +*.py  +*.rb  +*.go  +*.html  +*.java  +*.md  +*.json  +*.sc  +*.scala  +*.php  +*.rs  +*.js  +*.ts  +*.kts  +*.gradle  +*.rss 參 + +## Shells and Command Interpreters +*.bash  +*.cmd  +*.fish  +*.ps1  +*.sh  +*.zsh  + +## Archives +*.7z  +*.ace  +*.alz  +*.arc  +*.arj  +*.bz2  +*.bz  +*.cab  +*.cpio  +*.deb  +*.dwm  +*.dz  +*.ear  +*.esd  +*.gz  +*.jar  +*.lha  +*.lrz  +*.lz4  +*.lz  +*.lzh  +*.lzma  +*.lzo  +*.rar  +*.rpm  +*.rz  +*.sar  +*.swm  +*.t7z  +*.tar  +*.taz  +*.tbz2  +*.tbz  +*.tgz  +*.tlz  +*.txz  +*.tz  +*.tzo  +*.tzst  +*.war  +*.wim  +*.xz  +*.z  +*.zip  +*.zoo  +*.zst  + +## Music +*.aac  +*.mp3  +*.alac  +*.flac  +*.m4a  +*.wav  +*.webm  +*.mka  +*.mid  +*.midi  + +## Video +*.avi  +*.m2v  +*.m4v  +*.mkv  +*.mov  +*.mp4  +*.mp4v  + +## Image +*.asf  +*.au  +*.bmp  +*.cgm  +*.dl  +*.emf  +*.flc  +*.fli  +*.flv  +*.gif  +*.gl  +*.jpeg  +*.jpg  +*.mjpeg  +*.mjpg  +*.mng  +*.mpc  +*.mpeg  +*.mpg  +*.nuv  +*.oga  +*.ogg  +*.ogm  +*.ogv  +*.ogx  +*.opus  +*.pbm  +*.pcx  +*.pgm  +*.png  +*.ppm  +*.qt  +*.ra  +*.rm  +*.rmvb  +*.spx  +*.svg  +*.svgz  +*.tga  +*.tif  +*.tiff  +*.vob  +*.wmv  +*.xbm  +*.xcf  +*.xpm  +*.xspf  +*.xwd  +*.yuv  + +## Directories +.git/  +.github/  +.config/  +node_modules/  +games/  +steam/  + +### Home Directories +# ~/downloads/  +~/media/videos/ ﳜ +~/media/images/  +~/media/music/  +~/.steam/  +~/.wine/  +~/.dotfiles/  +~/.mozilla/  +~/.tor-browser/  + +### XDG Stuff +# ~/user/  +# ~/prog/  +# ~/multi/  +# ~/OS/  + +# TODO +#  diff --git a/misc/lf/lfrc b/misc/lf/lfrc new file mode 100644 index 00000000..727b1942 --- /dev/null +++ b/misc/lf/lfrc @@ -0,0 +1,106 @@ +# interpreter for shell commands +set shell sh + +# set '-eu' options for shell commands +# These options are used to have safer shell commands. Option '-e' is used to +# exit on error and option '-u' is used to give error for unset variables. +# Option '-f' disables pathname expansion which can be useful when $f, $fs, and +# $fx variables contain names with '*' or '?' characters. However, this option +# is used selectively within individual commands as it can be limiting at +# times. +set shellopts '-eu' + +# set internal field separator (IFS) to "\n" for shell commands +# This is useful to automatically split file names in $fs and $fx properly +# since default file separator used in these variables (i.e. 'filesep' option) +# is newline. You need to consider the values of these options and create your +# commands accordingly. +set ifs "\n" + +# leave some space at the top and the bottom of the screen +set scrolloff 10 + +# use enter for shell commands +map shell + +# execute current file (must be executable) +map x $$f +map X !$f + +# dedicated keys for file opener actions +map o &mimeopen $f +map O $mimeopen --ask $f + +# define a custom 'open' command +# This command is called when current file is not a directory. You may want to +# use either file extensions and/or mime types here. Below uses an editor for +# text files and a file opener for the rest. +cmd open ${{ + case $(file --mime-type $f -b) in + text/*) $EDITOR $fx;; + *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;; + esac +}} + +# define a custom 'rename' command without prompt for overwrite +# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1 +# map r push :rename + +# make sure trash folder exists +# %mkdir -p ~/.trash + +# move current file or selected files to trash folder +# (also see 'man mv' for backup/overwrite options) +cmd trash %set -f; mv $fx ~/.trash + +# define a custom 'delete' command +# cmd delete ${{ +# set -f +# printf "$fx\n" +# printf "delete?[y/n]" +# read ans +# [ $ans = "y" ] && rm -rf $fx +# }} + +# use '' key for either 'trash' or 'delete' command +# map trash +# map delete + +# extract the current file with the right command +# (xkcd link: https://xkcd.com/1168/) + +set icons + +cmd extract ${{ + set -f + case $f in + *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;; + *.tar.gz|*.tgz) tar xzvf $f;; + *.tar.xz|*.txz) tar xJvf $f;; + *.zip) unzip $f;; + *.rar) unrar x $f;; + *.7z) 7z x $f;; + esac +}} + +# compress current file or selected files with tar and gunzip +cmd tar ${{ + set -f + mkdir $1 + cp -r $fx $1 + tar czf $1.tar.gz $1 + rm -rf $1 +}} + +# compress current file or selected files with zip +cmd zip ${{ + set -f + mkdir $1 + cp -r $fx $1 + zip -r $1.zip $1 + rm -rf $1 +}} + + +set previewer lf-ueberzug-previewer +set cleaner lf-ueberzug-cleaner diff --git a/misc/profile b/misc/profile index 959b45c4..3fb4ee68 100755 --- a/misc/profile +++ b/misc/profile @@ -23,3 +23,13 @@ export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$FLUTTER_HOME/bin:$PATH export PATH="/home/yigit/.scripts:/home/yigit/.local/bin:/home/yigit/.gem/ruby/2.7.0/bin:$GOPATH/bin:$GOPATH/binexport:/home/yigit/.local/bin:$PATH" export CPATH=/usr/include/opencv4 + +# LF Icons +LF_ICONS=$(sed ~/.config/lf/diricons \ + -e '/^[ \t]*#/d' \ + -e '/^[ \t]*$/d' \ + -e 's/[ \t]\+/=/g' \ + -e 's/$/ /') +LF_ICONS=${LF_ICONS//$'\n'/:} + +export LF_ICONS diff --git a/scripts/lf-ueberzug b/scripts/lf-ueberzug new file mode 100755 index 00000000..950aabb3 --- /dev/null +++ b/scripts/lf-ueberzug @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +# TODO: Remove LF_UebERZUG_FIFO and use LF_UEBERZUG_TEMPDIR/fifo + +cleanup() { + rm -r "$LF_UEBERZUG_TEMPDIR" 2>/dev/null + kill $ueberzugpid 2>/dev/null +} + +export LF_UEBERZUG_TEMPDIR="$(mktemp -d -t lf-ueberzug-XXXXXX)" +trap cleanup INT + +export LF_UEBERZUG_FIFO="$LF_UEBERZUG_TEMPDIR/fifo" +mkfifo "$LF_UEBERZUG_FIFO" +tail -f "$LF_UEBERZUG_FIFO" | ueberzug layer --silent & +ueberzugpid=$! +lf $@ +cleanup diff --git a/scripts/lf-ueberzug-cleaner b/scripts/lf-ueberzug-cleaner new file mode 100755 index 00000000..1492dc07 --- /dev/null +++ b/scripts/lf-ueberzug-cleaner @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +cat < "$LF_UEBERZUG_FIFO" +{ +"action": "remove", +"identifier": "lf-preview" +} +EOF diff --git a/scripts/lf-ueberzug-previewer b/scripts/lf-ueberzug-previewer new file mode 100755 index 00000000..706f7635 --- /dev/null +++ b/scripts/lf-ueberzug-previewer @@ -0,0 +1,123 @@ +#!/usr/bin/env sh + +preview() { + cat <<-EOF | paste -sd '' >"$LF_UEBERZUG_FIFO" + { + "action": "add", "identifier": "lf-preview", + "path": "$1", "x": $4, "y": $5, "width": $2, "height": $3, + "scaler": "contain" + } + EOF +} + +set -C -f -u +IFS=$'\n' + +lf-ueberzug-cleaner # clean active preview + +file="$1"; shift + +# Settings +HIGHLIGHT_SIZE_MAX=262143 # 256KiB +HIGHLIGHT_TABWIDTH=8 +HIGHLIGHT_STYLE='base16/oceanicnext' +PYGMENTIZE_STYLE='autumn' + +case "$(basename "$file" | tr '[A-Z]' '[a-z]')" 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|*.t*.Z|*.tzo|*.war|*.xpi|*.xz|*.Z|*.zip) + atool --list -- "$file" + bsdtar --list --file "$file" + exit 1;; + *.rar) + # Avoid password prompt by providing empty password + unrar lt -p- -- "$file" + exit 1;; + *.7z) + # Avoid password prompt by providing empty password + 7z l -p -- "$file" + exit 1;; + + # BitTorrent + *.torrent) + transmission-show -- "$file" + exit 1;; + + # OpenDocument + *.odt|*.ods|*.odp|*.sxw) + # Preview as text conversion + odt2txt "$file" + exit 1;; + + # HTML + *.htm|*.html|*.xhtml) + # Preview as text conversion + w3m -dump "$file" + lynx -dump -- "$file" + elinks -dump "$file" + exit 1;; # Continue with next handler on failure + *.avi|*.mp4|*.mkv) + thumbnail="$LF_UEBERZUG_TEMPDIR/thumbnail.png" + ffmpeg -y -i "$file" -vframes 1 "$thumbnail" + preview "$thumbnail" "$@" + exit 127;; + *.pdf) + thumbnail="$LF_UEBERZUG_TEMPDIR/thumbnail.png" + gs -o "$thumbnail" -sDEVICE=pngalpha -dLastPage=1 "$file" >/dev/null + preview "$thumbnail" "$@" + exit 127;; + *.jpg|*.jpeg|*.png|*.bmp) + preview "$file" "$@" + exit 127;; + *.svg) + thumbnail="$LF_UEBERZUG_TEMPDIR/thumbnail.png" + convert "$file" "$thumbnail" + preview "$thumbnail" "$@" + exit 127;; +esac + +MIMETYPE="$( file --dereference --brief --mime-type -- "$file" )" + +case "$MIMETYPE" in + # Text + + text/plain) + cat "$file" + exit 127;; + + text/* | */xml) + # Syntax highlight + if [ "$( stat --printf='%s' -- "$file" )" -gt "$HIGHLIGHT_SIZE_MAX" ]; then + notify-send 123 123123 + exit 2 + fi + if [ "$( tput colors )" -ge 256 ]; then + pygmentize_format='terminal256' + highlight_format='xterm256' + else + pygmentize_format='terminal' + highlight_format='ansi' + fi + highlight --replace-tabs="$HIGHLIGHT_TABWIDTH" --out-format="$highlight_format" --style="$HIGHLIGHT_STYLE" --force -- "$file" + # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "$file" + exit 127;; + + # Image + image/*) + # Preview as text conversion + # img2txt --gamma=0.6 -- "$file" && exit 1 + exiftool "$file" + exit 1;; + + # Video and audio + video/* | audio/*|application/octet-stream) + mediainfo "$file" + exiftool "$file" + exit 1;; +esac + +echo '----- File Type Classification -----' && file --dereference --brief -- "$file" +exit 1 + + diff --git a/zsh/aliases b/zsh/aliases index 82454b41..6864995a 100755 --- a/zsh/aliases +++ b/zsh/aliases @@ -14,6 +14,7 @@ alias tat="TERM=screen-256color-bce tmux a -t " alias yain="yay -Syu " alias ls="ls --color" alias yay="yay --sudoloop" +alias lf=lf-ueberzug # Suffix aliases alias -g G=" | rg" diff --git a/zsh/cmds b/zsh/cmds index a65a0dab..da96de45 100644 --- a/zsh/cmds +++ b/zsh/cmds @@ -116,4 +116,3 @@ tmate-unpair() { echo "Session already killed" fi } - diff --git a/zsh/zshrc b/zsh/zshrc index 3fbb3f56..9048f256 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -81,9 +81,11 @@ zstyle ':completion:*' matcher-list '' \ 'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \ 'r:|?=** m:{a-z\-}={A-Z\_}' + local copy_widgets=( vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line ) + local paste_widgets=( vi-put-{before,after} ) @@ -91,3 +93,4 @@ local paste_widgets=( # Use X11 Clipboard x11-clip-wrap-widgets copy $copy_widgets x11-clip-wrap-widgets paste $paste_widgets +