I want to initiate those commands automatically when attaching a screen:
Ctrl+a |
Then
Ctrl+a TAB
Then
Ctrl+a :resize 15
Anyway to do this in one command line?
You can put respective commands at the end of your ~/.screenrc file and they'll get executed every time you start screen. In case you'd like this happen only occasionally, you could create a special screenrc-file, e.g. ~/.screenrc.special and then run screen with screen -c ~/.screenrc.special when you want these things to happen.
Your ~/.screenrc in this case should have as last three lines this:
split
focus
resize 15
Split now supports the -v option
split -v
focus
resize 15
Related
I have this command:
bindsym $mod+q split toggle
This will toggle between hsplit and vsplit. My individual vsplit and hsplit (activated using $mod+v and $mod+h respectively) are:
bindsym $mod+h split h; exec notify-send 'tile horizontally'
bindsym $mod+v split v; exec notify-send 'tile vertically'
As you can see, these individual splits have a notify-send that pop up to tell me which split orientation is being used.
How do I add that to the split toggle command above?
I tried:
bindsym $mod+q split toggle; exec notify-send 'vertical'; exec notify-send 'horizontal'
This doesnt seem to work. The split toggle command on its own does highlight the side of the window that it's being split, i.e. vertical split has right side of the window being highlighted, while horizontal split has the bottom side of the being highlighted.
However, I would like some better visual feedbacks, hence I want to get this notify-send to work.
What you've written essentially wants to call notify-send twice. So what you probably need to do instead is bind the key to a shell script that keeps track of the current split state (or can inquire about it) using i3-msg.
Often when I run a command that writes to stdout, and that command fails, I have to scroll up (using uncomfortable key-bindings) looking for the place where I pressed Enter, to see what the first error was (out of hundreds others, across many screens of text). This is both annoying and time-consuming. I wish there was a feature which allowed me to pin my current terminal to the place where I am now, then start the command, see only the first lines of the output (as many as fits below my cursor) and let the rest of the output be written but not displayed. In other words I would like a feature to allow me automatically scroll up to the place where I gave the command, to see the first lines of the output (where usually the origin of the failure is displayed).
I searched for it but I didn't find it. Do you know if such feature exists? Or have an idea how to implement it with some tricks or workarounds?
If you have a unique shell prompt you could bind a key to jump between shell prompts, for example something like this will make C-b S jump to the previous shell prompt then S subsequent ones:
bind S copy-mode \; send -X search-backward 'nicholas#myhost:'
bind -Tcopy-mode S send -X search-backward 'nicholas#myhost:'
Or similarly you could search for error strings if they have a recognisable prefix. If you install the tmux 3.1 release candidate, you can search for regular expressions.
Alternatively, you could use capture-pane to load the entire history into an editor with key bindings you prefer, for example:
$ tmux capturep -S- -E- -p|vim -
Or pipe to grep or whatever. Note you will need to use a temporary file for this to work with emacs.
Or try to get into the habit of teeing commands with lots of output to a file to start with.
I catted a binary file and hit Ctrl-Z to stop it. Now ls results are misaligned. What did it happen and how could I have them listed correctly again ?
Type reset to reset your terminal, and press Enter. Then maybe press Ctrl+L to clear the screen. You should be back to normal.
Oh and by the way, that binary cat you ran, when you pressed Ctrl-Z that just suspended it, it's probably still running. Run jobs to see the list of jobs, and if it's there, say job number 2, do kill %2 (or whichever job number).
When you catted the binary file, your terminal probably inadvertently interpreted some of its data as control sequences and tried to execute them, screwing its properties and state.
You can either kill the terminal altogether (quit it if you're in a GUI, or relog if you're on a tty), or use another control sequence to reset the terminal. echo -e \\033c should do the trick. Some systems also have a reset builtin/command, which accomplishes the same thing.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
The community reviewed whether to reopen this question 5 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
When using GNU Screen we can work with scrollback buffer also known as "copy mode" using the Ctrl+a+[ command.
In there we can copy text to the copy buffer by pressing space selecting the text and pressing space again.
Is there some way to copy this text from screen copy buffer to the X clipboard?
In my case I'm using Ubuntu 12.04 with gnome and Xorg.
You can use a CLI clipboard tool like xsel or pbpaste and the cat utility to grab contents from STDIN. The steps on Linux with xsel are as follows:
Copy text from your screen session into GNU screen's copy buffer.
Run this command within screen: cat | xsel -b
If xsel didn't report any error, now dump screen's copy buffer to STDIN: Ctrl+a+]
Send an EOF to cat to terminate it: Ctrl+d
At this point, the contents of the screen copy buffer should be in your clipboard.
EDIT: As with all X programs, xsel needs to know how to contact your X server in order to access the clipboard. You should have your DISPLAY environment variable set appropriately.
This answer works for only a scenario where your end target is to paste the copied buffer contents immediately.
The simplest way to do this is by splitting your screen into two regions. You can do this by hitting CTRL+a then |'This is not an i. It is the PIPE sign on your keyboard'
Hit CTRL+a then TAB to switch to the second region, CTRL+a then c to create a new session in the second region.
If you want to copy from nano and paste in terminal, open up the file in nano on the left region, hit CTRL+a then ESC, scroll to the start point of your copy location and hit SPACE, select the text by scrolling to the end point and hit SPACE again to mark copy.
Now, all you have to do is hit CTRL+a then TAB to switch to the region on your right and hit CTRL+a then ].
Your text will be written out to the command line. Note that you can also check for hardcopy option if you want to write directly to file.
There is a simpler and less manual way to do this. In your screen .rc file, add the following line:
bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "/usr/bin/pbcopy < /tmp/screen-exchange"'
How to use the copy functionality:
screen -c path/to/screen/config.rc
Hit Ctrl+A then Esc to enter copy mode.
Scroll up the text buffer and find the spot you want to leave your start marker for copying, then hit space.
Scroll down and select the text you wish to copy. When you are done, hit space again.
The text will now be in your clipboard.
EDIT:
On Linux with no pbcopy but with clipit, you can use as below:
bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "/bin/cat /tmp/screen-exchange | /bin/clipit"'
This answer applies to OS X.
After copying the desired text into the GNU Screen paste buffer using copy mode, do the following:
In any of your screen windows, type pbcopy <enter>.
Then paste your text into the terminal using the GNU Screen paste command (Ctrl-a ] unless you've changed your escape key).
If the text does not end in a newline, press <enter> to insert one.
Finally, press Ctrl-d to cause pbcopy to push the text to the system clipboard.
Then you can paste the text elsewhere in OS X as usual using Command-v or an equivalent menu option.
Since nobody seems to have directly answered the question:
Once you have copied the output you want into your buffer you need to
Open a text editor with a new file i.e. vim somefile.txt
Go into edit mode i.e. i in vim
Press Ctrl + a then ] which will dump the contents of the buffer you just filled into the text editor
ta-da!
Exit your ssh terminal session, if you are currently connected to a server.
If you are using XQuartz on Mac OS and xsel on the server. You should update the XQuartz pasteboard settings by selecting Preferences in the xQuartz application menu.
XQuartz settings:
ssh into the remote machine and try run:
xsel -p <<<"THIS IS A TEST".
Press cmd + v and "THIS IS A TEST" should be output.
I wanted a way to do this programmatically similarly to #kungfuspider and tweaked their solution to work for Ubuntu WSL running on Windows.
Setup:
Download win32yank executable and place win32yank.exe somewhere useful (I created a symbolic link to it in /usr/bin with ln -s <path to exe> /usr/bin/win32yank)
Place the following into ~/.screenrc (from #kungfuspider). You might need to modify the command to point to the correct cat and win32yank locations.
bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "cat /tmp/screen-exchange | win32yank -i --crlf"'
Reload ~/.screenrc without killing your session by executing CTRL+a : source ~/.screenrc
How To Use:
Enter copy mode with CTRL+a [
Move around with vim style key movement or arrow keys
Start selecting text by hitting space
Highlight desired text and finish copy by hitting space again, text should now be in your Windows clipboard and can be pasted back to Ubuntu with a right-click.
Note: It is very important to finish copy with a space because that's what the bindkey command is using to map win32yank
If it's just a little bit of info that you want to copy just highlight it with your mouse and then paste it where you want.
If you're trying to get a lot of info the screen session can be logged to a file and then you can copy from the file or clean it up a bit and use it for instructions on doing things
Finally today I found a solution with mouse:
Hold down Ctrl and right click with mouse.
Copy/paste context menu shows up.
Some screens at https://michalzuber.wordpress.com/2015/01/28/gnu-screen-copy-paste-with-mouse/
Simply put, I know you can do ctrl+v+tab to insert a physically real tab character in a bash statement. But how do I do the same for iTerm?
The answer was to hit control+v, then tab afterwards, not all together! Hope this helps someone.
It's not iTerm, but your shell that affects how you''re able to insert a tab.
First, make sure you're in BASH shell: Type the following command:
$ echo $RANDOM $BASH_VERSINFO
23714 3
The first is a random number, and the second should be the BASH Version number. If you get a blank line or just a random number, you're not in the BASH shell, and that's probably one of your issues.
Another thing is to execute this command:
$ set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
[...]
privileged off
verbose off
vi off
trace off
The two lines of interest is the emacs and the vi lines. One of those should be on. If they're both off, you can't do the Ctrl-V-Tab to insert a tab character.
When the vi mode is on, it should be Ctrl-V-Tab like you said. With emacs mode on, it is either Ctrl-V-tab, or possibly Ctrl-Q-tab.
However, this isn't an iTerm thing, this is your shell that's doing it.
If by a "physically real tab character" you mean sending the tab hex code (0x09) to the shell, then you can do this in iTerm by pressing Ctrl + Tab (⌃ ⇥).
This is the default setting, although you can change it (as well as add other hex code values to send) in iTerm > Preferences > Profiles > Keys.
I'm not certain why you're comparing a "bash statement" with iTerm. You write bash scripts in iTerm. Which means, assuming you're writing your scripts in iTerm, you're already doing what you want.
I'll assume you mean scripting in vi vs command line. The way I get literal characters on the command line is by using vi editing mode. Do set -o vi. Then you can use ctrl+v followed by tab in the manner that you're used to.
IMO, using vi editing mode comes with a slew of other pluses like searching your history, faster navigation, etc. So you could just add it to your .bashrc if you wanted and use it all the time.
One should also try Ctl + V Ctl + I. It is working in konsole where Ctl+V+Tab deosn't work.