diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index c3c5ce8..9a94424 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -8,6 +8,7 @@ in { ./package-sets.nix ./nixpak-tricks.nix ./hidden-apps.nix + ./helix-desktop.nix ]; services.xserver = { diff --git a/modules/desktop/helix-desktop.nix b/modules/desktop/helix-desktop.nix new file mode 100644 index 0000000..95d485e --- /dev/null +++ b/modules/desktop/helix-desktop.nix @@ -0,0 +1,58 @@ +{ pkgs, ... }: + +let + helixDesktop = pkgs.makeDesktopItem { + name = "net.privatevoid.HelixDesktop"; + desktopName = "Helix"; + comment = "Helix Editor"; + mimeTypes = [ + "text/plain" + "application/x-zerosize" + "inode/directory" + ]; + inherit icon; + tryExec = "hx"; + exec = ''${hxOpenHandler} %F''; + }; + + icon = pkgs.fetchurl { + name = "helix-logo.svg"; + url = "https://raw.githubusercontent.com/helix-editor/helix/d1a4bd876b3ae646693c0905d7f29b636e2e5033/logo.svg"; + sha256 = "sha256-1XBrlGbCfkfYhIZuQ9eDBgDoohup/gQ9VZynEerUqcY="; + }; + + hxOpenHandler = pkgs.writeShellScript "hx-open-handler" '' + isDir () { test -d "$1"; } + isFile () { test -f "$1"; } + findAnyDir () { + for f in "$@"; do + if test -d "$f"; then + echo "$f" + return 0 + fi + done + return 1 + } + if [[ "$#" == 0 ]]; then + exec blackbox -w "$HOME" -c hx + elif [[ "$#" == 1 ]]; then + isDir "$1" && exec blackbox -w "$1" -c "hx ." + isFile "$1" && exec blackbox -w "$(dirname "$1")" -c "hx '$1'" + else + firstDir="$(findAnyDir "$@")" + findAnyDirStatus="$?" + if [[ "$findAnyDirStatus" == 0 ]]; then + exec blackbox -w "$firstDir" -c "hx ." + else + # magic: find common base directory + workDir="$(dirname "$@" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D')" + args=("$@") + exec blackbox -w "$workDir" -c "hx ''${args[*]@Q}" + fi + fi + ''; +in + +{ + environment.systemPackages = [ helixDesktop ]; +}