In my zshrc I have an alias like this:
alias sl='screen -list'
It fits my need (seeing what screens I have running), but the output is rather ugly:
[pts/7]~% sl
There are screens on:
32765.quotes-api (04/26/2015 11:09:18 AM) (Detached)
5055.gitsync-test (04/07/2015 09:24:04 PM) (Detached)
15074.gitsync-interceptor (03/31/2015 10:39:45 AM) (Detached)
4662.eloquent-api (03/29/2015 11:37:26 AM) (Detached)
16177.Dropbox (03/17/2015 03:53:44 PM) (Detached)
18803.gitsync-todo-api-py (03/06/2015 08:21:24 AM) (Detached)
796.website (01/31/2015 01:56:02 PM) (Detached)
7874.gitsync-optionals (01/29/2015 02:27:24 PM) (Detached)
28474.linkbag (12/16/2014 09:56:39 AM) (Detached)
10839.datapump (10/13/2014 02:16:26 PM) (Detached)
5118.resr-api-python (09/13/2014 12:28:33 PM) (Detached)
7619.dataglobbing (09/03/2014 08:34:13 PM) (Detached)
10583.rest-api-dataglobbing (09/03/2014 01:06:21 AM) (Detached)
11705.save-functions (08/12/2014 01:00:58 PM) (Detached)
14 Sockets in /var/run/screen/S-tuvokki.
So I started to format this and got the following to kinda work:
screen -list|grep -v There|grep -v Sockets|awk 'BEGIN { format = " %-35s %-10s %s\n"
printf format, "Name", "Active", "Status"
printf format, "----", "------", "------" }
{ printf format, $1, $2, $5 }'
But how do I put this in an alias like the simple command I had before?
Just putting it all on one line does not work. I have tried to escape the quotes, use double quotes instead of single gave parse errors. I also tried to wrap it in a function, but it seems that the awk command relies on the newlines and doesn't like all the instructions to be on one line.
sl
package! ;)