Skip to content

Commit

Permalink
ast-grep: rename command sg to ast-grep
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiangmoe committed Jan 15, 2025
1 parent 4f6586c commit a43569a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

- `ast-grep` remove `sg` command to prevent conflict with `sg` command from shadow-utils. If you need legacy sg command compatibility with old code, you can use `ast-grep.override { enableLegacySg = true; }`

- `binwalk` was updated to 3.1.0, which has been rewritten in rust. The python module is no longer available.
See the release notes of [3.1.0](https://github.com/ReFirmLabs/binwalk/releases/tag/v3.1.0) for more information.

Expand Down
38 changes: 31 additions & 7 deletions pkgs/by-name/as/ast-grep/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
fetchFromGitHub,
stdenv,
installShellFiles,
buildPackages,
versionCheckHook,
enableLegacySg ? false,
}:

rustPlatform.buildRustPackage rec {
Expand All @@ -26,12 +29,27 @@ rustPlatform.buildRustPackage rec {
rm .cargo/config.toml
'';

postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd sg \
--bash <($out/bin/sg completions bash) \
--fish <($out/bin/sg completions fish) \
--zsh <($out/bin/sg completions zsh)
'';
cargoBuildFlags = [
"--package ast-grep --bin ast-grep"
] ++ lib.optionals enableLegacySg [ "--package ast-grep --bin sg" ];

postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (
let
emulator = stdenv.hostPlatform.emulator buildPackages;
in
''
installShellCompletion --cmd ast-grep \
--bash <(${emulator} $out/bin/ast-grep completions bash) \
--fish <(${emulator} $out/bin/ast-grep completions fish) \
--zsh <(${emulator} $out/bin/ast-grep completions zsh)
''
+ lib.optionalString enableLegacySg ''
installShellCompletion --cmd sg \
--bash <(${emulator} $out/bin/sg completions bash) \
--fish <(${emulator} $out/bin/sg completions fish) \
--zsh <(${emulator} $out/bin/sg completions zsh)
''
);

checkFlags =
[
Expand All @@ -48,14 +66,20 @@ rustPlatform.buildRustPackage rec {
"--skip=test::test_load_parser"
"--skip=test::test_register_lang"
];
nativeInstallCheckInputs = [
versionCheckHook
];
versionCheckProgramArg = [ "--version" ];
doInstallCheck = true;

meta = with lib; {
mainProgram = "sg";
mainProgram = "ast-grep";
description = "Fast and polyglot tool for code searching, linting, rewriting at large scale";
homepage = "https://ast-grep.github.io/";
changelog = "https://github.com/ast-grep/ast-grep/blob/${src.rev}/CHANGELOG.md";
license = licenses.mit;
maintainers = with maintainers; [
xiaoxiangmoe
montchr
lord-valen
cafkafk
Expand Down

0 comments on commit a43569a

Please sign in to comment.