Skip to content

Commit

Permalink
Fix output of list_running_app_ids script (#83164)
Browse files Browse the repository at this point in the history
Tidy up code following #67948, avoid shelling out as much, and slightly improve column alignment in output.
  • Loading branch information
danielbayley committed May 25, 2020
1 parent d99486f commit 31f6ae5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions developer/bin/list_running_app_ids
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

require "open3"
require "set"
require "io/console"

###
### globals
###

$opt_test = nil
$COLUMNS = IO.console.winsize.last

###
### methods
Expand Down Expand Up @@ -86,23 +88,18 @@ def excluded_app_name(app_name)
%r{^osascript$}.match(app_name) # this script itself
end

def expand(table)
@COLUMNS = `/usr/bin/tput cols`.to_i
puts `echo '#{table}'| /usr/bin/expand -t#{@COLUMNS / 2}`
end

def report_apps
running = Set.new
@app_names.zip(@bundle_ids, @unix_ids).each do |app_name, bundle_id, _unix_id|
next if excluded_bundle_id bundle_id
next if excluded_app_name app_name
bundle_id.gsub!(%r{^(missing value)$}, '<\1>')
running.add "#{bundle_id}\t#{app_name}"
running.add "#{bundle_id.ljust($COLUMNS / 2)}\t#{app_name}"
end

expand "bundle_id\tapp_name"
puts "-" * @COLUMNS + "\n"
expand running.to_a.sort.join "\n"
puts "bundle_id".ljust($COLUMNS / 2) + "\tapp_name"
puts "-" * $COLUMNS
puts running.to_a.sort.join "\n"
end

###
Expand Down

0 comments on commit 31f6ae5

Please sign in to comment.