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

Implement env filter #876

Merged
merged 6 commits into from
Oct 22, 2024
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
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
Loading