Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abbreviations for subcommands #6283

Closed
bessey opened this issue Nov 4, 2019 · 6 comments
Closed

Abbreviations for subcommands #6283

bessey opened this issue Nov 4, 2019 · 6 comments

Comments

@bessey
Copy link

bessey commented Nov 4, 2019

fish version: 3.0.0
OS: MacOS X 19.0.0

This is a feature proposal for abbreviation support for, for lack of a better term, subcommands. Similar but not the same as #5003. By subcommands I mean status in git status and get in kubectl get

I find abbreviations super useful for amongst other things pair programming, saving on typing while keeping what is actually going on clear to the passenger, but I wish the following were possible:

I configure the following abbreviations:

abbr --add g git
abbr --add --scope=git co checkout
abbr --add --scope="git checkout" m master

I write g co m
I get git checkout master, with each word expanding at the space

If scoping simply meant "the scoped word must be to the left of the currently being written word for abbreviations to be considered" then this would allow for DRYing up shared arguments e.g.

abbr --add g git
abbr --add --scope=git co checkout
abbr --add --scope=git r rebase
abbr --add --scope=git m master  # note I didn't scope this to  "git checkout" like above

# so now
g r m # becomes
git rebase master

g co m # becomes
git checkout master

Thoughts?

@krobelus
Copy link
Member

krobelus commented Nov 4, 2019

Makes sense. Future global abbreviations could have a condition flag (like complete --condition/-n) to support this.

What you can do right now is override some bindings:

bind ' ' my-expand
bind \r 'my-expand execute'
bind \n 'my-expand execute'

where my-expand can be defined in ~/.config/fish/functions/my-expand.fish like below

function my-expand
   set -l first_token (commandline -opc)[1]
   set -l current_token (commandline -ct)
   set -l exp
   switch $first_token
   case git
       switch $current_token
       case co; set exp checkout
       case r;  set exp rebase
       case m;  set exp master
       end
   case kubectl
       # ...
   end
   if string length -q -- $exp
       commandline --replace --current-token $exp
   end
       
   if string match -q execute $argv
       commandline -f execute
   else
       commandline --insert ' '
       commandline -f expand-abbr
   end
end

@zanchey zanchey added this to the fish-future milestone Nov 8, 2019
@equwal
Copy link

equwal commented Nov 10, 2019

If you are going to add these things, you may as well also add expansion at any location not the beginning of the line (issue #6309 now).

@markstos
Copy link
Contributor

I also use "git ci" as an abbreviation for "git commit" and am interested in having tab completion with command and sub-command abbreviations.

@faho
Copy link
Member

faho commented Nov 11, 2019

Duplicate of #5003

@faho faho marked this as a duplicate of #5003 Nov 11, 2019
@faho faho closed this as completed Nov 11, 2019
@faho faho removed this from the fish-future milestone Nov 11, 2019
@bessey
Copy link
Author

bessey commented Nov 11, 2019

I disagree that this is a duplicate of #5003 as I explained in the OP. You might wish for a sub-command to expand to different abbreviations depending on the root command.

@equwal
Copy link

equwal commented Nov 11, 2019

I disagree that this is a duplicate of #5003 as I explained in the OP. You might wish for a sub-command to expand to different abbreviations depending on the root command.

You might want that, though it seems far too complicated for an abbrev system. Use a function instead?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants