1

When I exit a screen, I want to be able to return to the terminal looking as I left it. But right now, all I can do is have it clear the screen and put the terminal at the top or the bottom through modifying my .screenrc file.

I can get the interaction I want by doing tput smcup; screen -S hello; tput rmcup, but I don't think I can easily alias or safely make it into a function*.  How would I change my .screenrc file to get this behavior?

Here is what I have tried to little effect from other Stack Exchange questions:

termcapinfo xterm|xterms|xs|rxvt ti@:te@
termcapinfo xterm*|rxvt*  te=\E[?1049l:ti=\E[?1049h:
termcapinfo xterm*|rxvt*  te=:ti= 

from How to prevent GNU screen from clearing the screen when terminating?

I also read the answer to “Why doesn't the screen clear when running vi?” in the XTerm FAQ by Thomas E. Dickey, but couldn't translate it into something actionable.

Changing the term command didn't affect me and I didn't try the second part: Detaching from a GNU Screen suddenly clears the terminal (on Super User).

____________
* I did actually try my hand at it, but I'd like some confirmation that this wouldn't break anything:

jscreen () {

  if [ $# -eq 2 ]; then
      if [ $1 == "-r" ] || [ $1 == "-S" ]; then
        tput smcup
        screen $@
        tput rmcup
        return
      fi
  fi
  screen $@
}
Jeff
  • 123
  • 4
  • Please don’t say `$@` without putting it in quotes: `screen "$@"`. – G-Man Says 'Reinstate Monica' Nov 08 '22 at 04:41
  • Shouldn't that not matter unless the argument itself has spaces in it, in which case, the user should double quote that himself, like `screen -S "help me"` to make a screen called `\`help me\``? And thanks for the code edit. – Jeff Nov 09 '22 at 16:43
  • 1
    (1) Well, you’re getting the point and missing the point at the same time.  Yes, quoting is partly about preserving spaces.  And yes, of course, if the user makes a screen called `foo bar` by typing `screen -S "foo bar"` and later tries to reattach to it with `screen -r foo bar`, it won’t work.  But the point is, if they run your `jscreen` function as `jscreen -r "foo bar"`, and your function says `screen $@` (without quotes), then your function will run `screen -r foo bar`, which won’t work.   … (Cont’d) – G-Man Says 'Reinstate Monica' Nov 09 '22 at 19:36
  • 1
    (Cont’d) …  (2) Quoting is also critical when the ``IFS`` variable has been set to something weird, or when dealing with strings that contain any of the glob characters `?`, `*` or `[`.   See [Security implications of forgetting to quote a variable in bash/POSIX shells](https://unix.stackexchange.com/q/171346/80216), [Why does my shell script choke on whitespace or other special characters?](https://unix.stackexchange.com/q/131766/80216), and the other questions referenced in [the \[quoting\] tag wiki](https://unix.stackexchange.com/tags/quoting/info). – G-Man Says 'Reinstate Monica' Nov 09 '22 at 19:36

0 Answers0