{"id":1268,"date":"2007-11-03T02:08:48","date_gmt":"2007-11-03T00:08:48","guid":{"rendered":"http:\/\/vizZzion.org\/blog\/2007\/11\/konsole-tabs-on-steroids\/"},"modified":"2007-11-03T02:08:48","modified_gmt":"2007-11-03T00:08:48","slug":"konsole-tabs-on-steroids","status":"publish","type":"post","link":"https:\/\/vizZzion.org\/blog\/2007\/11\/konsole-tabs-on-steroids\/","title":{"rendered":"konsole tabs on steroids."},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/vizzzion.org\/images\/blog\/konsole-tabs.png\" alt=\"konsole with dynamic tab names.\" title=\"konsole with dynamic tab names.\" align=\"right\" class=\"showonplanet\" \/><br \/>\n    In the category <em>&#8220;little gems that make my life better&#8221;<\/em> (which in fact is synonym for <em>&#8220;Why<br \/>\n    everyone would be better off with the Z-Shell&#8221;<\/em>), today I&#8217;m reading from my .zshrc file. Zsh has<br \/>\n    those fine pre- and post-exec hooks. Those let you specify functions that are run before a command<br \/>\n    is executed, and right after. I&#8217;m using a tabbed konsole all of the time, with some DCOP magic,<br \/>\n    it&#8217;s easy to monitor your commands from another tab.<br \/>\n    But let the .zshrc script speak:<\/p>\n<pre>\n# Define colors\nBLACK=\"%{\"$'\\033[01;30m'\"%}\"\nGREEN=\"%{\"$'\\033[01;32m'\"%}\"\nRED=\"%{\"$'\\033[01;31m'\"%}\"\nYELLOW=\"%{\"$'\\033[01;33m'\"%}\"\nBLUE=\"%{\"$'\\033[01;34m'\"%}\"\nBOLD=\"%{\"$'\\033[01;39m'\"%}\"\nNORM=\"%{\"$'\\033[00m'\"%}\"\n\nif [ \"$KONSOLE_DCOP_SESSION\" ]\nthen\n        if [ `\/usr\/bin\/whoami` != 'root' ]\n                then\n                alias ssh='konsolewrap  ssh'\n                alias lftp='konsolewrap  lftp'\n                alias sftp='konsolewrap  sftp'\n                alias ssh='konsolewrap  ssh'\n                alias su='konsolewrap su'\n                alias ipy='konsolewrap ipython'\n        preexec () {konsole-rename-cmd $1}\n        precmd () {\n            konsole-rename-path\n            if [ `\/bin\/hostname` = 'luna' ]; then\n                RPROMPT=\"${BLUE}[${YELLOW}%*${NORM} `battery`${BLUE}]${NORM}\"\n            fi\n        }\n        fi\nfi\n    <\/pre>\n<p>    This involves two small scripts, konsole-rename-path and konsole-rename-cmd. Those basically<br \/>\n    change the name of the tab with a dcop call. konsole-rename-path looks like this:<\/p>\n<pre>\n#!\/bin\/bash\n# This small script renames the konsole tab to the current working directory\n\nif [ \"$KONSOLE_DCOP_SESSION\" ]\nthen\n    dcop `echo ${KONSOLE_DCOP_SESSION}` renameSession \"`echo $PWD | sed s,^$HOME,~,`\"\nfi\n    <\/pre>\n<p>    This is konsole-rename-cmd:<\/p>\n<pre>\n#!\/bin\/bash\n# This small script renames the konsole tab to the current command\n\nif [ \"$KONSOLE_DCOP_SESSION\" ]\nthen\n    dcop `echo ${KONSOLE_DCOP_SESSION}` renameSession \"$1\"\nfi\n    <\/pre>\n<p>    konsolewrap is for commands like ssh, tabs get the hostname in this case:<\/p>\n<pre>\n#!\/bin\/sh\ndcop $KONSOLE_DCOP_SESSION renameSession \"$*\"\nexec $cmd \"$@\"\n    <\/pre>\n<p>    This can of course all be neatified, but it does the job pretty well. I can start a job in<br \/>\n    one tab, switch to another, and I see the tabname change when the command is finished. This<br \/>\n    is somewhat similar to the &#8220;Monitor for Silence \/ Activity&#8221; in konsole, but a bit more<br \/>\n    flexible.<\/p>\n<p \/>\n    As you see, there&#8217;s also a variable set, RPROMPT. This produces a clock and the current<br \/>\n    battery charge state. In colors and all.<\/p>\n<pre>\nbattery(){\n        CBS=`acpi | awk '{print $4}' | awk -F % '{print $1}'`\n        if [[ ${CBS} -lt 35 ]] && [[ ${CBS} -gt 10 ]]; then\n                echo \"${YELLOW}${CBS}%%${NORM}\"\n        elif [[ ${CBS} -lt 10 ]] || [[ ${CBS} -eq 10 ]]; then\n                echo \"${RED}${CBS}%%${NORM}\"\n        else\n                echo \"${GREEN}${CBS}%%${NORM}\"\n        fi\n}\n    <\/pre>\n<p>    Low battery value, and the right hand side prompt&#8217;s battery percentage goes yellow, then red.<\/p>\n<p \/>\n    KDE4&#8217;s konsole has a very similar feature built in, so less fiddling with scripts in the<br \/>\n    future. :-)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the category &#8220;little gems that make my life better&#8221; (which in fact is synonym for &#8220;Why everyone would be better off with the Z-Shell&#8221;), today I&#8217;m reading from my .zshrc file. Zsh has those fine pre- and post-exec hooks. Those let you specify functions that are run before a command is executed, and right&hellip; <a class=\"more-link\" href=\"https:\/\/vizZzion.org\/blog\/2007\/11\/konsole-tabs-on-steroids\/\">Continue reading <span class=\"screen-reader-text\">konsole tabs on steroids.<\/span> <span class=\"meta-nav\" aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-1268","post","type-post","status-publish","format-standard","hentry","category-kde"],"_links":{"self":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/1268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/comments?post=1268"}],"version-history":[{"count":0,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/posts\/1268\/revisions"}],"wp:attachment":[{"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/media?parent=1268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/categories?post=1268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vizZzion.org\/blog\/wp-json\/wp\/v2\/tags?post=1268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}