aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/wrapper/sxiv
diff options
context:
space:
mode:
authordavidpkj <davidpenkow1@gmail.com>2023-08-27 16:36:12 +0200
committerdavidpkj <davidpenkow1@gmail.com>2023-08-27 16:36:12 +0200
commit8ec89f25e98c83bd348856f767ae2d193583d91a (patch)
treeef3fc77835de77bde0b74d8e6146932843ac8fa5 /scripts/.local/bin/personal/wrapper/sxiv
parentd6c6ff9997cc7d8b48a77dd8880d2cab3481d462 (diff)
Reorganize scripts
Diffstat (limited to 'scripts/.local/bin/personal/wrapper/sxiv')
-rwxr-xr-xscripts/.local/bin/personal/wrapper/sxiv112
1 files changed, 112 insertions, 0 deletions
diff --git a/scripts/.local/bin/personal/wrapper/sxiv b/scripts/.local/bin/personal/wrapper/sxiv
new file mode 100755
index 0000000..36d120c
--- /dev/null
+++ b/scripts/.local/bin/personal/wrapper/sxiv
@@ -0,0 +1,112 @@
+#!/bin/dash
+
+# nsxiv pipe
+#
+# tmpfile="${TMPDIR:-/tmp}/nsxiv_pipe_$$"
+# trap 'rm -f -- $tmpfile' EXIT
+#
+# if [ "$#" -eq 0 ]; then
+# if [ -t 0 ]; then
+# echo "nsxiv-pipe: No arguments provided" >&2; exit 1
+# else
+# # Consume stdin and put it in the temporal file
+# cat > "$tmpfile"
+# fi
+# fi
+#
+# for arg in "$@"; do
+# # if it's a pipe then drain it to $tmpfile
+# [ -p "$arg" ] && cat "$arg" > "$tmpfile"
+# done
+#
+# if [ -s "$tmpfile" ]; then
+# nsxiv -q "$@" "$tmpfile" # -q to silence warnings
+# else
+# nsxiv "$@" # fallback
+# fi
+
+# nsxiv rifle
+#
+# TMPDIR="${TMPDIR:-/tmp}"
+# tmp="$TMPDIR/nsxiv_rifle_$$"
+#
+# is_img_extension() {
+# grep -iE '\.(jpe?g|png|gif|svg|webp|tiff|heif|avif|ico|bmp)$'
+# }
+#
+# listfiles() {
+# find -L "$1" -maxdepth 1 -type f -print |
+# is_img_extension | sort | tee "$tmp"
+# }
+#
+# open_img() {
+# file="$1"; shift;
+# # only go through listfiles() if the file has a valid img extension
+# if echo "$file" | is_img_extension >/dev/null 2>&1; then
+# trap 'rm -f $tmp' EXIT
+# count="$(listfiles "///${file%/*}" | grep -nF "$file")"
+# fi
+# if [ -n "$count" ]; then
+# nsxiv -i -n "${count%%:*}" "$@" -- < "$tmp"
+# else
+# # fallback incase file didn't have a valid extension, or we couldn't
+# # find it inside the list
+# nsxiv "$@" -- "$file"
+# fi
+# }
+#
+# uri2path() {
+# python3 - "$@" <<'___HEREDOC'
+# from urllib.parse import unquote, urlparse
+# from sys import argv
+# for arg in argv[1:]:
+# print(unquote(urlparse(arg).path))
+# ___HEREDOC
+# }
+#
+# [ "$1" = '--' ] && shift
+# case "$1" in
+# "") echo "Usage: ${0##*/} PICTURES" >&2; exit 1 ;;
+# /*) open_img "$1" ;;
+# "~"/*) open_img "$HOME/${1#"~"/}" ;;
+# file:///*) open_img "$(uri2path "$1")" ;;
+# trash:///*)
+# trash_dir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash/files"
+# open_img "${trash_dir}$(uri2path "$1")" -N "nsxiv_trash"
+# ;;
+# *) open_img "$PWD/$1" ;;
+# esac
+
+# nsxiv url
+# cache_dir="${TMPDIR:-/tmp}/nsxiv"
+#
+# die() {
+# [ -n "$1" ] && printf '%s\n' "$*" >&2;
+# exit 1
+# }
+#
+# cleanup() {
+# rm -f -- "$cache_dir"/*
+# }
+#
+# get_image() (
+# cd "$cache_dir" && curl -sSLO "$1"
+# )
+#
+# ### main ###
+#
+# [ -z "$1" ] && die "No arguments given"
+# trap cleanup EXIT
+# [ -d "$cache_dir" ] || mkdir -p -- "$cache_dir" || die
+# while [ -n "$1" ]; do
+# case "$1" in
+# *://*.*) get_image "$1" ;;
+# *) echo "Invalid url: $1" >&2 ;;
+# esac
+# shift
+# done
+#
+# [ "$(find "$cache_dir" -type f -print | wc -l)" -ne 0 ] &&
+# nsxiv -p "$cache_dir"
+
+nsxiv