I have an issue when using GNU screen in windows terminal. Mouse wheel scrollback doesn't work.
When using the wheel it does not scroll more than one window height, continues on the printouts before I entered the gnu screen. When using putty it works normally.
Also when using screen scroll (C-a / Escape / "up" or "down") it scrolls normally (past window top).
I am using "Screen version 4.01.00devel (GNU) 2-May-06" and "Windows Terminal Version: 1.5.10271.0".
As my company manages this I can not update to a newer version.
This is my screen file:
# Use bash
shell /bin/bash
# Remove visual bell flash
vbell off
autodetach on
# Enable multiuser:
multiuser on
# Big scrollback
defscrollback 10000
# No startup message
startup_message off
# Display the status line at the bottom
hardstatus on
hardstatus alwayslastline
backtick 0 30 30 sh -c 'screen -ls | grep Multi | cut -f 2'
hardstatus string "%{WK}%-w%{kc} %t [%n] %{-}%+w %=%{+b yK}| %`#%H ~ %Y-%m-%d ~ %c "
# Make first screen for general work
chdir /home/me/scripts/
screen -t 'NODE 1' 1
# Make second screen for general work
screen -t 'NODE 2' 2
# Make screen for logging
chdir /home/me/scripts/LOGGING/
screen -t 'LOGS' 3
# Miscelaneous
chdir /home/me/
screen -t 'MISC' 4
# Switch to the first screen
select 1
# termcapinfo xterm ti#:te#
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007:ti#:te#'
termcapinfo xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l
I found online some issues where adding ti#:te# fixed it, but my screen file already has that. I have tried looking online for documentation on 'ti#' and 'te#' but can not find any. Also I have found somewhere that windows terminal doesn't support screen buffer, which seems odd, but I don't know how to verify.
Any advice would be welcomed!
Related
Question
Is it possible, in a terminal emulator, to run a command whenever a mosue event happens?
What I've tried
I think I'm halfway there - using echo -e "\e[?1003h" (see here for details) and waving the mouse about over the terminal produces a desirable effect of printing a bunch of characters, related to the occurred mouse event. (Note: echo -e "\e[?1003l" turns this off)
echo -e "\e[?1003h"
# move mouse over terminal window, in the character input line, NOT to stdout:
> CF*CC+C#,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C80C81C81C81C81C81C90C:/C;/C;.C<.C<.
# After deleting that, I enter:
> echo -e "\e[?1003l"
# mouse move, all is quiet
I've also tried hooking it up to output to a file. This was to see if I could watch the file and run a command according to that. It went as follows:
> echo -e "\e[?1003h" >> file.txt
# elevator music whilst I move the mouse about
> echo -e "\e[?1003l"
# move mouse a bit, nothing
> cat file.txt
# nothing but blank lines, fair enough. But, mouse moves and in the terminal input is printed...
> CF*CC+C#,C;.C:/C8/C8/C8/C8/C9/C9/C9/C90C90C8 ...
# Delete that output, and then I type:
> echo -e "\e[?1003l"
# mouse moves, no output
What I want
How can I either capture this output so that it is going to stdout, or to a file, so that I can then use the changing output to trigger running a command? If that's not possible, is there any other way to capture when a mouse click occurs in a terminal emulator, with the event coordinates?
It's not output, it's input.
There are multiple ways to read input in bash. Here's one that reads everything until stopped:
echo -e "\e[?1003h"
echo "Press enter and then ctrl-d to stop reading"
cat > myfile
When done and correctly exited with Enter and Ctrl+D you can inspect myfile to see all the mouse events.
A proper mouse application would disable local echo and terminal buffering before reading and decoding the escape sequences from the terminal.
I am scripting the display of the output of a script (well, it is just the program git diff) with tmux: Once a filesystem change is detected the shell script executes tmux send-keys q enter C-l "git diff" enter which has it effectively refresh the git diff view.
You might consider this similar to functionality provided by iTerm's coprocesses.
Problem is, I want it on refresh to scroll back to the same position that it was in.
One of the reasons for using tmux is that the window is actually a totally normal and interactive terminal session that can be interacted with as normal to scroll around to look at the full output.
But I want to obtain the scroll position somehow.
Suppose I want to actually do computation on the text content of the terminal window itself, exactly like iTerm2's coprocess does, but so that I can use it on Linux (over ssh). Does tmux provide this ability?
I'm unsure about capturing this with a script, but less -N will show line numbers.
And -jn or --jump-target=n can jump to a location.
About iTerm's coprocesses,
tmux has a command pipe-pane that can be used to pipe the input and output of a shell command to the output and input of a target pane specified by -t.
So if I have a shell program, ~/script.sh for example:
#!/usr/bin/env bash
while read line; do
if [[ "$line" = "are you there?"* ]]; then
echo "echo yes"
fi
done
Note that read line will read every line printed to the pane, i.e. the prompt as well.
I can connect its stdin and stdout to pane 0 in my-session:my-window like so:
tmux pipe-pane -IO -t my-session:my-window.0 "~/script.sh"
and then at the prompt, type echo are you there?, and it responds:
$ echo are you there?
are you there?
$ echo yes
yes
Be careful using -IO together as it can easily cause a feedback loop (I had to kill the tmux server a few times while experimenting with this feature, lol).
I am using gnome-terminal.
Is it possible to make it(or any other terminal) beep whenever its output screen changes (like some new output line came)?
I want it for only one particular window.
Possibly of use:
The GNU screen program has features for monitoring background windows for activity as well as inactivity.
http://www.gnu.org/software/screen/manual/screen.html#Monitor
Something called lTerm has "tabs with activity alerts"
http://lterm.sourceforge.net/
But at this point I'm turning into a meta search engine.
$ ./myprogram | sed 's/$/\a/'
for example
$ for i in {1..10}; do echo $i; sleep 1; done | sed 's/$/\a/'
I am trying to send input to a interactive command running via screen. Here is my initial command
screen -L -c ./customrc -S psql -d -m /opt/PostgreSQL/9.0/bin/psql
The above command will run interactive psql in screen detach mode. The customrc is used to define a log file for the output (which I will read from another process by polling)
I am using following two commands to send input to psql running in screen
screen -S psql -X readreg p psqlcommands.sql
screen -S psql -X paste p
The problem is that the above commands do not work unless I reattach screen at least once. Once I have attached screen and detached, the above commands work as expected. I have to launch these commands via background java process hence the interactive shell (bash) is not available. My goal is to run psql in interactive mode and pass input to it and capture its output via a log file.
So far I have tried to run screen via xterm (or konsole or gnome-terminal) in attach mode, use readreg/paste and then detach, but I realise that xterm will not be available in my production environment. I've also tried sending output to /proc//fd/0 but I am unable to emulate 'ENTER' from keyboard (I have to attach and press in order for the output to be accepted by psql). I think pipes and fifo may help but I am unable to figure out how to proceed with them using screen and psql.
I appreciate any further hints or workarounds.
Thank you,
Usman.
Well, you can use
screen -S psql -p 0 -X stuff $'\n'
or better (works for me)
screen -S mname -p 0 -X stuff `echo -ne '\015'`
-p 0 is needed to select the window.
Have you tried this to "press enter" after your readreg and paste?
screen -S psql -X stuff $'\n'
FINAL ANSWER: It is a bug/feature in 'GNU screen' that it needs a DISPLAY atleast once for 'paste' command to work. Following are possible workarounds this problem:
Finally figured out how to utilise psql with pipes and screen. Here is the solution:
mkfifo psql.pipe
screen -L -c ./customrc -S psql -d -m bash -i -c "while (true); do cat psql.pipe; done | /opt/PostgreSQL/9.0/bin/psql -a"
After that, I can cat my commands to the pipe:
cat ./mycommands.sql > psql.pipe
To quit from screen and terminating psql, I used
screen -S psql -X quit
EDIT: (finally) figured out the solution for my problem without using screen command. Meet 'empty' utility.
empty -f -i psql.in -o psql.o -p psql.pid <psqlpath>
This allows psql to run in full interactive mode as opposed to the original solution that I used (in which psql does not run in interactive mode).
Thanks.
Usman
I had this same problem. My workaround was to launch screen attached but pass it a screenrc file where the last command is "detach"
So this is my screenrc
#change the hardstatus settings to give an window list at the bottom of the
#Set this first otherwise messes with bash profile
hardstatus alwayslastline
#screen, with the time and date and with the current window highlighted
#hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
#set scrollback
defscrollback 4096
#detach
detach
Hope this helps
P
According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify.
Here's my cofig:
# Default screens
screen -t "shell_0" 1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest
It will not run the autotest command. That window where I'm trying to run autotest just closes instantly when I start screen.
I also tried it with just...
screen -t "autotest" 2 cd ~/project/contactdb
Same result.
I also tried...
screen -t "autotest" 2 ls
Same result there too.
What's the secret to getting it to run a command in a given screen on startup?
Your program is being run (well, except the cd), it's just that it's being run without a parent shell, so as soon as it completes, it exits and you're done.
You could do:
screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest'
Spawns two shells, but life will probably go on.
Try this:
$ screen -S 'tailf messages' -d -m tailf /var/log/messages
Then later you can do:
$ screen -ls
1234.tailf messages
Followed by:
$screen -r 1234
This might help but may not be entirely what you want.
Put "zombie az" or "defzombie az" as the first line of your .screenrc. "az" can be whatever 2 keys you'd like. Now, when a screen ought to close (command finished executing, for instance), it won't actually close; hitting 'a' will close it, hitting 'z' will re-execute the command attached to that screen.
I found that at the screen user's manual.
You can also "stuff" characters into the screen as if you had typed them.
Here's how you can do that with your example:
screen -t "shell_0" 1
# create the following screen in the desired dir, instead of cd-ing afterwards :)
chdir ~/project/contactdb
screen -t "autotest" 2
# (without this sometimes screens fail to start correctly for me)
sleep 5
# paste some text into screen number 2:
select 2
stuff "autotest\012"
Here's how mine looks. It seems to work fine. I think either the parenthesis might be causing the problem or screen will not open a window if the command "autotest" does not exist.
screen -t zsh 1
screen -t emacs 2 emacs -nw
screen -t mutt 3 mutt
monitor on
screen -t mc 4 mc -s
screen -t elinks 4 elinks
Here's how I'd do it.
screen -t shell_0
chdir ~/project/contactdb
screen -t autotest autotest
The above appears to be evaluated procedurally by screen. First we establish a new screen with the title shell_0. Since we gave no other options, current working directory will be that of the parent shell or the user's home directory. We then set the default directory for new screens to ~/project/contactdb. Next, we establish a new screen running the autotest command.
Window number (n) is optional, I generally omit it.