Skip to content

Commit

Permalink
feat(nu): add clipboard plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston committed Aug 2, 2024
1 parent aa827b2 commit 4f13391
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 41 deletions.
60 changes: 30 additions & 30 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 21 additions & 11 deletions home/apps/nu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@
let
nu_scripts = "${pkgs.nu_scripts}/share/nu_scripts";

shellAliases = lib.concatStringsSep "\n" (
lib.mapAttrsToList (k: v: "alias ${k} = ${v}") config.home.shellAliases
aliases = mkAliases (
(config.home.shellAliases or { })
// {
clipcopy = "clipboard copy";
clippaste = "clipboard paste";
}
);

mkAliases =
aliases: lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: "alias ${k} = ${v}") aliases);

mkCompletions =
completions:
lib.concatStringsSep "\n" (
builtins.map (
el:
let
name = el.name or el;
filename = el.filename or el;
in
"source ${nu_scripts}/custom-completions/${name}/${filename}-completions.nu"
el: "source ${nu_scripts}/custom-completions/${el.name or el}/${el.filename or el}-completions.nu"
) completions
);

completions = [
completions = mkCompletions [
"cargo"
"composer"
"gh"
Expand All @@ -46,6 +48,12 @@ let
}
];

mkPlugins =
plugins:
lib.concatStringsSep "\n" (builtins.map (plugin: "plugin add ${lib.getExe plugin}") plugins);

plugins = mkPlugins (with pkgs.nushellPlugins; [ clipboard ]);

command-not-found = pkgs.writeShellScript "command-not-found" ''
source ${config.programs.nix-index.package}/etc/profile.d/command-not-found.sh
command_not_found_handle "$@"
Expand All @@ -54,6 +62,7 @@ in
{
programs.carapace = {
enable = true;
# prefer my own completer
enableNushellIntegration = false;
};

Expand All @@ -74,8 +83,9 @@ in
source ${./nu/keybindings.nu}
''
+ lib.concatStringsSep "\n" [
shellAliases
(mkCompletions completions)
completions
plugins
aliases
];
};
}
34 changes: 34 additions & 0 deletions pkgs/nu_plugin_clipboard.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
darwin,
fetchFromGitHub,
rustPlatform,
lib,
stdenv,
}:
let
inherit (darwin.apple_sdk.frameworks) AppKit IOKit;
in
rustPlatform.buildRustPackage {
name = "nu_plugin_clipboard";
version = "0.96.0";

src = fetchFromGitHub {
owner = "FMotalleb";
repo = "nu_plugin_clipboard";
sha256 = "sha256-Uo9dd9D32Q1eBVPFG9dYBvsWvBcpuu6QuaVqs7bdZfM=";
rev = "494018928fb72e5b19c4eb83f0390645fc839651";
};

buildInputs = lib.optionals stdenv.isDarwin [
AppKit
IOKit
];

cargoHash = "sha256-wGKqQwPjBjrqJEmfe8L6Wz2tRYJsZ4PiY7AmRvxxABQ=";

meta = with lib; {
description = "A nushell plugin to copy text into clipboard or get text from it.";
license = licenses.mit;
mainProgram = "nu_plugin_clipboard";
};
}
3 changes: 3 additions & 0 deletions pkgs/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
in
{
inherit (inputs.swayfx.packages.${prev.system}) swayfx-unwrapped;
nushellPlugins = (prev.nushellPlugins or { }) // {
clipboard = prev.callPackage ./nu_plugin_clipboard.nix { };
};
starship = prev.starship.overrideAttrs (old: {
patches = [
(prev.fetchpatch {
Expand Down

0 comments on commit 4f13391

Please sign in to comment.