{"id":499,"date":"2016-02-11T14:03:01","date_gmt":"2016-02-11T08:33:01","guid":{"rendered":"http:\/\/www.cyberaka.com\/?p=499"},"modified":"2016-02-11T14:06:04","modified_gmt":"2016-02-11T08:36:04","slug":"using-tput-to-label-tmux-panes","status":"publish","type":"post","link":"https:\/\/www.cyberaka.com\/?p=499","title":{"rendered":"Using tput to label tmux panes"},"content":{"rendered":"<p>As I had pointed out in my post about <a href=\"http:\/\/www.cyberaka.com\/?p=492\">tmux<\/a> that now I am using tmux to configure and debug multiple servers inside a single window split into panes. Now I ran to another problem I always forgot which pane was meant for which service. Beyond 2 to 3 panes it was getting confusing to remember which pane is monitoring which service. So I remembered my <a href=\"http:\/\/www.cyberaka.com\/?p=403\">previous post related to tput<\/a> which allows anybody to show a running clock inside a linux terminal. So I decided to provision a small shell script to fix this issue. Basically I wanted a way to label each pane so that I could effortlessly identify the purpose of the pane inside tmux. So here is the code:<br \/>\n<code><br \/>\n#!\/bin\/bash<br \/>\n#Display Service Name<\/p>\n<p>function die {<br \/>\n    echo \"Dying on signal $1\"<br \/>\n    exit 0<br \/>\n}<\/p>\n<p>function redraw {<br \/>\n  local width length;<br \/>\n  width=$(tput cols);<br \/>\n  str=$1;<br \/>\n  length=${#str}+10;<br \/>\n  tput sc;<br \/>\n  tput cup 0 $((width-length));<br \/>\n  set_foreground=$(tput setaf 7)<br \/>\n  set_background=$(tput setab 1)<br \/>\n  echo -n $set_background$set_foreground<br \/>\n  printf ' Service:%s ' $str<br \/>\n  tput sgr0;<br \/>\n  tput rc;<br \/>\n}<\/p>\n<p>trap 'die \"SIGINT\"' SIGINT<br \/>\ntrap 'die \"SIGQUIT\"' SIGQUIT<\/p>\n<p>trap redraw WINCH;<\/p>\n<p>while true; do<br \/>\n  redraw $*;<br \/>\n  sleep 1;<br \/>\ndone<br \/>\n<\/code><\/p>\n<p>This shell script takes a parameter and shows it on the top right column in a red background with white foreground. This script should be invoked in this way.<br \/>\n<code><br \/>\n.\/ShowTextInTerm.sh service-name &<br \/>\n<\/code><\/p>\n<p>Invoking this script in every tmux pane with relevant substitution for service-name is giving me this result:<br \/>\n<a href=\"http:\/\/www.cyberaka.com\/wp-content\/uploads\/Screen-Shot-2016-02-11-at-1.59.55-pm.png\" rel=\"attachment wp-att-500\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.cyberaka.com\/wp-content\/uploads\/Screen-Shot-2016-02-11-at-1.59.55-pm.png\" alt=\"Screen Shot 2016-02-11 at 1.59.55 pm\" width=\"299\" height=\"599\" class=\"alignnone size-full wp-image-500\" \/><\/a><\/p>\n<p>Please note that this script works well on my MacBook. I am yet to test it on a Linux terminal. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I had pointed out in my post about tmux that now I am using tmux to configure and debug multiple servers inside a single window split into panes. Now I ran to another problem I always forgot which pane was meant for which service. Beyond 2 to 3 panes it was getting confusing to [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,35,24],"tags":[49,53],"class_list":["post-499","post","type-post","status-publish","format-standard","hentry","category-linux-os","category-mac-os","category-tips-and-tricks","tag-tmux","tag-tput"],"_links":{"self":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=499"}],"version-history":[{"count":3,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":503,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions\/503"}],"wp:attachment":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}