Skip to content

Abbreviations #731

@dag

Description

@dag

Introduce abbreviations as an alternative to aliases, possibly replacing them.

Abbreviations are exactly like aliases, except they're expanded into their full form live as you type them on the commandline. Say you have gc as an abbreviation for git commit; now if you type gc -am "did stuff" the commandline changes when you type the space after "gc" and finally ends up as git commit -am "did stuff". This should only happen in command position, and when you type a space or hit enter.

Original text follows:

Replace aliasing with self-expanding short forms

I don't know what to call these but anyway. The idea is that if you type "g" as a command it expands to "git" when you type a space or enter.

Arguments for:

  • It solves many of the issues with completions. Since the alias expands "live", the git completions work as normal and commandline doesn't have to lie or do any other hacks like that.
  • It's easy to implement. I can kinda do it with bind and commandline although I didn't try to write a complete implementation. We don't need any changes to function or complete etc, as in other proposed solutions.
  • It's arguably "fishy": the user can see the expanded form, it's not hidden in an alias; it's instant and live, similar to completions, prompt repainting with prevd-or-backward-word etc.
  • When copy-pasting a command-line for instructions to others, it won't be full of your custom aliases that they have no knowledge of.
  • You can edit the expanded form if it's only almost-right.

Arguments against:

  • Doesn't solve the problem with alias git=hub, a problem that doesn't currently exist but is introduced with some alias completion proposals such as this one. However you can simply write a normal function function git; hub $argv; end instead to side-step this proposed alias system.
  • Some might find it surprising to have the command-line change as you type, without pressing anything like Tab or such.
  • The reason you can edit the expanded form is also the reason you can't delete what you typed with simply two backspaces. Even CTRL-W might not be enough as you might have gc expand to git commit for example. CTRL-U will do if it's the only command but it will delete too much if you're using the alias for a pipe for example. Perhaps we could introduce a new binding for "kill current command but not whole buffer".

Prior art:

  • :abbreviate in Vim
  • I think maybe search engines in Chrome?

Discuss.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions