This repository has no description
1.4 kB
61 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 video/*)
51 mpv "$FILE" ;;
52 *)
53 echo $TERM >> /tmp/xdg.debug
54 # open dmenu and ask for program to open with
55 runner=$({ IFS=:; ls -H $PATH; } | sort | dmenu)
56 exec $runner "$FILE";;
57 esac
58 '';
59in {
60 environment.systemPackages = [ xdg-open ];
61}