Trim whitespace when copying from gnu screen in a terminal - whitespace

I'm running 20.04.4 using the MATE desktop and the mate-terminal (which is a derivative of Xterm, if I understand correctly).
When I copy text from the terminal, trailing whitespace is ignored (as I want it to be). However, if I copy text from a gnu-screen window within the terminal, the whitespace is included. (My clipboard manager, Parcellite, has an option which trims both leading and trailing whitespace, but I don't want that.)
Is there a .screenrc I can set to get the desired behavior? (i.e. equivalent to trimSelection in xterm when copying from a screen pane)

Related

Paste bash command, but make sure it doesn't run

Sometimes when you ctrl-v with bash it will run the command even though you didn't intend to run it yet - is there a way to paste a command into the bash shell / terminal making sure you don't actually run any of the command(s)?
if you could set what was on the terminal prompt programmatically, you could do this with bash on MacOS:
export BASH_PROMPT="$(pbpaste)"
which ties into my other question that I just asked:
How to change the value that's in the prompt
There is a Readline variable:
enable-bracketed-paste
When set to On, Readline will configure the terminal in a way that will enable it to insert each paste into the editing buffer as a single string of characters, instead of treating each character as if it had been read from the keyboard. This can prevent pasted characters from being interpreted as editing commands. The default is off.
To turn this on, put something like
set enable-bracketed-paste on
into your ~/.inputrc.
This was introduced in Bash 4.4 / Readline 7.0.
Use ^X^E aka Ctrl+X Ctrl+E in bash to open your $EDITOR for command entry.
Paste and/or edit as much as you want, across as many lines as you want. When you're done, save and exit, and bash will run it.
(In vi mode, the shortcut is v)

Cannot cat shift-jis file in mac terminal

I have a file that emacs correctly displays on mac. When I cat or less the file in mac terminal I see garbled characters such as "?E?u?#?#?#?#?#?#?#?". Running chardetect indicates SHIFT-JIS.
I tried adding the following to ~./bashrc but still see the same output.
export LANG=ja_JP.SHIFT_JIS
export LC_ALL=ja_JP.SHIFT_JIS
Under encodings in preferences for terminal, all encodings are checked including the Japanese ones.
Am I missing some other method here for viewing these files? I can see other files with Japanese characters in the mac terminal.
You need to change the text encoding at the Advanced tab in profile preferences to make Terminal use different encoding.
Env vars (LANG, LC_ALL) only affect the shell and child processes.
Also note that some characters from Windows cannot be displayed (①,髙,Ⅰ (roman digit) etc).

Pasting into OS X command line adds extraneous characters

When I paste text into the Terminal window, Terminal appends 0~ before the pasted string and 1~ after it. I've never seen this behaviour before. If I copy foo from anywhere (including the same Terminal window), pasting into the command line results in:
-bash-4.2$ 0~foo1~
I tried every method for pasting text into OS X terminal from How to paste into a terminal?, i.,e.
Command v; CommandControlv; Shift + Insert.
Pasting into text editors and browsers (basically, any place other than Terminal) does not add any extra characters. Why is this happening and how can I fix it?
I'm using macOS 10.14.2; Terminal version 2.9.1.
I don't know the actual answer for this but for me it works after restarting the terminal.
Command + Q
I will update once I will find something.

How do I get out of ESC mode in zsh?

When using zsh, I sometimes accidentally press Escape out of habit, expecting it to clear the entire line as it does in Windows. Instead, it goes into a mode that I'm not sure how to get out of. The cursor goes back one character, and some keys perform some special commands, but all I really want to do is get out of this mode and be able to press Ctrl+U to clear the line.
Searching around has been tough - I get results for escaping characters.
Short answer: press a.
Medium answer: press a, then enter bindkey -e.
Long answer: Like a lot of UNIX shells, zsh has an emacs-like mode and a vi-like mode. You're in vi-like mode, and ESC takes you out of the vi-like insert mode. a puts you back into insert mode, with the cursor after the current character. (Sorry for the two different uses of "mode," but it is the accepted terminology in both cases.)
bindkey -e overrides the settings from the rc files and puts zsh into emacs mode, which only has one mode (i.e., no "ESC mode"), so this won't bother you any more. Unfortunately, it won't carry over to your next shell invocation. bindkey -v would switch from emacs mode back to vi mode.
In the absence of any other configuration, zsh defaults to emacs mode, so unless there's something in one of the rc files, the likely culprit is that the EDITOR variable is some form of vi, which causes zsh to default to vi mode. If you don't like vi mode, then you should probably hunt down what part of the system-wide or user-specific configuration is causing zsh to default to vi mode and turn it off by removing it or overriding it in one of those rc files.
If everything else fails, when you're in ESC mode, type :w then Enter to save, and then :q to exit. You can also type :wq and Enter

How to strip the newline when use sharing clipboard

description updated
I want to share clipboard between VIM and shell so that when I have text selected in VIM, I can use SHIFT+INSTERT in shell to paste it in command line. One of the user case is to grep certain word in current directory.
I am using VIM version 7.4, and have following line added in vimrc file:
set clipboard=unnamedplus
This approach works fine when do yank in normal mode. When I select text by CTRL+v in VIM, SHIFT+INSERT in shell always paste a newline along with the word.
Is there any way to stripe the newline?

Resources