dundalek / closh

Bash-like shell based on Clojure
Eclipse Public License 1.0
1.62k stars 66 forks source link

Feature: User-defined Aliases, Abbreviations, Functions and Commands #12

Closed dundalek closed 6 years ago

dundalek commented 6 years ago

For user defined helpers I am thinking of supporting following:

Aliases

Aliases for defining / overriding functionality. When alias is used it does not get expanded and is saved into history as is.

Example:

(defalias ls "ls --color=auto")

Abbreviations

Abbreviations are similar to aliases but expand to underlying definition. Therefore autocomplete can work seamlessly and also full command is saved to history. Inspired by abbr in fish. See also discussion.

(defabbrev ga "git add")
(defabbr gaa "git add --all")

Functions

Classic Clojure functions, already works.

(defn hello [name]
  (str "Hello " name))

Run in command line like: (hello "World").

Commands

Similar to functions, but can be executed like commands without parens. Related to builtin commands. Defining similar to defn:

(defcmd hello [name]
  (str "Hello " name))

Run in command line like: hello World. There should probably also be a way to promote existing function to a command.

4mitch commented 6 years ago

Will it work like init.el in Emacs?

dundalek commented 6 years ago

@4mitch Currently we load ~/.closhrc on startup so users will be able to put these kinds of definitions there. So you could say it is similar to Emacs init (from my limited understanding of Emacs).

mnewt commented 6 years ago

@dundalek Have you started on this yet? If not, I can tackle it

dundalek commented 6 years ago

I do work on it, I have an work in progress branch here: https://github.com/dundalek/closh/tree/feature/custom-commands-aliases

dundalek commented 6 years ago

This is now ready in master branch.