Skip to content
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

Nix bash completion, better zsh completion support #100

Merged
merged 6 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ Set up Bash completion by adding the following to your Bash resource file or pro
eval "$(harmony --bash-completion-script)"
```

You can set up tab completion in Zsh, too:
### Zsh completion
Zsh completion is supported via `bashcompinit` and can be loaded by adding the following to your Zsh resource file or profile:
```shell
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
eval "$(harmony --bash-completion-script)"
eval "$(harmony --zsh-completion-script)"
```

## Usage
Expand Down
24 changes: 22 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{ stdenv, lib, callPackage, fetchFromGitHub, idris2, git, makeWrapper, nodejs }:
{ callPackage
, fetchFromGitHub
, git
, idris2
, lib
, installShellFiles
, makeWrapper
, nodejs
, stdenv
}:
let
nodeDependencies = (callPackage ./node2nix.nix { inherit nodejs; }).nodeDependencies;
idrisAddsVersion = "0.3.0";
Expand Down Expand Up @@ -34,7 +43,7 @@ stdenv.mkDerivation (finalAttrs: {
pname = "harmony";
version = "3.0.0";

nativeBuildInputs = [ idris2 makeWrapper ];
nativeBuildInputs = [ idris2 installShellFiles makeWrapper ];
buildInputs = [ nodejs git ];

src = ./.;
Expand Down Expand Up @@ -65,7 +74,18 @@ stdenv.mkDerivation (finalAttrs: {
--prefix PATH : ${lib.makeBinPath [ nodeDependencies git "$out" ]} \
--prefix NODE_PATH : ${nodeDependencies}/lib/node_modules

installShellCompletion --cmd harmony \
--bash <($out/bin/harmony --bash-completion-script) \
--zsh <($out/bin/harmony --zsh-completion-script) \

runHook postInstall
'';

meta = with lib; {
description = "Harmony GitHub collaboration tool";
homepage = "https://github.com/mattpolzin/harmony";
license = licenses.mit;
mainProgram = "harmony";
};

})
10 changes: 5 additions & 5 deletions harmony.ipkg
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package harmony
version = 3.0.0
authors = "Mathew Polzin"
license = "MIT"
-- brief =
-- readme =
-- homepage =
-- sourceloc =
-- bugtracker =
brief = "Harmony GitHub collaboration tool"
readme = "https://github.com/mattpolzin/harmony/blob/main/README.md"
homepage = "https://github.com/mattpolzin/harmony"
sourceloc = "https://github.com/mattpolzin/harmony"
bugtracker = "https://github.com/mattpolzin/harmony/issues"

langversion >= 0.7.0

Expand Down
20 changes: 10 additions & 10 deletions node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ let
sha512 = "VRLSGzik+Unrup6BsouBeHsf4d1hOEgYWTm/7Nmw1sXoN1+tRly/Gy/po3yeahnP4jfnQWWAhQAqcNfH7ngOkA==";
};
};
"@types/node-20.10.5" = {
"@types/node-20.10.6" = {
name = "_at_types_slash_node";
packageName = "@types/node";
version = "20.10.5";
version = "20.10.6";
src = fetchurl {
url = "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz";
sha512 = "nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==";
url = "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz";
sha512 = "Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==";
};
};
"aggregate-error-3.1.0" = {
Expand Down Expand Up @@ -535,13 +535,13 @@ let
sha512 = "1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==";
};
};
"simple-git-3.21.0" = {
"simple-git-3.22.0" = {
name = "simple-git";
packageName = "simple-git";
version = "3.21.0";
version = "3.22.0";
src = fetchurl {
url = "https://registry.npmjs.org/simple-git/-/simple-git-3.21.0.tgz";
sha512 = "oTzw9248AF5bDTMk9MrxsRzEzivMlY+DWH0yWS4VYpMhNLhDWnN06pCtaUyPnqv/FpsdeNmRqmZugMABHRPdDA==";
url = "https://registry.npmjs.org/simple-git/-/simple-git-3.22.0.tgz";
sha512 = "6JujwSs0ac82jkGjMHiCnTifvf1crOiY/+tfs/Pqih6iow7VrpNKRRNdWm6RtaXpvvv/JGNYhlUtLhGFqHF+Yw==";
};
};
"undici-types-5.26.5" = {
Expand Down Expand Up @@ -626,7 +626,7 @@ let
sources."@types/aws-lambda-8.10.130"
sources."@types/btoa-lite-1.0.2"
sources."@types/jsonwebtoken-9.0.5"
sources."@types/node-20.10.5"
sources."@types/node-20.10.6"
sources."aggregate-error-3.1.0"
sources."before-after-hook-2.2.3"
sources."bottleneck-2.19.5"
Expand Down Expand Up @@ -661,7 +661,7 @@ let
sources."lru-cache-6.0.0"
];
})
sources."simple-git-3.21.0"
sources."simple-git-3.22.0"
sources."undici-types-5.26.5"
sources."universal-github-app-jwt-1.1.1"
sources."universal-user-agent-6.0.1"
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Data.String
import Data.User

import AppVersion
import BashCompletion
import Commands
import Config
import FFI.Git
Expand All @@ -17,6 +16,9 @@ import JSON.Parser
import System
import System.File

import BashCompletion
import ZshCompletion

import Text.PrettyPrint.Prettyprinter
import Text.PrettyPrint.Prettyprinter.Render.Terminal

Expand Down Expand Up @@ -157,7 +159,7 @@ handleConfiguredArgs @{config} envPAT args = do
handleAuthenticatedArgs @{config'} args


-- bash completion is a special case where we don't want to create the config
-- bash and zsh completion are special cases where we don't want to create the config
-- if it doesn't exist yet so we handle it up front before loading config and then
-- handling any other input.
covering
Expand All @@ -167,9 +169,9 @@ handleArgs : Git =>
-> (editor : Maybe String)
-> List String
-> IO ()
handleArgs _ _ _ ["--bash-completion", curWord, prevWord] = exitError "Bash completion is currently configured using a pre-v2.0 version of harmony. Please restart your shell, re-source your resource script, or re-run 'eval \"$(harmony --bash-completion-script)\"'"
handleArgs _ _ _ ["--bash-completion", subcommand, curWord, prevWord] = bashCompletion subcommand curWord prevWord
handleArgs _ _ _ ["--bash-completion-script"] = putStrLn BashCompletion.script
handleArgs _ _ _ ["--zsh-completion-script"] = putStrLn ZshCompletion.script
handleArgs envPAT terminalColors editor args =
resolve'' $
do -- create the config file before continuing if it does not exist yet
Expand Down
18 changes: 18 additions & 0 deletions src/ZshCompletion.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

module ZshCompletion

import BashCompletion

||| Zsh completion is performed via Harmony's Bash completion support.
||| For details on the expected structure of bash completion calls, see
||| the docs for the `BashCompletion.script` function.
export
script : String
script = """
# compdef harmony
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit

\{BashCompletion.script}
"""