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