Skip to content
Merged
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
20 changes: 10 additions & 10 deletions lib/shared-functions
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ skim-stdin() {
#
# Implementation of `pipe-skimming` pattern.
#
# Typical usage within Bash-my-AWS:
#
# - local asg_names=$(skim-stdin "$@") # Append to arg list
# - local asg_names=$(skim-stdin) # Only draw from STDIN
#
# $ stacks | skim-stdin foo bar
# foo bar huginn mastodon grafana
#
# $ stacks
# huginn CREATE_COMPLETE 2020-01-11T06:18:46.905Z NEVER_UPDATED NOT_NESTED
# mastodon CREATE_COMPLETE 2020-01-11T06:19:31.958Z NEVER_UPDATED NOT_NESTED
# grafana CREATE_COMPLETE 2020-01-11T06:19:47.001Z NEVER_UPDATED NOT_NESTED
#
# Typical usage within Bash-my-AWS functions:
#
# local asg_names=$(skim-stdin "$@") # Append to arg list
# local asg_names=$(skim-stdin) # Only draw from STDIN

local skimmed_stdin="$([[ -t 0 ]] || awk 'ORS=" " { print $1 }')"

printf -- '%s %s' "$*" "$skimmed_stdin" |
awk '{$1=$1;print}' # trim leading/trailing spaces

(
printf -- "$*" # Print all args
printf " " # Print a space
[[ -t 0 ]] || awk 'ORS=" " { print $1 }' # Print first token of each line of STDIN
) | awk '{$1=$1;print}' # Trim leading/trailing spaces
}


Expand Down