Skip to content

Commit

Permalink
Refactor with pipeline_w, it much helps for GH-825
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Oct 22, 2024
1 parent 3fab172 commit 20af32e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Style/QuotedSymbols:
Style/MultilineInPatternThen:
Enabled: true

Layout:
Enabled: true

Layout/TrailingEmptyLines:
Enabled: true

Expand Down
15 changes: 1 addition & 14 deletions pkgs/envs/envs.bash
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
if [ $# -ge 1 ]; then
query="$1"
shift
else
query=""
fi

# summarize() {
# local -r env_name="$1"
# local -r val="$env_name"
# printf "%s=%.25s...\n" "$env_name" "$(echo "$val" | tr '\n' ' ')"
# }

ruby -w "$RUBY_SCRIPT_PATH" | fzf --delimiter '=' --nth '1' --query "$query"
ruby -w "$RUBY_SCRIPT_PATH" "$@"
15 changes: 8 additions & 7 deletions pkgs/envs/envs.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# require 'open3'
require 'open3'

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

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

# o, e, s = Open3.capture3("echo a; sort >&2", :stdin_data=>"foo\nbar\nbaz\n")
# p o #=> "a\n"
# p e #=> "bar\nbaz\nfoo\n"
# p s #=> #<Process::Status: pid 32682 exit 0>
fzf_query = ARGV.first

# Open3.capture3("echo a; sort >&2", :stdin_data=>"foo\nbar\nbaz\n")
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 20af32e

Please sign in to comment.