From bdce2cfb10a204042a35cf574669cb46950e679f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Tue, 21 Dec 2021 01:52:47 +0300 Subject: Switch to nsxiv as main image viewer sxiv is no longer maintained. --- dotfiles/.config/mimeapps.list | 8 ++-- dotfiles/.config/nsxiv/exec/key-handler | 55 ++++++++++++++++++++++++ dotfiles/.config/sxiv/exec/key-handler | 55 ------------------------ dotfiles/.local/bin/nsxiv-rifle | 29 +++++++++++++ dotfiles/.local/share/applications/nsxiv.desktop | 8 ++++ 5 files changed, 96 insertions(+), 59 deletions(-) create mode 100755 dotfiles/.config/nsxiv/exec/key-handler delete mode 100755 dotfiles/.config/sxiv/exec/key-handler create mode 100755 dotfiles/.local/bin/nsxiv-rifle create mode 100644 dotfiles/.local/share/applications/nsxiv.desktop (limited to 'dotfiles') diff --git a/dotfiles/.config/mimeapps.list b/dotfiles/.config/mimeapps.list index 7f6d7d3..622cc74 100644 --- a/dotfiles/.config/mimeapps.list +++ b/dotfiles/.config/mimeapps.list @@ -8,10 +8,10 @@ audio/mpeg=mpv.desktop; audio/x-xm=mpv.desktop; audio/x-mod=mpv.desktop; audio/x-it=mpv.desktop; -image/gif=imv.desktop; -image/jpeg=sxiv.desktop; -image/png=sxiv.desktop; -image/webp=sxiv.desktop; +image/gif=nsxiv.desktop; +image/jpeg=nsxiv.desktop; +image/png=nsxiv.desktop; +image/webp=nsxiv.desktop; image/svg+xml=org.inkscape.Inkscape.desktop text/html=org.qutebrowser.qutebrowser.desktop; text/xml=nvim.desktop; diff --git a/dotfiles/.config/nsxiv/exec/key-handler b/dotfiles/.config/nsxiv/exec/key-handler new file mode 100755 index 0000000..f20a143 --- /dev/null +++ b/dotfiles/.config/nsxiv/exec/key-handler @@ -0,0 +1,55 @@ +#!/bin/sh + +rotate() { + degree="$1" + file="$2" + case "$(file -b -i "$file")" in + image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;; + *) mogrify -rotate "$degree" "$file" ;; + esac +} + +if [ "$1" = "t" ]; then + while read file; do + files="$(printf "%s\n%s" "$files" "$file")" + done + dragon-drag-and-drop -a $files + exit 0 +fi + +while read file; do + case "$1" in + "C-a" | "C-1") + setbg "$file" + exit ;; + "C-2") + setbg "$file" "2" + exit ;; + "C-s") + setbglblur "$file" + exit ;; + "C-d") + setbglsimple "$file" + exit ;; + "C-c") + wl-copy < "$file" + exit ;; + "C-f") + wl-copy "$file" + exit ;; + "C-r") + # Move file to 'trash' directory, if the current directory's name is + # JPEG, remove the NEF file as well + dir="$(dirname "$file")" + name="$(basename "$file")" + base="${name%.*}" + mv "$file" ~/.local/trash/ + if [ "JPEG" = "$(basename $dir)" ]; then + mv $(dirname "$dir")/"$base".NEF ~/.local/trash/ + fi + exit ;; + "C-comma") rotate 270 $file ;; + "C-period") rotate 90 $file ;; + "C-slash") rotate 180 $file ;; + esac +done diff --git a/dotfiles/.config/sxiv/exec/key-handler b/dotfiles/.config/sxiv/exec/key-handler deleted file mode 100755 index f20a143..0000000 --- a/dotfiles/.config/sxiv/exec/key-handler +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh - -rotate() { - degree="$1" - file="$2" - case "$(file -b -i "$file")" in - image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;; - *) mogrify -rotate "$degree" "$file" ;; - esac -} - -if [ "$1" = "t" ]; then - while read file; do - files="$(printf "%s\n%s" "$files" "$file")" - done - dragon-drag-and-drop -a $files - exit 0 -fi - -while read file; do - case "$1" in - "C-a" | "C-1") - setbg "$file" - exit ;; - "C-2") - setbg "$file" "2" - exit ;; - "C-s") - setbglblur "$file" - exit ;; - "C-d") - setbglsimple "$file" - exit ;; - "C-c") - wl-copy < "$file" - exit ;; - "C-f") - wl-copy "$file" - exit ;; - "C-r") - # Move file to 'trash' directory, if the current directory's name is - # JPEG, remove the NEF file as well - dir="$(dirname "$file")" - name="$(basename "$file")" - base="${name%.*}" - mv "$file" ~/.local/trash/ - if [ "JPEG" = "$(basename $dir)" ]; then - mv $(dirname "$dir")/"$base".NEF ~/.local/trash/ - fi - exit ;; - "C-comma") rotate 270 $file ;; - "C-period") rotate 90 $file ;; - "C-slash") rotate 180 $file ;; - esac -done diff --git a/dotfiles/.local/bin/nsxiv-rifle b/dotfiles/.local/bin/nsxiv-rifle new file mode 100755 index 0000000..95d6423 --- /dev/null +++ b/dotfiles/.local/bin/nsxiv-rifle @@ -0,0 +1,29 @@ +#!/bin/sh + +if [ $# -eq 0 ]; then + echo "Usage: ${0##*/} PICTURES" + exit +fi + +[ "$1" = '--' ] && shift + +abspath () { + case "$1" in + /*) printf "%s\n" "$1";; + *) printf "%s\n" "$PWD/$1";; + esac +} + +listfiles () { + find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ + '.*\(jpe?g\|bmp\|webp\|png\|gif\)$' -print0 | sort -z +} + +target="$(abspath "$1")" +count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" + +if [ -n "$count" ]; then + listfiles | xargs -0 nsxiv -a -n "$count" -- +else + nsxiv -a -- "$@" # fallback +fi diff --git a/dotfiles/.local/share/applications/nsxiv.desktop b/dotfiles/.local/share/applications/nsxiv.desktop new file mode 100644 index 0000000..adb015a --- /dev/null +++ b/dotfiles/.local/share/applications/nsxiv.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Application +Name=nsxiv +GenericName=Image Viewer +Exec=nsxiv-rifle %F +MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/png;image/tiff;image/x-bmp;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-tga;image/x-xpixmap;image/webp; +NoDisplay=true +Icon=nsxiv -- cgit v1.2.3