-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## Tabry Nix Configurations | ||
|
||
### Home Manager Module | ||
|
||
This repository provides a home-manager (https://github.com/nix-community/home-manager) | ||
module to make tabry easy to install and use via home manager. | ||
|
||
To use the home-manager module via flakes, add this module to your home-manager | ||
configuration: | ||
|
||
```nix | ||
{ | ||
inputs = { | ||
tabry.url = "github:evanbattaglia/tabry-rs"; | ||
}; | ||
outputs = { ..., tabry }: { | ||
homeConfigurations.<user> = { | ||
modules = [ | ||
tabry.homeModules.tabry | ||
{ | ||
config.programs.tabry = { | ||
enable = true; | ||
enableBashIntegration = true; | ||
tabryFiles = [ | ||
./zellij.tabry | ||
]; | ||
}; | ||
} | ||
] | ||
} | ||
}; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
# This file contains a Home Manager module that installs tabry | ||
# and sets up tabry configuration files to be used by tabry | ||
# | ||
let | ||
|
||
cfg = config.programs.tabry; | ||
|
||
tabry = pkgs.callPackage ../default.nix {}; | ||
|
||
# converts /nix/store/.../foo.tabry to "foo" | ||
commandNameFromTabryFilename = fileName: | ||
(builtins.replaceStrings [".tabry"] [""] (builtins.baseNameOf fileName)); | ||
|
||
mkInitFish = fileName: let | ||
commandName = commandNameFromTabryFilename fileName; | ||
in '' | ||
tabry_completion_init ${commandName} | ||
''; | ||
|
||
tabryFileDir = pkgs.stdenv.mkDerivation { | ||
name = "tabry-files"; | ||
dontUnpack = true; | ||
phases = [ "installPhase" ]; | ||
installPhase = '' | ||
mkdir -p $out | ||
cp {${builtins.concatStringsSep "," cfg.tabryFiles}} $out | ||
''; | ||
}; | ||
|
||
in { | ||
|
||
options.programs.tabry = { | ||
enable = lib.mkEnableOption "tabry, a tab completion library"; | ||
enableFishIntegration = lib.mkEnableOption "enables fish completions"; | ||
enableBashIntegration = lib.mkEnableOption "enables bash completions"; | ||
tabryFiles = lib.mkOption { | ||
type = with lib.types; listOf path; | ||
default = []; | ||
description = '' | ||
*.tabry files to be compiled to completion json | ||
''; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
home.packages = [tabry]; | ||
|
||
# for each file, compile it to json | ||
# then add the dir to $TABRY_IMPORTS_PATH | ||
|
||
programs.fish.shellInit = lib.mkIf cfg.enableFishIntegration ( | ||
'' | ||
set -x TABRY_IMPORTS_PATH "${tabryFileDir}:$TABRY_IMPORTS_PATH" | ||
${tabry}/bin/tabry fish | source | ||
${builtins.concatStringsSep "\n" (map mkInitFish cfg.tabryFiles)} | ||
'' | ||
); | ||
|
||
programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration ( | ||
'' | ||
export TABRY_IMPORTS_PATH="${tabryFileDir}:$TABRY_IMPORTS_PATH" | ||
source <(${tabry}/bin/tabry bash) | ||
'' | ||
); | ||
}; | ||
} |