|
54 | 54 | pkg-exe-names = map getExeName cfg.plugins; |
55 | 55 | # Explanation: |
56 | 56 | # Map over `cfg.plugins` (the value of the `plugins` option provided by the user) |
57 | | - # and for each package specified, get the executable name, then create a shell alias |
| 57 | + # and for each package specified, get the executable name, then create a shell function |
58 | 58 | # of the form: |
59 | | - # `alias {pkg}="op plugin run -- {pkg}"` |
| 59 | + # |
| 60 | + # For Bash and Zsh: |
| 61 | + # ``` |
| 62 | + # {pkg}() { |
| 63 | + # op plugin run -- {pkg}; |
| 64 | + # } |
| 65 | + # ``` |
| 66 | + # |
| 67 | + # And for Fish: |
| 68 | + # ``` |
| 69 | + # function {pkg} --wraps {pkg} |
| 70 | + # op plugin run -- {pkg} |
| 71 | + # end |
| 72 | + # ``` |
60 | 73 | # where `{pkg}` is the executable name of the package |
61 | | - aliases = listToAttrs (map (package: { |
62 | | - name = package; |
63 | | - value = "op plugin run -- ${package}"; |
64 | | - }) pkg-exe-names); |
| 74 | + posixFunctions = map (package: '' |
| 75 | + ${package}() { |
| 76 | + op plugin run -- ${package}; |
| 77 | + } |
| 78 | + '') pkg-exe-names; |
| 79 | + fishFunctions = map (package: '' |
| 80 | + function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}" |
| 81 | + op plugin run -- ${package} |
| 82 | + end |
| 83 | + '') pkg-exe-names; |
65 | 84 | packages = [ pkgs._1password ] ++ cfg.plugins; |
66 | 85 | in mkIf cfg.enable (mkMerge [ |
67 | 86 | ({ |
| 87 | + # for Fish its the same option path between NixOS vs. home-manager |
| 88 | + fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions; |
| 89 | + } // optionalAttrs is-home-manager { |
68 | 90 | programs = { |
69 | | - bash.shellAliases = aliases; |
70 | | - zsh.shellAliases = aliases; |
71 | | - fish.shellAliases = aliases; |
| 91 | + # for the Bash and Zsh home-manager modules, |
| 92 | + # the initExtra option is equivalent to Fish's interactiveShellInit |
| 93 | + bash.initExtra = strings.concatStringsSep "\n" posixFunctions; |
| 94 | + zsh.initExtra = strings.concatStringsSep "\n" posixFunctions; |
72 | 95 | }; |
73 | | - } // optionalAttrs is-home-manager { |
74 | 96 | home = { |
75 | 97 | inherit packages; |
76 | 98 | sessionVariables = { OP_PLUGINS_SOURCED = "1"; }; |
77 | 99 | }; |
78 | 100 | } // optionalAttrs (!is-home-manager) { |
| 101 | + programs = { |
| 102 | + bash.interactiveShellInit = |
| 103 | + strings.concatStringsSep "\n" posixFunctions; |
| 104 | + zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions; |
| 105 | + }; |
79 | 106 | environment = { |
80 | 107 | systemPackages = packages; |
81 | 108 | variables = { OP_PLUGINS_SOURCED = "1"; }; |
|
0 commit comments