0

In Terminal I su - admin while in my user account to brew update, modify .bashrc, etc.

I have noticed that when in my user session changing the size of the window while running nano doesn't scramble the text at all. The window resizes perfectly.

However, after opening a new Terminal window, running su - admin, then nano and trying to resize - the text is scrambled and there is no way to recover it. control-l doesn't work.

When I log into the admin account open Terminal and run nano there is no issue with resizing the window — text doesn't scramble.

The same issue happens in reverse. From my admin account using su - user and running nano and resizing will cause the text to scramble.

Any idea what's happening here and how to resolve this issue?

I am using nano 4.9

1

The terminal emulator will send a Window Change signal (SIGWINCH) to the shell that was started along with the terminal emulator. The shell is supposed to pass it on to its children - but when you've transitioned to another user account (using su or otherwise), it won't be able to signal that shell because it's running as a different user. So the su'd shell and any programs run from it will keep using the old window size, oblivious to the fact that the real window size has changed.

To fully update the su session to use the new window size, you'll need to run eval $(resize) in that shell. It will both update the environment variables COLUMNS and LINES (that's why eval is needed), and the terminal settings (equivalent to commands stty rows and stty columns). In many cases, just resize without the eval... part might be sufficient, but some programs might need the environment variables too.

1
  • Thank you the background information! Apparently resize doesn't exist on macOS natively. But if it did... while I was in nano editing a document, how would I send that as a command? Is there an environmental variable I can set or can I add a command while transitioning to another account using su? – John Mar 31 '20 at 18:09
0

Using login on OS X is a workaround for this issue.


$ login
login: your username
password: your password
Last login: Day Month Date HH:MM:SS on ttys000
$ whoami
your username

Thanks to user grg on Apple Stack Exchange

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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