2
\$\begingroup\$

Create a script that, when run from a console, will display the text already in the console, prior to running.

Challenge

  • How will the winner of the challenge will be determined?

    The golf with the shortest length (in bytes) will win.

Example Input and Output

Input: (Shown is Windows)

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\CSS>dir
 Volume in drive C has no label.
 Volume Serial Number is B0A1-E768

 Directory of C:\Users\CSS

11/30/2016  07:18 PM    <DIR>          .
11/30/2016  07:18 PM    <DIR>          ..
12/01/2016  04:45 PM    <DIR>          .android
10/25/2016  12:41 PM    <DIR>          .atom
11/29/2016  05:52 PM    <DIR>          .dnx
10/27/2016  09:34 PM               148 .gitconfig
11/28/2016  03:02 PM    <DIR>          .MemuHyperv
11/29/2016  05:55 PM    <DIR>          .nuget
12/01/2016  04:42 PM    <DIR>          .oracle_jre_usage
10/26/2016  11:37 PM    <DIR>          .ssh
12/04/2016  06:20 PM    <DIR>          .VirtualBox
11/29/2016  12:56 PM    <DIR>          .vscode
11/28/2016  03:53 PM             8,528 2016-11-28-20-44-28.000-VBoxSVC.exe-2608.log
11/28/2016  05:09 PM    <DIR>          Andy
11/23/2016  10:01 AM    <DIR>          Contacts
12/11/2016  11:16 PM    <DIR>          Desktop
11/30/2016  07:35 PM    <DIR>          Documents
12/11/2016  01:43 AM    <DIR>          Downloads
11/23/2016  10:01 AM    <DIR>          Favorites
11/22/2016  07:23 PM               409 fciv.err
11/22/2016  07:21 PM               266 hi
11/23/2016  10:01 AM    <DIR>          Links
11/22/2016  04:28 PM                15 me.txt
11/28/2016  03:08 PM    <DIR>          Music
10/25/2016  12:44 AM    <DIR>          OneDrive
12/09/2016  05:57 PM    <DIR>          Pictures
11/23/2016  10:01 AM    <DIR>          Saved Games
11/24/2016  08:56 PM               151 search.bat
11/23/2016  10:01 AM    <DIR>          Searches
11/07/2016  11:00 AM                11 t.bat
11/24/2016  08:55 PM                93 update.bat
11/28/2016  03:08 PM    <DIR>          Videos
               8 File(s)          9,621 bytes
              24 Dir(s)  152,887,300,096 bytes free

C:\Users\CSS>

Output:

The script must display something like the text above, in the sense that it must display exactly what was in the console before the script was called.

\$\endgroup\$
  • \$\begingroup\$ Must it print out the entire terminal history, or just what's in the current window? \$\endgroup\$ – Gabriel Benamy Dec 12 '16 at 18:35
  • \$\begingroup\$ @GabrielBenamy The entire terminal history. \$\endgroup\$ – cascading-style Dec 12 '16 at 18:45
  • \$\begingroup\$ What precisely does "before the script was called" mean? When is the script called? If the invocation is directly from the terminal, is it when the user starts typing in the path to the script, or when they hit enter? If the invocation is indirect via a script which invokes my script, is it when the wrapper script is called or when it invokes my script? \$\endgroup\$ – Peter Taylor Dec 12 '16 at 19:04
  • \$\begingroup\$ @PeterTaylor The script is called when you hit enter. The script does not need to filter out the characters from the script being invoked. However, bonus points if it does. \$\endgroup\$ – cascading-style Dec 12 '16 at 19:08
  • 1
    \$\begingroup\$ The entire history of what was typed into the terminal is not necessarily stored anywhere. \$\endgroup\$ – feersum Dec 12 '16 at 19:16
1
\$\begingroup\$

MacOS terminal, 84 bytes

osascript -e 'tell app "System Events" to keystroke "ac" using command down'
pbpaste

Simple select-all then copy-and-paste.

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.