Created
August 20, 2012 20:54
-
-
Save 2shortplanks/3407819 to your computer and use it in GitHub Desktop.
Last command run in current terminal, applescript in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mac::AppleScript qw(RunAppleScript); | |
######################################################################## | |
# work out the line on the command line | |
######################################################################## | |
my $text = RunAppleScript(<<'END'); | |
tell application "Terminal" | |
tell front window | |
history of selected tab as text | |
end | |
end | |
END | |
# strip off any applescript string wrapper | |
$text =~ s/\A"//x; | |
$text =~ s/"\z//x; | |
$text =~ s/\\"/"/gx; | |
$text =~ s/\\\\/\\/gx; | |
# doesn't get much more inefficent than this! | |
my @lines = split /\n/, $text; | |
my $capture = ""; | |
do { | |
$capture = pop(@lines) . "\n" . $capture; | |
} while ($lines[-1] =~ /\\\z/); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment