↓ Skip to main content
  1. Blog/

Bang-Bang (!!, !$) Shell Shortcuts in Elvish

·271 words·2 mins·
Diego Zamboni
Author
Diego Zamboni

(Updated on March 19th, 2018 to use the new Elvish Package Manager)

The bash shortcuts (maybe older? I’m not sure in which shell these originated) for “last command” (!!) and “last argument of last command” (!$) are, for me at least, among the most strongly imprinted in my muscle memory, and I use them all the time. Although these shortcuts are not available in Elvish by default, they are easy to implement. I have written a module called bang-bang which you can readily use as follows:

  • Use epm to install my elvish-modules package (you can also add this to your rc.elv file to have the package installed automatically if needed):

          use epm
          epm:install github.com/zzamboni/elvish-modules
  • In your rc.elv (see mine as an example), add the following to load the bang-bang module and to set up the appropriate keybindings:

          use github.com/zzamboni/elvish-modules/bang-bang

That’s it! Start a new shell window, and test how command-history mode can be invoked by the ! key. Assuming your last command was ls -l ~/.elvish/rc.elv, when you press ! you will see the following:

  bang-lastcmd [A C] _
  ! ls -l .elvish/rc.elv
  0 ls
  1 -l
  2/$ .elvish/rc.elv
  Alt-! !

If you press ! again, the whole last command will be inserted. If you press $ (or 2), only the last argument will be inserted. You can insert any other component of the previous command using its corresponding number. If you want to insert an exclamation sign, you can press Alt-!.

Note that by default, Alt-! will also be bound to trigger this mode, so you can fully replace the default “last command” mode in Elvish.

Have fun with Elvish!

Using and writing completions in Elvish

·3445 words·17 mins
Like other Unix shells, Elvish has advanced command-argument completion capabilities. In this article I will explore the existing completions, and show you how you can create your own (and contribute them back to the community!)

Elvish, an awesome Unix shell

·663 words·4 mins
I’m always on the lookout for new toys, particularly if they make my work more productive or enjoyable. For a couple of months now I have been using a little-known Unix shell called Elvish as my default login shell on macOS, and I love it.