When using the linux screen, vi editor overwrites all console information. I expect vi to open the file as a separate window and on exit, it has to return back to console.
My .screenrc is,
################
#
# default windows
#
screen -t screen1 1
screen -t screen2 2
screen -t screen3 3
screen -t screen4 4
screen 1
# caption always "%3n %t%? #%u%?%? [%h]%?%=%c"
# hardstatus alwaysignore
# hardstatus alwayslastline "%Lw"
#hardstatus string "[screen %n]:%h"
hardstatus on
hardstatus alwayslastline
hardstatus string '%{= wk}%-w %{bw} [ %n %t ] %{Kd}%+w %-= %{KY} | %D %M %d %Y% | %C %A %{-} '
#caption always
#caption string "%{= bW}%3n %{y}%t %{-}%= %{m}%H%?%{-} -- %{c}%l%?%{-} -- %D %M %d %{y}%c"
#term screen-256color
attrcolor b ".I" # allow bold colors - necessary for some reason
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm' # tell screen how to set colors. AB = background, AF=foreground
defbce on # use current bg color for erased chars
vbell off
Screen does that. When opening a vi editor in screen, it will appear on the screen pushing back all the log on the console. Also, you cannot scroll back while checking a log on screen for similar reason.
However, every screen has a log file. It logs to screenlog.%n by default, where %n is the screen window number. In your .screenrc file, you can check/change this log file's path.
To start logging, start the screen using screen -L command.
To emulate what you need, open a new terminal tab and do a tail -f screenlog.0. This will give you the live updated log from your screen.
---Edit---
If you're comfortable with shifting to a new application, try tmux. It should do exactly what you need. Read this for more info.
Related
I have this script here:
tmux send-keys "${#:1}" Enter
sleep 2.5; tmux capture-pane -p -S -32767
This script captures the tmux pane and prints the output. I noticed that if the tmux pane isn't opened, the output would look like this:
L 05/15/2018 - 16:07:43
: "thebravelittleMercen
ary<348><[U:1:313493299
]><Blue>" say "!resizem
ytorso"
BOI: !resizemyhands
L 05/15/2018 - 16:07:44
: "BOI<377><[U:1:453920
082]><Red>" say "!resiz
emyhands"
In reality, it should look like this:
L 05/15/2018 - 16:07:43: "thebravelittleMercenary<348><[U:1:313493299]><Blue>" say "!resizemytorso"
BOI: !resizemyhands
L 05/15/2018 - 16:07:44: "BOI<377><[U:1:453920082]><Red>" say "!resizemyhands"
It is worth mentioning that when I do tmux attach and capture the pane, the output lines have the same length as my console width: http://i.cubeupload.com/Rp1BEU.png
The output is "wrapped" in the pane, so you'll want to use:
capture-pane -J
-J joins wrapped lines and preserves
trailing spaces at each line's end.
↳ https://docs.oracle.com/cd/E86824_01/html/E54763/tmux-1.html
I often run Vim in a tmux session to I can run tests in an adjacent pane. On a smaller monitor, I either have to sacrifice more Vim screen real estate than I'd like, or make the test pane too small to read the full results (which is fine if everything passes, but not when there are failures and I need to see the details).
Then my workflow becomes:
trigger tests from within Vim
switch to test pane (last-pane)
zoom pane to occupy full window (resize-pane -Z)
read the results
restore original layout (resize-pane -Z)
switch back to Vim pane (last-pane)
I wanted to add a key binding that I could use when I'm in the Vim pane to zoom the test pane (hiding Vim), and be able to use the same binding once zoomed to restore the original layout, returning me to Vim. This is what I came up with, but I wonder if there's a better way I can do it. I had to set, check, and unset an environment variable to save the state that would support toggling back and forth with the same key binding. I also haven't figured out how to make the toggle state specific to a window (right now, any multi-window session shares the state across all its windows, so this doesn't work correctly)
bind Space if-shell '[ -z "${ALT_PANE_ZOOM+x}" ]' \
'select-pane -t :.+; resize-pane -Z; set-environment ALT_PANE_ZOOM 1' \
'set-environment -u ALT_PANE_ZOOM; last-pane'
Update:
I found a simpler solution. Rather than relying on a per-window environment variable, I can leverage -F and the window_zoomed_flag format variable:
bind Space if-shell -F '#{window_zoomed_flag}' \
'last-pane' \
'select-pane -t :.+; resize-pane -Z'
In your tmux.conf, create a keybind which:
Saves the zoom state
Switch to the last pane, unzooming if a pane was zoomed in
Conditionally zooms depending on the zoomed state in #1
-
bind key run-shell "tmux setenv zoomed $(tmux display -p '#{window_zoomed_flag}')"\; \
last-pane\; \
run-shell "test $(tmux display -p '#{zoomed}') -ne 0 || tmux resize-pane -Z"
Note that the backslash escapes on the semicolons command separators are required.
I want to change top panel color and alpha when any window is maximized.
For now I have something like this:
#!/bin/bash
while [ 1 = 1 ]
do
if window_is_maximized
then
xfconf-query -c xfce4-panel -p /panels/panel-0/background-alpha -s 100
else
xfconf-query -c xfce4-panel -p /panels/panel-0/background-alpha -s 50
fi
done
Maximized windows in X do not have a special state that you can test reliably. From a script, you can use xwininfo:
You can check if the window happens to be the same size as the root (main) window, and its position is the upper-left corner.
If you happen to be using a window manager which supports certain EMWH properties (_NET_WM_STATE_FULLSCREEN, _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ), your script could check for those. But in a quick check for window managers which might do that, I found none.
I'm looking for a way to display the active user for each window in a GNU screen session in its the hardstatus line.
Example
I have the following windows open
Window 0 - user1#localmachine
Window 1 - user1#localmachine
Window 2 - user1#localmachine SSH to user2#remotemachine
At the moment the hardstatus is:
0$ something [user1] 1$ something [user1] 2$ something [user2]
Where something [username] is typed in manually.
Is there any way to automatically display the windows current user?
You can use an escape sequence to set the window title, if that's what you want:
echo -e '\033k'$USER#$HOSTNAME'\033\\'
Just add this line to your .bashrc or similar file.
My xterm $prompt variable in my .tcshrc is:
set prompt="%{\033]0;%m:%~\007%}%{^[[;37;1m%}%B%{^[[;34;1m%}%m%{^[[;34;1m%}:%b%c%# "
The highlighted part above (%{\033]0;%m:%~\007%}) puts the hostname (%m) and the current directory (%~) in the title bar. (At least I think that that's what puts it in the title bar; it's been a while since I fiddled with this prompt).
When I run screen, however, the current directory stops getting updated when I change directories.
My questions:
How can I make this prompt work in screen?
Is there a better way to display the current directory in the title bar?
I am running linux with xterm and tcsh.
I think there is no direct way, because of the way screen works. However screen can display its own status bar, that you can define in .screenrc. Here's mine for instance :
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%=%{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
Firstly, to make it work you must check where exactly is the line with set prompt=blah-blah in your .tcshrc. For example, the code below that perfectly works in plain xterm would not work under screen in xterm:
switch ($TERM)
case "xterm*":
set prompt="%{\033]0;${HOME:t}#%m:%l:%c08\007%}%{\033[36m%}%l:%c02%#%{\033[0m%} "
# update xterm title to display current cmd in it
alias postcmd 'echo -n "\033]0;${HOME:t}#`hostname`:${tty} \!#:q\007"'
...
because screen by default sets $TERM variable to screen and not xterm! So you must add:
case "screen":
# lame, but prevents an error in screen after 'su - root'
if (! $?WINDOW) setenv WINDOW 1
set prompt="%{\033]0;${HOME:t}#%m:${WINDOW}:%c08\007%}%{\033[36m%}%c02%#%{\033[0m%} "
alias postcmd 'echo -n "\033]0;${HOME:t}#`hostname`:${WINDOW} \!#:q\007"'
...
Secondly, make sure yo have this line in ~/.screenrc:
termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'