Remove url click implementation

This commit is contained in:
Nero 2023-03-30 12:04:49 +00:00
parent 7b9ab8a34a
commit 67faa30cda
4 changed files with 0 additions and 136 deletions

View File

@ -44,11 +44,3 @@ If xterm is not installed, rxvt-unicode is tried.
Sway can be started from the tty. Both `sway` and `foot` look into `~/.config` on their own.
Sway is using the same config as i3.
## xdg-open
This repo ships an own `xdg-open` overriding the system one.
It runs the `view` script in a new terminal window.
`view` itself contains complex logic to display the contents of the url to me, usually via feh, mpv or by chaining to firefox.
This includes displaying files of unknown type via hexdump, or showing text files via `less`.
It also degrades nicely in functionality when there is no Xorg or Wayland available, by resorting to command line programs.

124
bin/view
View File

@ -1,124 +0,0 @@
#!/bin/sh
# Syntax: view (url | path)
# Figure out how to display a file.
# also, downloaded files are cached, so i can view them again for two days
# without having to re-download them.
# usually this spawns a window that needs to be manually closed.
# create a temporary file to store contents in
cachefile() {
hash=$(printf "%s" "$1"|sed 's/^.*\/\///;s/[^a-zA-Z0-9\%\-\@\^\.]/_/g;s/__+/_/g')
name="${XDG_CACHE_HOME:-$HOME/.cache}"/urls/"$hash"
mkdir -p "${name%/*}"
printf "%s\n" "$name"
}
# long-running commands that require xorg
x11() {
test -n "$DISPLAY" || return
printf '%s\n' "$type"|grep -qiE "$1" || return
shift
command -v "$1" >/dev/null 2>&1 || return
setsid "$@" &
sleep 1
exit
}
# long-running commands that require wayland
way() {
test -n "$WAYLAND_DISPLAY" || return
printf '%s\n' "$type"|grep -qiE "$1" || return
shift
command -v "$1" >/dev/null 2>&1 || return
setsid "$@" &
sleep 1
exit
}
# long-running commands
cmd() {
printf '%s\n' "$type"|grep -qiE "$1" || return
shift
command -v "$1" >/dev/null 2>&1 || return
exec "$@"
}
# commands that dump presentation to stdout and exit
dmp() {
printf '%s\n' "$type"|grep -qiE "$1" || return
shift
command -v "$1" >/dev/null 2>&1 || return
(
printf "[%s]\n" "$type"
"$@"
) | less
exit 0
}
# delete older files so they dont pile up
find "${XDG_CACHE_HOME:-$HOME/.cache}"/urls -mtime +2 -delete 2>/dev/null
if test "$1" = "-" ; then
url=$(head -n 1)
else
url="$1"
fi
# some urls have special handling
case "$url" in
https://www.youtube.com/watch?v=*|https://youtu.be/*|https://hooktube*)
exec mpv --loop=inf "$url"
;;
file://*)
file="${url#file://}"
;;
/*)
file="$url"
url="file://$url"
;;
*://*|doi:*|isbn:*)
file=$(cachefile "$url")
if ! test -s "$file"; then
wget -O "${file}.$$" "$url" && mv "${file}.$$" "${file}" && touch "$file" || rm "${file}.$$"
fi
;;
*)
file="$PWD/$url"
url="file://$PWD/$url"
;;
esac
if ! test -s "$file" || ! test -f "$file"; then
echo "Failed to access file: ${url}" >&1
head -n 1
exit 1
fi
type=$(file -z -L -b "$file")
echo "$type"
# x11 = requires xorg
# way = requires wayland
# cmd = tui application
# dmp = displayed by converting to text, piped into less
# First match wins
x11 'PDF document' mupdf-gl -I "$file"
x11 'PDF document' mupdf -I "$file"
x11 'HTML document' qutebrowser "$url"
cmd 'HTML document' w3m -T text/html "$url"
cmd 'HTML document' lynx "$url"
dmp 'HTML document' sed -e 's/<[^>]*\(>\|$\)//g;/^\s*$/d' "$file"
cmd 'shell script' nano --view -Y sh "$file"
way 'image data' imv "$file"
way 'video|ISO Media|WebM|Matroska|GIF image data' mpv --loop-file=inf "$file"
x11 'video|ISO Media|WebM|Matroska|GIF image data' mpv --loop-file=inf "$file"
cmd 'audio|layer III' mpv --no-video --loop-file=inf "$file"
x11 'image data' feh --output-dir "$HOME" "$file"
cmd 'image data' cacaview "$file"
dmp 'tar archive' tar -tf "$file"
dmp 'PEM certificate request' openssl req -in "$file" -text -noout -verify
dmp 'PEM certificate' openssl x509 -in "$file" -text -noout
x11 'PEM certificate' gcr-viewer "$file"
dmp 'text' cat -v "$file"
dmp '.*' hexdump -Cv "$file"

View File

@ -1,3 +0,0 @@
#!/bin/sh
# this script overwrites the systems xdg-open by showing up earlier in PATH
x-terminal-emulator -e view "$1"

View File

@ -15,7 +15,6 @@ exec exec x-terminal-emulator
bindcode $mod+36 exec exec x-terminal-emulator
bindcode $mod+31 exit
bindcode $mod+46 exec --no-startup-id i3lock
bindcode $mod+30 exec --no-startup-id xdg-open "$(xclip -o)"
# compat keybinds
bindsym Mod1+F4 kill