Skip to content

Commit

Permalink
Implement env filter (#876)
Browse files Browse the repository at this point in the history
* Implement `envs` command to make easier debugging GH-755 and developing GH-853

* Rewrite the command with ruby, the pipeline_w much helps for daily use. So closes GH-825 for now
  • Loading branch information
kachick authored Oct 22, 2024
1 parent 87353d0 commit e3a178d
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 0 deletions.
154 changes: 154 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# TODO: Extract to another repository for use of inheritance

AllCops:
TargetRubyVersion: 3.3
DisplayCopNames: true
DisabledByDefault: true
Exclude:
- 'dependencies'
- '.direnv'
- 'result'
- 'dist'
NewCops: disable

Security:
Enabled: true

Style/HashSyntax:
Enabled: true

Style/TrailingMethodEndStatement:
Enabled: true

Style/MethodDefParentheses:
Enabled: true

Style/TrailingCommaInBlockArgs:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: 'single_quotes'

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: 'single_quotes'

Style/TopLevelMethodDefinition:
Enabled: true

Style/InPatternThen:
Enabled: true

Style/HashEachMethods:
Enabled: true

Style/QuotedSymbols:
Enabled: true
EnforcedStyle: 'single_quotes'

Style/MultilineInPatternThen:
Enabled: true

Layout:
Enabled: true

Layout/TrailingEmptyLines:
Enabled: true

Layout/TrailingWhitespace:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Layout/SpaceBeforeSemicolon:
Enabled: true

Layout/SpaceInsideArrayPercentLiteral:
Enabled: true

Layout/SpaceInsideBlockBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: true

Layout/SpaceInsideRangeLiteral:
Enabled: true

Layout/SpaceInsideReferenceBrackets:
Enabled: true

Layout/SpaceInsideStringInterpolation:
Enabled: true

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/ArgumentAlignment:
Enabled: true

Layout/CaseIndentation:
Enabled: true

Layout/SpaceInLambdaLiteral:
Enabled: true
EnforcedStyle: require_space

Layout/SpaceBeforeBlockBraces:
Enabled: true

Naming/MethodName:
Enabled: true

Naming/FileName:
Enabled: true

Naming/ConstantName:
Enabled: true

Naming/ClassAndModuleCamelCase:
Enabled: true

Naming/BlockParameterName:
Enabled: true

Naming/HeredocDelimiterCase:
Enabled: true

Bundler:
Enabled: true

Bundler/OrderedGems:
Enabled: false

Gemspec:
Enabled: true

Gemspec/OrderedDependencies:
Enabled: false

Lint:
Enabled: true

Lint/InheritException:
Enabled: false

Lint/RedundantStringCoercion:
Enabled: false

Lint/UnusedMethodArgument:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Lint/RescueException:
Enabled: false
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
go_1_23
goreleaser
trivy

(ruby_3_3.withPackages (ps: with ps; [ rubocop ]))
])
++ (with edge-pkgs; [
nixd
Expand All @@ -104,6 +106,7 @@
micro-nordcolors = homemade-packages.${system}.micro-nordcolors;
micro-everforest = homemade-packages.${system}.micro-everforest;
micro-catppuccin = homemade-packages.${system}.micro-catppuccin;
envs = homemade-packages.${system}.envs;
});

apps = forAllSystems (
Expand Down Expand Up @@ -132,6 +135,7 @@
"git-log-simple"
"git-resolve-conflict"
"gh-prs"
"envs"
"nix-hash-url"
"reponame"
"gredit"
Expand Down
1 change: 1 addition & 0 deletions home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
p
g
walk
envs
ir
updeps
bench_shells
Expand Down
2 changes: 2 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

gh-prs = import ./gh-prs { inherit pkgs; };

envs = import ./envs { inherit pkgs; };

reponame = import ./reponame { inherit pkgs; };

beedii = pkgs.callPackage ./beedii { };
Expand Down
12 changes: 12 additions & 0 deletions pkgs/envs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ pkgs, ... }:
pkgs.writeShellApplication rec {
name = "envs";
text = builtins.readFile ./${name}.bash;
runtimeInputs = with pkgs; [
fzf
ruby_3_3 # pkgs.writers.writeRuby and writeRubyBin does not fit
];
runtimeEnv = {
RUBY_SCRIPT_PATH = ./${name}.rb;
};
}
1 change: 1 addition & 0 deletions pkgs/envs/envs.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby -w "$RUBY_SCRIPT_PATH" "$@"
17 changes: 17 additions & 0 deletions pkgs/envs/envs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'open3'

shortner = -> str {
limit = 70
length = str.size
str.slice(...limit).gsub("\n", ' ') + (length > limit ? '...' : '')
}

envs = ENV.sort.map { |k, v| "#{k}=#{shortner.(v)}" }

fzf_query = ARGV.first

Open3.pipeline_w(
%Q!fzf --delimiter '=' --nth '1' --query "#{fzf_query}"!
) do |first_stdin, _wait_thrs|
first_stdin.puts envs
end

0 comments on commit e3a178d

Please sign in to comment.