DEV Community


Posted on

Hacking Fish Script In Emacs

What tools do you use when generate Insert SQL by CSV, calculate some data?
There're a lot of ways, like using text editor macros, writing shell scripts, typing manually.
Terms of reproducibility, I always write shell scripts in the junk file and share code as needed.

I think bash script is the most written script in the world, but the grammar is so old.
These days, zx script which grammar like JavaScript had published by google.
But we cannot use zx as a login shell, so I think we should not use it.

Fish script which grammar like Ruby is easy to learn and people who use it as a login shell is a lot.
It's easy to execute code by copy code and paste into REPL.

This time, I write the article how to hack fish shell in Emacs.

My Emacs config is below.



(leaf fish-mode
  :ensure t
  (fish-enable-auto-indent . t)
  :mode ("\\.fish$"))
Enter fullscreen mode Exit fullscreen mode

fish-mode is an Emacs major mode.
This package has features of syntax highlight and indent calculation.

It should enable fish-enable-auto-indent flag that can indent automatically when insert end or else or case.


(leaf company-shell
  :ensure t
  (push 'company-fish-shell company-backends))
Enter fullscreen mode Exit fullscreen mode

company-shell is a company-mode plugin, which is completion library.

Internally, the implementation of insert candidates is fetching fish script's functions by functions -a builtin -n.

2021/09/26 Today, It's heavy to show completions.

It's seems that whatis command is slow, and it's not necessary information.
So I tried to fork this repository and create company-shell-meta-enable variable to disable it.

Let you clone my repository by el-get.

(leaf company-shell
  :el-get (company-shell
           :url ""
           :features company-shell)
  (push 'company-shell company-backends)
  (push 'company-shell-env company-backends)
  (push 'company-fish-shell company-backends))
Enter fullscreen mode Exit fullscreen mode


(leaf fish-repl
  :el-get (fish-repl.el
           :url ""))
Enter fullscreen mode Exit fullscreen mode

This REPL library is my work.
This repository enables you to do REPL driven development.

It can send codes in buffer to Fish REPL.
It's still a work in progress, so I want to develop based on nodejs-repl.


(leaf ob-fish
  :el-get (ob-fish
           :url ""))

(leaf ob-babel
  :after (ob-fish)
  (org-babel-do-load-languages 'org-babel-load-languages
                               '((fish . t))))
Enter fullscreen mode Exit fullscreen mode

This library is my work too.

I store some org files which I wrote fish script in the past.

#+begin_src fish
function say_hello
    echo Hello $argv

say_hello "world"

  : Hello world
Enter fullscreen mode Exit fullscreen mode


yasnippet is power-full snippet plugin.
yasnippet-snippets plugin has a lot of fish-mode snippets.

I recommend that you may manage snippet by org file.


Fish script is easy to learn and write, so why don't you use it?

Top comments (0)