brownbetty: Tim gazes upon Dick's manly chest.  "Wow!" (Wow)
[personal profile] brownbetty posting in [community profile] command_liners
[personal profile] pixel's post below reminded me that I have meant to post this for a while: Screen! Screen seems sort of like the secret weapon of command-line users; somehow it takes one ages to discover it, and if one is not far enough along in one's command-line usage, it just ends up seeming sort of mean-spirited and baffling. It's documented, but it's such a swiss-army knife that it's easy to get lost in the maze of documentation. However, at a certain level of usage, it suddenly becomes the most useful program ever.

So I wanted to ask people their favourite things to do with screen, and to share their .screenrc files, where they've modified them in interesting ways.

I still remember that happy day when I discovered that screen could monitor a background window, and tell me when it changed or stopped changing. The latter was the revolutionary one, for me; I could start something enormous compiling, and then neglect it, secure in the conviction screen would let me know when it finished. If your keybindings are standard, "ctrl-a, _" will monitor for silence, and "ctrl-a, m" will monitor for change/movement.

My screenrc is very lightly customized, a relic of my old machine which would barf and die if asked to update screen too often, but I like it. The interesting entry is
caption always "%{= kw} %-Lw [%n-%f %t] %+Lw %?@%u%?%? [%h]%?"
This gives me a strip at the bottom of the session which lists my windows by name and number, ferrinstance, at this moment:
[0-$ bash]   1$ newsbeuter  2-$ mutt  3$ rtorrent 
where the active window is in square brackets. Mutt has a hyphen after the window because it's the last active window, and the one I'd go to if I used "ctrl-a a" to return to my previous. If one of my windows had produced an alert, I'd get a "!".

You can do some really crazy stuff with the caption command, although the syntax is so arcane it requires years of study. I'm pretty sure most people copy someone else's and fiddle with it to get what they want, rather than attempt to write one from scrap.

Date: 2010-07-29 09:22 pm (UTC)
pixel: Dean fistpump, "Made of Win." (Supernatural) (supernatural: dean madeofwin)
From: [personal profile] pixel
Here, I'll bite. My favorite new use for screen is 'launching' all the fiddly bits of Rails development. So it starts my server, starts one version of spork for rspec, one for cucumber and then starts up autotest (which notifies lib-notify...) anyway, I spent a few days tweaking, but it's mostly still cribbed from elsewhere. Thought people might find it interesting with all the command line options screen has.
I've included my (dead simple) .screenrc too.
All at: http://gist.github.com/499251

I totally agree with you, it took years for me to see what the deal was with screen, and now...

Date: 2010-07-29 10:13 pm (UTC)
pixel: (losers: jensen huh?)
From: [personal profile] pixel
It isn't intuitively obvious to the casual observer but the problem is that it's SO flexible it defies simple explanation. I first ran into it while using irssi, where I liked the reconnect feature, but it wasn't obvious from that what else it could be good for.

Care to share more about this nesting concept? I'm not sure I quite get it. (Love the idea of different keybindings on a remote machine)

Date: 2010-07-30 12:38 pm (UTC)
pixel: Alec the geek. (Leverage) (leverage: hardison geek)
From: [personal profile] pixel
Still pretty slick, which reminds me I ought to tinker with my caption more....;)

Date: 2010-07-29 11:27 pm (UTC)
kerravonsen: 9th Doctor wearing his headlamp: Technical wizard (technical-wiz)
From: [personal profile] kerravonsen
Nifty thing to do with screen: controlling curses apps.
I use "randomplay" to play music (randomly, naturally). Unfortunately, it isn't one of those command-line apps where you can send commands to the daemon by typing a new command. It's a curses app, where you type commands in the terminal it's running in. However, I discovered a little-known thing about screen: one can pipe characters to its command buffer. Which means that one can write a script to send commands to a curses app which is running inside screen. Which means that one can use something like "xbindkeys" to bind a function key to call a script to send commands to a curses app running in screen! Yes, it all sounds a bit like "The House that Jack Built", but it means that I can use my nice multimedia keyboard to control my music-playing, rather than having to grovel around with multiple mouse-clicks when I want to pause my music because the phone rings.

This is the screen session for randomplay:

source $HOME/.byobu/profile
sessionname play
screen -t play 1 randomplay


This is the "sendplay" script:

#!/bin/zsh
# send commands to the "play" screen session
COMMAND=$1
shift
CMD_BUFFER=/tmp/screen-exchange
SESS=play
WIND=1

case $COMMAND in
next|fore*)
        echo -n f >$CMD_BUFFER
        ;;
prev|back*)
        echo -n b >$CMD_BUFFER
        ;;
*pause|*play)
        echo -n p >$CMD_BUFFER
        ;;
help)
        echo -n h >$CMD_BUFFER
        ;;
more|plus)
        echo -n + >$CMD_BUFFER
        ;;
less|minus)
        echo -n - >$CMD_BUFFER
        ;;
stop|quit)
        echo -n q >$CMD_BUFFER
        ;;
start)
        screen -d -m -c $HOME/.byobu/play
        exit
esac

screen -S $SESS -X select $WIND
screen -S $SESS -X readbuf
screen -S $SESS -X paste .
screen -S $SESS -X redisplay


And here are the relevant bindings in my .xbindkeysrc:

"sendplay prev; omessage '<< prev'"
  XF86AudioPrev

"sendplay less; omessage 'weight--'"
  Control + XF86AudioPrev

"sendplay next; omessage 'next >>'"
  XF86AudioNext

"sendplay more; omessage 'weight++'"
  Control + XF86AudioNext

"sendplay stop; omessage 'stop |#|'"
  XF86AudioStop

"sendplay toggleplay; omessage 'P/P >||'"
  XF86AudioPlay

"sendplay start; omessage 'play >'"
  Control + XF86AudioPlay

Date: 2010-07-30 12:40 pm (UTC)
pixel: Will's smile, "Sweet!" (Pirates of the Carribean) (potc: will sweet)
From: [personal profile] pixel
This is very cool. If I used something besides Pandora/Slacker I'd be all over it.

Date: 2010-07-30 09:47 am (UTC)
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
From: [personal profile] pne
screen could monitor a background window, and tell me when it changed or stopped changing.

It can? That's pretty amazing.

As are some of the other things people have shared here.

Wow.

Date: 2010-08-03 09:03 pm (UTC)
sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)
From: [personal profile] sophie
My caption setting:

caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c"

This highlights the screen name at the bottom that you're in, which I find much easier to see. It also puts the hostname and date/time of your host on the bottom-right. Of course, it's not actually "mine"; as you said, it's one I got somewhere and tweaked.

Profile

command_liners: A command line prompt with a blinking cursor after it, green against black. (Default)
Command Liners

January 2022

S M T W T F S
      1
2 345678
9101112131415
16171819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 6th, 2025 11:48 am
Powered by Dreamwidth Studios