2019-04-17 18:12:01 +00:00
|
|
|
|
{ config, pkgs, lib, ... }: with import <stockholm/lib>; let
|
|
|
|
|
|
|
|
|
|
xdg-open-wrapper = pkgs.writeDashBin "xdg-open" ''
|
2023-02-21 06:35:27 +00:00
|
|
|
|
exec ${xdg-open}/bin/xdg-open "$@" >> /tmp/xdg-debug.log 2>&1
|
2019-04-17 18:12:01 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2023-02-21 06:35:27 +00:00
|
|
|
|
xdg-open = pkgs.writeBashBin "xdg-open" ''
|
|
|
|
|
set -xe
|
2019-04-17 18:12:01 +00:00
|
|
|
|
FILE="$1"
|
2023-02-21 06:35:27 +00:00
|
|
|
|
PATH=/run/current-system/sw/bin
|
2019-04-17 18:12:01 +00:00
|
|
|
|
mime=
|
|
|
|
|
|
|
|
|
|
case "$FILE" in
|
|
|
|
|
http://*|https://*)
|
|
|
|
|
mime=text/html
|
|
|
|
|
;;
|
|
|
|
|
mailto:*)
|
|
|
|
|
mime=special/mailaddress
|
|
|
|
|
;;
|
|
|
|
|
magnet:*)
|
|
|
|
|
mime=application/x-bittorrent
|
|
|
|
|
;;
|
|
|
|
|
irc:*)
|
|
|
|
|
mime=x-scheme-handler/irc
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
# it’s a file
|
|
|
|
|
|
|
|
|
|
# strip possible protocol
|
|
|
|
|
FILE=''${FILE#file://}
|
|
|
|
|
mime=''$(file -E --brief --mime-type "$FILE") \
|
|
|
|
|
|| (echo "$mime" 1>&2; exit 1)
|
|
|
|
|
# ^ echo the error message of file
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
case "$mime" in
|
|
|
|
|
special/mailaddress)
|
2023-02-21 06:35:27 +00:00
|
|
|
|
alacritty --execute vim "$FILE" ;;
|
2019-04-17 18:12:01 +00:00
|
|
|
|
text/html)
|
2023-02-21 06:35:27 +00:00
|
|
|
|
firefox "$FILE" ;;
|
2019-04-17 18:12:01 +00:00
|
|
|
|
text/xml)
|
2023-02-21 06:35:27 +00:00
|
|
|
|
firefox "$FILE" ;;
|
2019-04-17 18:12:01 +00:00
|
|
|
|
text/*)
|
2023-02-21 06:35:27 +00:00
|
|
|
|
alacritty --execute vim "$FILE" ;;
|
2019-04-17 18:12:01 +00:00
|
|
|
|
image/*)
|
|
|
|
|
sxiv "$FILE" ;;
|
|
|
|
|
application/x-bittorrent)
|
|
|
|
|
env DISPLAY=:0 transgui "$FILE" ;;
|
|
|
|
|
application/pdf)
|
|
|
|
|
zathura "$FILE" ;;
|
|
|
|
|
inode/directory)
|
2023-02-21 06:35:27 +00:00
|
|
|
|
alacritty --execute mc "$FILE" ;;
|
2019-04-17 18:12:01 +00:00
|
|
|
|
*)
|
|
|
|
|
# open dmenu and ask for program to open with
|
2023-02-21 06:35:27 +00:00
|
|
|
|
runner=$(print -rC1 -- ''${(ko)commands} | dmenu)
|
|
|
|
|
exec $runner "$FILE";;
|
2019-04-17 18:12:01 +00:00
|
|
|
|
esac
|
|
|
|
|
'';
|
|
|
|
|
in {
|
|
|
|
|
environment.systemPackages = [ xdg-open-wrapper ];
|
|
|
|
|
|
|
|
|
|
security.sudo.extraConfig = ''
|
2023-02-21 06:35:27 +00:00
|
|
|
|
cr ALL=(lass) NOPASSWD: ${xdg-open}/bin/xdg-open *
|
|
|
|
|
ff ALL=(lass) NOPASSWD: ${xdg-open}/bin/xdg-open *
|
2019-04-17 18:12:01 +00:00
|
|
|
|
'';
|
|
|
|
|
}
|