{"id":319,"date":"2012-03-27T13:46:35","date_gmt":"2012-03-27T18:46:35","guid":{"rendered":"http:\/\/www.alandmoore.com\/blog\/?p=319"},"modified":"2012-03-27T13:58:42","modified_gmt":"2012-03-27T18:58:42","slug":"quick-google-search-in-awesome-window-manager","status":"publish","type":"post","link":"https:\/\/alandmoore.com\/blog\/2012\/03\/27\/quick-google-search-in-awesome-window-manager\/","title":{"rendered":"Quick google search in Awesome window manager"},"content":{"rendered":"<p>I&#8217;m back to using AwesomeWM on my work desktop; not sure what brought me back, but I will say that overall I prefer the way it handles multiple monitors and multiple desktops a little better than how KDE does it. \u00a0That, and KWin&#8217;s tiling mode is still useless with dual monitors even in 4.8.<\/p>\n<p>Something about running a window manager like Awesome makes you uber-sensitive to operations that require you to do a lot of mouse-maneuvering or manual window management, and thus encourages you to streamline these operations. \u00a0One such thing for me is searching google for something, an activity which I&#8217;m bound to do at least six dozen times during a workday, especially when developing (since I can&#8217;t remember API&#8217;s for squat).<\/p>\n<p>With a little help from a bash script and surfraw, I came up with a pretty cool solution.\u00a0<!--more--><\/p>\n<p>First, you need to install surfraw. \u00a0Surfraw is a command-line tool for searching different search engines; it&#8217;s available in the Debian and Ubuntu repositories. \u00a0Once installed, you can call it like this:<\/p>\n<pre LANG='BASH'>sr google bunch of search terms<\/pre>\n<p>And it will open a new tab in your browser (or open a browser, if need be) with the google search. \u00a0Of course, you don&#8217;t have to use google, as surfraw comes with a variety of other search options.<\/p>\n<p>You&#8217;ll also need wmctrl installed.<\/p>\n<p>Once those were installed, I created a script in my ~\/bin directory (which I&#8217;ve added to my path &#8212; you can of course put this script in \/usr\/local\/bin\/ or wherever) and called it &#8220;google_search.sh&#8221;:<\/p>\n<pre LANG='BASH'>#!\/bin\/bash\r\nterm=$@\r\nfoo=''\r\n#search with surfraw\r\nsr google $term\r\n#wait until the window exists and registers with the WM\r\nwhile [ -z \"$foo\" ]; do\r\n foo=$(wmctrl -l |grep -i \"$term - Google Search\")\r\n sleep .5\r\ndone\r\n#could use wmctrl -a, but it's not always reliable in awesome with dual screens\r\nwmctrl -r \"$term - Google Search\" -b add,demands_attention\r\necho \"awful.client.urgent.jumpto()\" |awesome-client<\/pre>\n<p>Basically this script does the following:<\/p>\n<ol>\n<li>assigns all arguments to a variable &#8220;term&#8221; <\/li>\n<li>runs surfraw with the search terms<\/li>\n<li>the while loop watches the window list for a window with your search terms and &#8220;Google Search&#8221; in the title<\/li>\n<li>Once it shows up, we mark the given window as &#8220;demands_attention&#8221; a.k.a. &#8220;urgent&#8221;<\/li>\n<li>Finally, we tell awesome to switch to the urgent client.<\/li>\n<\/ol>\n<p>As I noted in the script, on a single monitor situation I could just use &#8220;wmctrl -a&#8221; to switch to the window instead of doing all that urgent nonsense, but I&#8217;ve found that to be unreliable with dual monitors (e.g., sometimes it switches to the right tag, but on the wrong screen).<\/p>\n<p>Once I have this script somewhere in my $PATH, I add the shortcut to awesome, by adding these lines to the &#8220;globalkeys&#8221; table in my rc.lua:<\/p>\n<pre LANG='lua'>-- surfraw search\r\n awful.key({ modkey, }, \"g\",\r\n function()\r\n awful.prompt.run({ prompt = \"<span foreground='#7f9f7f'>Google Search:<\/span> \"},\r\n mypromptbox[mouse.screen].widget,\r\n function(input)\r\n awful.util.spawn_with_shell(\"google_search.sh \" .. input)\r\n end, nil\r\n )\r\n end\r\n ),<\/pre>\n<p>(Incidentally, you may want to remove or change the pango markup on the prompt to match your theme. I&#8217;m using zenburn, so it matches nicely).<\/p>\n<p>After restarting Awesome, Mod4-g gives me a prompt to do a google search. \u00a0Works a treat!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m back to using AwesomeWM on my work desktop; not sure what brought me back, but I will say that overall I prefer the way it handles multiple monitors and multiple desktops a little better than how KDE does it. \u00a0That, and KWin&#8217;s tiling mode is still useless with dual monitors even in 4.8. Something [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,5],"tags":[26,16,20,13,34],"class_list":["post-319","post","type-post","status-publish","format-standard","hentry","category-floss","category-general","category-technology","tag-awesome-wm","tag-floss-2","tag-how-to","tag-pointless-geekery","tag-practical-tech"],"_links":{"self":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts\/319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/comments?post=319"}],"version-history":[{"count":8,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":633,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/posts\/319\/revisions\/633"}],"wp:attachment":[{"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alandmoore.com\/blog\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}