Skip to content

Instantly share code, notes, and snippets.

@vuon9
Last active July 27, 2023 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vuon9/30c0b8fd65b48369691abad6727e6a58 to your computer and use it in GitHub Desktop.
Save vuon9/30c0b8fd65b48369691abad6727e6a58 to your computer and use it in GitHub Desktop.
Sequel Ace bundle - Copy as Cucumber table

Copy a bundle command to a new one then change it to similar like the below settings.

How the bundle setting looks like

This will help to copy via context menu:

image

And output to Cucumber format table when you pasting:

| id    | content                      | created_at          | 
| 80883 | very longgggggggg contentttt | 2023-05-18 04:00:17 | 
| 80953 | very longgggggggg contentttt | 2023-05-18 04:00:23 | 
| 81090 | very longgggggggg contentttt | 2023-05-19 04:00:20 | 
| 81105 | very longgggggggg contentttt | 2023-05-19 04:00:22 | 
| 81296 | very longgggggggg contentttt | 2023-05-20 04:00:18 | 
| 81333 | very longgggggggg contentttt | 2023-05-20 04:00:21 | 
| 81489 | very longgggggggg contentttt | 2023-05-21 04:00:19 | 
| 81491 | very longgggggggg contentttt | 2023-05-21 04:00:19 | 
| 81676 | very longgggggggg contentttt | 2023-05-22 04:00:18 | 
| 81703 | very longgggggggg contentttt | 2023-05-22 04:00:20 | 
cat | /usr/bin/perl -e '
use strict;
use warnings;
# Read row data of each selected row
my $rowData;
my @rows = ();
while ($rowData = <>) {
# Remove line ending and trim the data
chomp($rowData);
$rowData =~ s/^\s+|\s+$//g;
# Split column data which are tab-delimited
my @data = split(/\t/, $rowData);
push @rows, \@data;
}
# Find the maximum width of each column
my $h_cnt = scalar @{$rows[0]}; # number of columns
my @max_widths = ();
for (my $i = 0; $i < $h_cnt; $i++) {
my $max_width = length($rows[0][$i]);
foreach my $row (@rows) {
my $col_width = length($row->[$i]);
if ($col_width > $max_width) {
$max_width = $col_width;
}
}
push @max_widths, $max_width;
}
# Print the Gherkin table
foreach my $row (@rows) {
print "| ";
for (my $i = 0; $i < $h_cnt; $i++) {
my $cell_value = $row->[$i];
my $header_length = length($rows[0][$i]);
my $max_width = $max_widths[$i];
if (length($cell_value) < $header_length) {
$max_width = $header_length;
}
printf("%-*s | ", $max_width, $cell_value);
}
print "\n";
}
print "\n";
' | __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment