Skip to content

Instantly share code, notes, and snippets.

@nugend
Created November 14, 2019 22:00
Show Gist options
  • Save nugend/c84ab9e7478023c4ac375488b6654b3c to your computer and use it in GitHub Desktop.
Save nugend/c84ab9e7478023c4ac375488b6654b3c to your computer and use it in GitHub Desktop.
RLWrap Strip Newlines
alias q='rlwrap --multi-line --multi-line-ext=.q --filter=/path/to/remove_newline.pl --no-warnings q'
#!/usr/bin/env perl
# filter to remove newlines from an editor session (initiated with Ctrl-^)
use lib ($ENV{RLWRAP_FILTERDIR} or ".");
use RlwrapFilter;
use strict;
my $filter = new RlwrapFilter;
my $name = $filter -> name;
$filter -> help_text("Usage: rlwrap --multi-line --filter='$name' --no-warnings\n".
"Removes newlines from editor session text\n"
);
$filter -> input_handler(\&scrub);
$filter -> run;
sub scrub {
my ($dirty) = @_;
my $clean = $dirty;
$clean =~ s/^$/;/gm;
$clean =~ s/^\s+//gm;
$clean =~ s/\n//g;
return $clean;
}
@nugend
Copy link
Author

nugend commented Nov 14, 2019

Use the Ctrl+^ key in the interpreter to drop into the editor

Borrowed from... somewhere. I don't remember where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment