summaryrefslogtreecommitdiffstats
path: root/lass/2configs/xdg-open.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-04-17 22:04:03 +0200
committertv <tv@krebsco.de>2019-04-17 22:04:03 +0200
commitffd36f5554256f74beb6ade469666b00f72b22a9 (patch)
tree51e77c75388d9f9e032bdb09427bcaace2b846c7 /lass/2configs/xdg-open.nix
parente051fecf9c19d446d6588bd21070fd1a799b97a3 (diff)
parent1314eb9284697b46d8208c138cf2349816e15c5f (diff)
Merge remote-tracking branch 'gum/master'
Diffstat (limited to 'lass/2configs/xdg-open.nix')
-rw-r--r--lass/2configs/xdg-open.nix66
1 files changed, 66 insertions, 0 deletions
diff --git a/lass/2configs/xdg-open.nix b/lass/2configs/xdg-open.nix
new file mode 100644
index 00000000..824c36dc
--- /dev/null
+++ b/lass/2configs/xdg-open.nix
@@ -0,0 +1,66 @@
+{ config, pkgs, lib, ... }: with import <stockholm/lib>; let
+
+ xdg-open-wrapper = pkgs.writeDashBin "xdg-open" ''
+ /run/wrappers/bin/sudo -u lass ${xdg-open} "$@"
+ '';
+
+ xdg-open = pkgs.writeBash "xdg-open" ''
+ set -e
+ FILE="$1"
+ 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)
+ urxvtc --execute vim "$FILE" ;;
+ ${optionalString (hasAttr "browser" config.lass) ''
+ text/html)
+ ${config.lass.browser.select}/bin/browser-select "$FILE" ;;
+ text/xml)
+ ${config.lass.browser.select}/bin/browser-select "$FILE" ;;
+ ''}
+ text/*)
+ urxvtc --execute vim "$FILE" ;;
+ image/*)
+ sxiv "$FILE" ;;
+ application/x-bittorrent)
+ env DISPLAY=:0 transgui "$FILE" ;;
+ application/pdf)
+ zathura "$FILE" ;;
+ inode/directory)
+ sudo -u lass -i urxvtc --execute mc "$FILE" ;;
+ *)
+ # open dmenu and ask for program to open with
+ $(dmenu_path | dmenu) "$FILE";;
+ esac
+ '';
+in {
+ environment.systemPackages = [ xdg-open-wrapper ];
+
+ security.sudo.extraConfig = ''
+ cr ALL=(lass) NOPASSWD: ${xdg-open} *
+ '';
+}