-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add nix hm module #5
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,65 @@ | ||
{ 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 {}; | ||
tabryLang = pkgs.callPackage ./tabry-lang.nix { inherit tabry; }; | ||
|
||
# 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} | ||
''; | ||
|
||
compileTabryFiles = map tabryLang.compileTabryFile; | ||
|
||
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 ( | ||
let | ||
tabryImportsPath = builtins.concatStringsSep ":" (compileTabryFiles cfg.tabryFiles); | ||
in { | ||
home.packages = [tabry]; | ||
|
||
# for each file, compile it to json | ||
# then add the dir to $TABRY_IMPORT_PATH | ||
|
||
programs.fish.shellInit = lib.mkIf cfg.enableFishIntegration ( | ||
'' | ||
set -x TABRY_IMPORT_PATH "${tabryImportsPath}:$TABRY_IMPORT_PATH" | ||
${tabry}/bin/tabry fish | source | ||
${builtins.concatStringsSep "\n" (map mkInitFish cfg.tabryFiles)} | ||
'' | ||
); | ||
|
||
programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration ( | ||
'' | ||
set -x TABRY_IMPORT_PATH "${tabryImportsPath}:$TABRY_IMPORT_PATH" | ||
source <(${tabry}/bin/tabry bash) | ||
'' | ||
); | ||
} | ||
); | ||
} |
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,27 @@ | ||
{ stdenv, tabry, ... }: | ||
let | ||
# converts /nix/store/.../foo.tabry to "foo" | ||
commandNameFromTabryFilename = filename: | ||
(builtins.replaceStrings [".tabry"] [""] (builtins.baseNameOf filename)); | ||
|
||
formatJsonFilename = tabryFilename: | ||
(commandNameFromTabryFilename tabryFilename) + ".json"; | ||
|
||
# This is a function that takes a .tabry file | ||
# and returns a derivation that compiles that | ||
# .tabry file into the tabry .json file | ||
compileTabryFile = inFile: stdenv.mkDerivation { | ||
name = "tabry-compile-file-${inFile}"; | ||
buildPhase = '' | ||
mkdir $out | ||
${tabry}/bin/tabry compile < ${inFile} > $out/${formatJsonFilename inFile} | ||
''; | ||
# by default, stdenv.mkDerivation will run `make install` | ||
# which we don't want to do here | ||
dontInstall = true; | ||
dontUnpack = true; | ||
}; | ||
|
||
in { | ||
inherit compileTabryFile commandNameFromTabryFilename; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably figure out a better example, as zellij actually does have its own shell completion... When I do, I'll change it here
One useful example I may make (especially when I get delegation working better) is you could have your own aliases
dc r
,dc e
, etc. -- one command with subcommands delegated to different commands -- and have shell completion for all the subcommands ... right now I don't actually know an easy way of doing that without tabry.