This repository has no description
1.5 kB
65 lines
1{ pkgs, ... }: let
2
3 xdg-open = pkgs.writeBashBin "xdg-open" ''
4 set -xe
5 FILE="$1"
6 PATH=/run/current-system/sw/bin
7 mime=
8
9 case "$FILE" in
10 http://*|https://*)
11 mime=text/html
12 ;;
13 mailto:*)
14 mime=special/mailaddress
15 ;;
16 magnet:*)
17 mime=application/x-bittorrent
18 ;;
19 irc:*)
20 mime=x-scheme-handler/irc
21 ;;
22 *)
23 # it’s a file
24
25 # strip possible protocol
26 FILE=''${FILE#file://}
27 mime=''$(file -E --brief --mime-type "$FILE") \
28 || (echo "$mime" 1>&2; exit 1)
29 # ^ echo the error message of file
30 ;;
31 esac
32
33 case "$mime" in
34 special/mailaddress)
35 alacritty --execute vim "$FILE" ;;
36 text/html)
37 firefox-devedition "$FILE" ;;
38 text/xml)
39 firefox-devedition "$FILE" ;;
40 text/*)
41 alacritty --execute vim "$FILE" ;;
42 image/*)
43 sxiv "$FILE" ;;
44 application/x-bittorrent)
45 env DISPLAY=:0 transgui "$FILE" ;;
46 application/pdf)
47 zathura "$FILE" ;;
48 inode/directory)
49 alacritty --execute mc "$FILE" ;;
50 inode/symlink)
51 exec "$0" "$(realpath "$FILE")" ;;
52 audio/*)
53 mpv "$FILE" ;;
54 video/*)
55 mpv "$FILE" ;;
56 *)
57 echo $TERM >> /tmp/xdg.debug
58 # open dmenu and ask for program to open with
59 runner=$({ IFS=:; ls -H $PATH; } | sort | dmenu)
60 exec $runner "$FILE";;
61 esac
62 '';
63in {
64 environment.systemPackages = [ xdg-open ];
65}