diff options
author | Profpatsch <mail@profpatsch.de> | 2020-05-09 21:12:03 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2020-05-09 21:13:09 +0200 |
commit | 0adf4290a0eaab8b907d34f66c4831c3493b25fb (patch) | |
tree | b8987cbc41f64fb8be3fbecd8a40f73161250f31 /pkgs/profpatsch/xdg-open/xdg-open.dhall | |
parent | b4248f32786039908c2268b8608b46935fc6c31e (diff) |
pkgs/profpatsch: add xdg-open, WIP
Diffstat (limited to 'pkgs/profpatsch/xdg-open/xdg-open.dhall')
-rw-r--r-- | pkgs/profpatsch/xdg-open/xdg-open.dhall | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/pkgs/profpatsch/xdg-open/xdg-open.dhall b/pkgs/profpatsch/xdg-open/xdg-open.dhall new file mode 100644 index 00000000..cbd9654e --- /dev/null +++ b/pkgs/profpatsch/xdg-open/xdg-open.dhall @@ -0,0 +1,92 @@ +let Text/concatSep = ./imports/Prelude/Text/concatSep + +let Text/concatMap = ./imports/Prelude/Text/concatMap + +let List/concatMap = ./imports/Prelude/List/concatMap + +let List/map = ./imports/Prelude/List/map + +let + -- TODO use library like with shell commands + Executable = + Text + +let config = ./config.dhall + +let foo = + { match = [ "image", "png" ] + , cmd = λ(_ : Text) → { exe = "echo", args = [ "foo" ] } + } + +let renderMime = Text/concatSep "/" + +let shellEscapeCommand = + λ(shellEscape : Text → Text) + → λ(file : Text) + → λ(cmd : config.Command) + → Text/concatSep + " " + ( [ shellEscape cmd.exe ] + # List/map + config.Arg + Text + ( λ(arg : config.Arg) + → merge + { String = λ(t : Text) → shellEscape t + , Variable = λ(t : Text) → t + } + arg + ) + (cmd.args file) + ) + : Text + +let repeatText = + λ(t : Text) + → λ(n : Natural) + → Natural/fold n Text (λ(t2 : Text) → t ++ t2) "" + +let Lines = { indent : Natural, lines : List Text } + +let prettyLines = + λ(lines : Lines) + → Text/concatMap + Text + (λ(line : Text) → repeatText " " lines.indent ++ line ++ "\n") + lines.lines + +let xdg-open = + let case = + λ(shellEscape2 : Text → Text) + → λ(file2 : Text) + → λ(m : config.MimeMatch) + → [ "${renderMime m.match})" + , "${shellEscapeCommand shellEscape2 file2 m.cmd}" + , ";;" + ] + + in λ(bins : { get-mime-type : Executable }) + → λ(write-dash : Text → Text → Executable) + → λ(shellEscape : Text → Text) + → λ(pkgs : { package : Text, binary : Text } → Executable) + → λ(special : config.Special) + → write-dash + "xdg-open" + '' + file="$1" + mime=$(${bins.get-mime-type} "$file") + + case "$mime" in + ${prettyLines + { indent = 2 + , lines = + List/concatMap + config.MimeMatch + Text + (case shellEscape "\"\$file\"") + (config.mimeMatcher pkgs special) + }} + esac + '' + +in xdg-open |