💾 Archived View for atyh.net › code-posix-opener.gmi captured on 2023-09-28 at 15:48:28. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-04-26)
-=-=-=-=-=-=-
__________ ______________ |:"""""""":: | ............ : |: |: | : | : |: |: | : | : |:________!: | : | : | ..... :---____-| :__________! : | '-----" : |..............: | @ :"-__-_ |"""""""""""""": |..........: _-" |..............: /.::::::::.\ /\ /.::::::::.:::.\ /____________\ (__) /________________\
The computing environments I prefer are minimal. Minimal window managers, and CLI oriented programs are my preference. This being the case, I am not a fan of xdg-open. This may be because I dont fully understand it, or because I feel it is overly complex. Whatever the reason, I prefer a plumber which is explicity defined, in a language I can understand.
The Noice terminal file manager relies on a separate opener for plumbing called 'nopen'. File types, and what those file types are opened with is explicitly defined. I find this appealing. The same kind of opener can be created using posix shell with a case statement:
case $1 in *.mp4|*.mkv|*.webm|*.mov|*.m3u) mpv "$1" ;; *.ogg|*.mp3|*.pls*|*.opus|*.aiff|*.aif|*.flac) mpv --no-video "$1" ;; *.png|*.gif|*.jpg|*.jpe|*.jpeg|*.webp) nsxiv "$1" ;; *.html|*.htm) w3m "$1" ;; *.pdf|*.epub|*.cbz|*.djvu) zathura "$1" ;; *.md) lowdown -Tterm "$1" | less ;; # all other files *) "${EDITOR:=vi}" "$1" ;; esac
I use this opener for almost everything now, and added it to my
system in the following ways:
In ~/bin/openr.sh
Added to my ~/.kshrc as:
openr(){ "the above case statement" }
map o $openr $f
cmd openr $/home/atyh/bin/openr.sh $f
OPENER=/home/atyh/bin/openr.sh
With the opener(plumber) defined in these 4 locations, I am able to
use it to great effect. The power in this lies in the ability to
define shell commands for specific file types. The *.md) section for
example takes advantage of lowdown(1)'s ability to format markdown
documents into terminal formated output. With this, in lf, I can
push 'o' and lf will open a README.md in a git repo in a nice color
formated and readable way in less(1).
This is really just scratching the surface with what can be done
with this plumbing method.