about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/kakoune
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/editors/kakoune')
-rw-r--r--nixpkgs/pkgs/applications/editors/kakoune/default.nix2
-rw-r--r--nixpkgs/pkgs/applications/editors/kakoune/plugins.nix5
-rw-r--r--nixpkgs/pkgs/applications/editors/kakoune/wrapper.nix44
-rw-r--r--nixpkgs/pkgs/applications/editors/kakoune/wrapper.sh30
4 files changed, 80 insertions, 1 deletions
diff --git a/nixpkgs/pkgs/applications/editors/kakoune/default.nix b/nixpkgs/pkgs/applications/editors/kakoune/default.nix
index 16596056c9a0..8dfcc4856680 100644
--- a/nixpkgs/pkgs/applications/editors/kakoune/default.nix
+++ b/nixpkgs/pkgs/applications/editors/kakoune/default.nix
@@ -3,7 +3,7 @@
 with stdenv.lib;
 
 stdenv.mkDerivation rec {
-  name = "kakoune-${version}";
+  pname = "kakoune-unwrapped";
   version = "2019.01.20";
   src = fetchFromGitHub {
     repo = "kakoune";
diff --git a/nixpkgs/pkgs/applications/editors/kakoune/plugins.nix b/nixpkgs/pkgs/applications/editors/kakoune/plugins.nix
new file mode 100644
index 000000000000..d2f3607d63cb
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/kakoune/plugins.nix
@@ -0,0 +1,5 @@
+{ parinfer-rust }:
+
+{
+  inherit parinfer-rust;
+}
diff --git a/nixpkgs/pkgs/applications/editors/kakoune/wrapper.nix b/nixpkgs/pkgs/applications/editors/kakoune/wrapper.nix
new file mode 100644
index 000000000000..b4cc823880e7
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/kakoune/wrapper.nix
@@ -0,0 +1,44 @@
+{ stdenv, bash }:
+with stdenv.lib;
+
+kakoune:
+
+let
+  getPlugins = { plugins ? [] }: plugins;
+
+  wrapper = { configure ? {} }:
+  stdenv.mkDerivation rec {
+    pname = "kakoune";
+    version = getVersion kakoune;
+
+    src = ./.;
+    buildCommand = ''
+      mkdir -p $out/share/kak
+      for plugin in ${strings.escapeShellArgs (getPlugins configure)}; do
+        if [[ -d $plugin/share/kak/autoload ]]; then
+          find "$plugin/share/kak/autoload" -type f -name '*.kak'| while read rcfile; do
+            printf 'source "%s"\n' "$rcfile"
+          done
+        fi
+      done >>$out/share/kak/plugins.kak
+
+      mkdir -p $out/bin
+      substitute ${src}/wrapper.sh $out/bin/kak \
+        --subst-var-by bash "${bash}" \
+        --subst-var-by kakoune "${kakoune}" \
+        --subst-var-by out "$out"
+      chmod +x $out/bin/kak
+    '';
+
+    preferLocalBuild = true;
+    buildInputs = [ bash kakoune ];
+    passthru = { unwrapped = kakoune; };
+
+    meta = kakoune.meta // {
+      # prefer wrapper over the package
+      priority = (kakoune.meta.priority or 0) - 1;
+      hydraPlatforms = [];
+    };
+  };
+in
+  makeOverridable wrapper
diff --git a/nixpkgs/pkgs/applications/editors/kakoune/wrapper.sh b/nixpkgs/pkgs/applications/editors/kakoune/wrapper.sh
new file mode 100644
index 000000000000..48a971a10c6e
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/kakoune/wrapper.sh
@@ -0,0 +1,30 @@
+#!@bash@/bin/bash
+
+# We use the -E option to load plugins.  This only makes sense when we are
+# starting a new session, so we detect that.  Also, Kakoune can only handle
+# one -E option, so we prepend loading plugins to an existing one.
+args=( "$@" )
+loadPlugins=true
+EValueOffset=-1
+pluginScript='@out@/share/kak/plugins.kak'
+
+for (( i = 0; i < ${#args[@]}; i++ )); do
+    case "${args[i]}" in
+        -n|-c|-l|-p|-clear|-version) loadPlugins=false;;
+        -E)                          EValueOffset=$(( i + 1 ));;
+        --)                          break;;
+    esac
+    case "${args[i]}" in
+        -E|-c|-e|-s|-p|-f|-i|-ui|-debug) i=$(( i + 1 ));;
+    esac
+done
+
+if [[ $loadPlugins = true ]]; then
+    if (( EValueOffset >= 0 )); then
+        args[EValueOffset]="source '$pluginScript'"$'\n'"${args[EValueOffset]}"
+    else
+        args=( "-E" "source '$pluginScript'" "${args[@]}" )
+    fi
+fi
+
+exec @kakoune@/bin/kak "${args[@]}"