Skip to content

Commit e424ad8

Browse files
authored
Merge pull request #545 from BJSummerfield/bjs/fish-plugins
Pass args to plugin shell functions
2 parents 6f2097e + fc45441 commit e424ad8

File tree

1 file changed

+51
-57
lines changed

1 file changed

+51
-57
lines changed

nix/shell-plugins.nix

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
{
2-
pkgs,
3-
lib,
4-
config,
5-
is-home-manager,
6-
...
7-
}:
1+
{ pkgs, lib, config, is-home-manager, ... }:
82
with lib;
93
let
104
cfg = config.programs._1password-shell-plugins;
@@ -50,13 +44,15 @@ in
5044
# for which the executable has a supported 1Password Shell Plugin
5145
apply =
5246
package_list:
53-
map (
54-
package:
55-
if (elem (getExeName package) supported_plugins) then
56-
package
57-
else
58-
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
59-
) package_list;
47+
map
48+
(
49+
package:
50+
if (elem (getExeName package) supported_plugins) then
51+
package
52+
else
53+
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
54+
)
55+
package_list;
6056
};
6157
};
6258
};
@@ -84,51 +80,49 @@ in
8480
# end
8581
# ```
8682
# where `{pkg}` is the executable name of the package
87-
posixFunctions = map (package: ''
88-
${package}() {
89-
op plugin run -- ${package};
90-
}
91-
'') pkg-exe-names;
92-
fishFunctions = map (package: ''
93-
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
94-
op plugin run -- ${package}
95-
end
96-
'') pkg-exe-names;
83+
posixFunctions = map
84+
(package: ''
85+
${package}() {
86+
op plugin run -- ${package} "$@";
87+
}
88+
'')
89+
pkg-exe-names;
90+
fishFunctions = map
91+
(package: ''
92+
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
93+
op plugin run -- ${package} $argv
94+
end
95+
'')
96+
pkg-exe-names;
9797
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
9898
in
9999
mkIf cfg.enable (mkMerge [
100-
(
101-
{
102-
# for Fish its the same option path between NixOS vs. home-manager
103-
fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
104-
}
105-
// optionalAttrs is-home-manager {
106-
programs = {
107-
# for the Bash and Zsh home-manager modules,
108-
# the initExtra option is equivalent to Fish's interactiveShellInit
109-
bash.initExtra = strings.concatStringsSep "\n" posixFunctions;
110-
zsh.initExtra = strings.concatStringsSep "\n" posixFunctions;
111-
};
112-
home = {
113-
inherit packages;
114-
sessionVariables = {
115-
OP_PLUGINS_SOURCED = "1";
116-
};
117-
};
118-
}
119-
// optionalAttrs (!is-home-manager) {
120-
programs = {
121-
bash.interactiveShellInit =
122-
strings.concatStringsSep "\n" posixFunctions;
123-
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
124-
};
125-
environment = {
126-
systemPackages = packages;
127-
variables = {
128-
OP_PLUGINS_SOURCED = "1";
129-
};
130-
};
131-
}
132-
)
100+
{
101+
programs.fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
102+
}
103+
(optionalAttrs is-home-manager {
104+
programs = {
105+
# for the Bash and Zsh home-manager modules,
106+
# the initExtra option is equivalent to Fish's interactiveShellInit
107+
bash.initExtra = strings.concatStringsSep "\n" posixFunctions;
108+
zsh.initExtra = strings.concatStringsSep "\n" posixFunctions;
109+
};
110+
home = {
111+
inherit packages;
112+
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
113+
};
114+
})
115+
(optionalAttrs (!is-home-manager) {
116+
programs = {
117+
bash.interactiveShellInit =
118+
strings.concatStringsSep "\n" posixFunctions;
119+
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
120+
};
121+
environment = {
122+
systemPackages = packages;
123+
variables = { OP_PLUGINS_SOURCED = "1"; };
124+
};
125+
})
133126
]);
134127
}
128+

0 commit comments

Comments
 (0)