{"id":109,"date":"2009-06-05T00:22:56","date_gmt":"2009-06-04T13:22:56","guid":{"rendered":"http:\/\/christopherowen.id.au\/blog\/?p=109"},"modified":"2019-09-12T08:34:59","modified_gmt":"2019-09-11T22:34:59","slug":"bash-your-fish","status":"publish","type":"post","link":"https:\/\/christopherowen.au\/blog\/2009\/06\/05\/bash-your-fish\/","title":{"rendered":"Bash your Fish"},"content":{"rendered":"<p>I love shells. I spend an inordinate amount of every working day in one. That one happens to be Bash, arguably the most ubiquitous CLI shell in the world. It&#8217;s not bad at all, although sometimes I think CLIs could be so much more than they are today. Some <a href=\"http:\/\/directwebremoting.org\/blog\/joe\/2009\/05\/27\/command_lines.html\">other people agree too<\/a>, but that delectable future seems a little way off.<\/p>\n<p><!--more--><\/p>\n<p>An existing shell that aims to provide a better interactive experience is the <a href=\"http:\/\/fishshell.org\/index.php\">Friendly Interactive SHell &#8212; Fish<\/a>. I&#8217;ve recently started to spend some time with this shell although there is a problem with it: my collection of Bash functions that I&#8217;ve accumulated over the years in <kbd>.bashrc<\/kbd> are rendered impotent in this environment. Sure, I could spend some time and redefine them all in Fish&#8217;s shellscript dialect; or I could just abandon trying something new in the name of efficiency and laziness and head back to Bash. That does seem sad, and fortunately there is a way to bridge the gap.<\/p>\n<p>For other souls in a similar situation to me, here&#8217;s some script you can pop in your <kbd>~\/.config\/fish\/config.fish<\/kbd> (Fish&#8217;s equivalent to <kbd>.bashrc<\/kbd>)<\/p>\n<pre>function bash_env\n    set -x BASH_ENV ~\/.bash_functions\n    bash -c \"$argv\"\nend\n\nfor BASH_FUNCTION in (bash_env 'declare -F' | awk '{print $3}')\n    eval \"function $BASH_FUNCTION; bash_env $BASH_FUNCTION \\$argv; end\"\nend\n<\/pre>\n<p>You&#8217;ll need to change the <kbd>BASH_ENV<\/kbd> setting on the second line to point to the file where you declare your Bash functions. I&#8217;ve moved my functions out of <kbd>.bashrc<\/kbd> and into a separate file that I source from <kbd>.bashrc<\/kbd>. This is because I also source <kbd>\/etc\/bash_completion<\/kbd> from <kbd>.bashrc<\/kbd>, and that is quite a time consuming process to do every time you want to run a simple Bash function from Fish.<\/p>\n<p>Once that&#8217;s done, simply fire up Fish and type &#8216;functions&#8217;. You should see all of your old, dear Bash functions appear in the list, ready to aid you in your daily endeavours, just like times of old. Now, try the Fish!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve recently started to spend some time with the Fish shell, although there is a problem with it: my collection of Bash functions that I&#8217;ve accumulated over the years in <kbd>.bashrc<\/kbd> are rendered impotent in this environment. Fortunately there is a quick way to bridge the gap.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":""},"categories":[15,22],"tags":[35,38,44,48],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-nerd","category-software","tag-bash","tag-cli","tag-fish","tag-functions"],"_links":{"self":[{"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":1,"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":319,"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/posts\/109\/revisions\/319"}],"wp:attachment":[{"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/christopherowen.au\/blog\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}