1

My intention is to copy many pages of my terminal output to a file for logging purpose. The trick to copy screen content does not work well with me. It requires too many keys to remember, and even if I remember it, it is still slower than Shift+F7 to capture the whole thing.

However, Shift+F7 opens a new window tab name "PRINTSCREEN*" using my environment $EDITOR, and if I choose to save it (using vim or emacs), it will save to something like /tmp/shm/byobu-username-RanDomNameDir/.

I will have to navigate to my $PWD to save the file. The path is most of the time very deep and long. Is there a way I can change so that the temporary buffer of byobu's PRINTSCREEN default to $PWD?

Update:

Why not just use redirection?

Many suggested this. The answer is, I know about redirection. But this is not the case to use it. I do interactive with the terminal to explore various direction before script the work and redirect output to file "properly". My question is about tweaking configuration of byobu's Shift+F7 command. The sole purpose of it is to serve the use cases where screen redirection did not happen. So no need to talk about screen redirection please.

  • Doesn't the PrtScrn key work for you? – Jos Jul 10 '18 at 09:00
  • @Jos: No, because I have thousands of lines, and want to save the output in text. – biocyberman Jul 10 '18 at 09:03
  • This sounds like an X-Y Problem. What are you actually trying to achieve? If you want to capture the output of a command (series) you can use output redirection. – David Foerster Jul 10 '18 at 10:21
  • @DavidFoerster I updated the title to make it clearer what I want to achieve. It is not screen redirection because I want to save my interactive session. It 's not duplicate neither, because the main thing is to change default path for byobu Shift+F7 command – biocyberman Jul 10 '18 at 10:31
  • @biocyberman: In that case could you please describe how you configured the keyboard short-cut in question in byobu currently (maybe linking to a relevant answer serving as a template)? Thanks. – David Foerster Jul 10 '18 at 10:38
  • @DavidFoerster I did not customized the shortcut. It is configured by default. I actually I digged into the source code and found the relevant line: https://github.com/dustinkirkland/byobu/blob/master/usr/share/byobu/keybindings/f-keys.tmux#L65 I will make changes and see – biocyberman Jul 10 '18 at 10:48

2 Answers2

1

Use Linux embedded script utility. For example, to capture everything from terminal to file capture.log in the current directory (get it with pwd), do:

script capture.log

To stop capturing just type exit or press CTRL+D. More information on script and its options:

man script

Remark. Script utility output files contain raw control characters, thus to read it use less with -r and -R options, i.e.

less -rR capture.log

To clean output files from raw control characters use the command:

cat capture.log | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b > capture-clean.log

The last command removes raw control chars from capture.log file and creates plain text file capture-clean.log.

Additionally read How to clean up output of linux 'script' command.

Bob
  • 2,533
  • I overlooked script. It is useful and can almost provide what I want. But, its intention is to print out its output, not to read with plain-text viewers. So it's output looks quite messy if view in, for example, less. – biocyberman Jul 11 '18 at 08:46
0

After some testing, I decided that it's best to fix from the root: not byobu, but tmux. Some nice developer at tmux community made a patch. And things works perfectly now: https://github.com/tmux/tmux/issues/1400