58 lines
1.5 KiB
Nix
58 lines
1.5 KiB
Nix
{ 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 ];
|
|
}
|