{"id":317,"date":"2009-05-22T19:32:16","date_gmt":"2009-05-22T23:32:16","guid":{"rendered":"http:\/\/www.timelordz.com\/blog\/?p=317"},"modified":"2009-05-26T10:45:56","modified_gmt":"2009-05-26T14:45:56","slug":"brilliant-bash-profile-functions","status":"publish","type":"post","link":"https:\/\/www.timelordz.com\/blog\/2009\/05\/brilliant-bash-profile-functions\/","title":{"rendered":"Brilliant Bash Profile Functions"},"content":{"rendered":"<p>Whilst perusing about, I chanced upon these <a title=\"Great Bash Functions\" href=\"http:\/\/bbs.archlinux.org\/viewtopic.php?pid=416977\" target=\"_blank\">great bash functions<\/a> (original author unknown) which you and place in your .bashrc\u00a0 They are a great example of how simple it can be to define a function in Bash and are actually pretty useful. First some examples of the output:<\/p>\n<p><span style=\"color: #33cccc;\">paracelsus@Callandor:~&gt; weather London<br \/>\nWeather for London, UK 59\u00b0F Current: Cloudy Wind: W at 9 mph Humidity: 67%<\/span><\/p>\n<p><span style=\"color: #33cccc;\">paracelsus@Callandor:~&gt; translate cat japanese<br \/>\n&#8220;cat&#8221; in Japanese:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u732b<\/span><\/p>\n<p><span style=\"color: #33cccc;\">paracelsus@Callandor:~&gt; define haxor<br \/>\n* Leet or Eleet (sometimes rendered l33t, 1337, or 31337), also known<br \/>\n* A variant spelling of hacker in the leet argot<\/span><\/p>\n<p>Note that as a defined function auto completion of the initial call works too, which I didn&#8217;t know.<\/p>\n<p>The code to implement this is quite simple really and is the same as the site above, only I changed one line to update a reference so the translation function works:<\/p>\n<p>(Displayed in the nifty new <a title=\"wp-codebox\" href=\"http:\/\/wordpress.org\/extend\/plugins\/wp-codebox\/\" target=\"_blank\">wp-codbox<\/a> plugin I just installed.)<\/p>\n<pre lang=\"bash\"># richs-lxh needs to find rude words in other languages, define new groovy  words that the kids use nowadays, and see if it's sunny ; D\r\n\r\n# Weather by placename # weather \"Barcelona\"\r\nweather ()\r\n{\r\ndeclare -a WEATHERARRAY\r\nWEATHERARRAY=( `lynx -dump \"http:\/\/www.google.com\/search?hl=en&amp;lr=&amp;client=firefox-a&amp;rls=org.mozilla%3Aen-US%3Aofficial&amp;q=weather+${1}&amp;btnG=Search\" | grep -A 5 -m 1 \"Weather for\" | grep -v \"Add to \"`)\r\necho ${WEATHERARRAY[@]}\r\n}\r\n\r\n#Translate Spanish\/English  - USAGE: translate lamer spanish  # See dictionary.com for available languages (there are many).\r\ntranslate ()\r\n{\r\nTRANSLATED=`lynx -dump \"http:\/\/translate.reference.com\/browse\/${1}\" | grep -i -m 1 -w \"${2}:\" | sed 's\/^[ \\t]*\/\/;s\/[ \\t]*$\/\/'`\r\nif [[ ${#TRANSLATED} != 0 ]] ;then\r\n   echo \"\\\"${1}\\\" in ${TRANSLATED}\"\r\n   else\r\n   echo \"Sorry, I can not translate \\\"${1}\\\" to ${2}\"\r\nfi\r\n}\r\n\r\n# Define a groovy word - USAGE: define lamer\r\ndefine ()\r\n{\r\nlynx -dump \"http:\/\/www.google.com\/search?hl=en&amp;q=define%3A+${1}&amp;btnG=Google+Search\" | grep -m 3 -w \"*\"  | sed 's\/;\/ -\/g' | cut -d- -f1 &gt; \/tmp\/templookup.txt\r\n         if [[ -s  \/tmp\/templookup.txt ]] ;then\r\n            until ! read response\r\n               do\r\n               echo \"${response}\"\r\n               done &lt; \/tmp\/templookup.txt\r\n            else\r\n               echo \"Sorry $USER, I can't find the term \\\"${1} \\\"\"\r\n         fi\r\nrm -f \/tmp\/templookup.txt\r\n}<\/pre>\n<p>These function templates are great and provide examples from which all manner of interesting things could be made. Thanks to whomever originally contributed them!<\/p>\n<p>Cheers,<br \/>\nPete<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whilst perusing about, I chanced upon these great bash functions (original author unknown) which you and place in your .bashrc\u00a0 They are a great example of how simple it can be to define a function in Bash and are actually pretty useful. First some examples of the output: paracelsus@Callandor:~&gt; weather London Weather for London, UK [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":5,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.timelordz.com\/blog\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}