Skip to content

[feature] Place the cursor at a given place after an abbr #2287

Description

@Hettomei

Hi,

I love abbreviation, it always show me the right command.

But sometimes I need to put the cursor at a given place, is it possible to do that ?

Example :

abbr -a describe 'mysql -u root my_database -e "describe $CURSOR"'

and so, after typing "describe" I would like to have my cursor at $CURSOR

Thank you for this awesome shell ;)

Activity

  1. ridiculousfish commented on Aug 10, 2015

    @ridiculousfish
    Member

    Thanks for the kind words :)

    Is the idea that you want to have the cursor inside the closing quotes. That makes a lot of sense, and is something that global aliases definitely could not do. Do you have ideas for what the syntax for this could be?

    Also, what would you like or expect to happen if you press return after typing the abbreviation but before it expands? Today that expands and then executes it; maybe it should just expand it.

  2. added this to the fish-future milestone on Aug 10, 2015
  3. faho commented on Aug 10, 2015

    @faho
    Member

    Also, what would you like or expect to happen if you press return after typing the abbreviation but before it expands? Today that expands and then executes it; maybe it should just expand it.

    If I may interject - it's GNU/expands I'd like it if it just executed, or if at least there was an easy way to just execute what is written on the commandline.

    Today, I can't see a way to execute something called pm if I define that as an abbr for pulsemixer - or I'm just missing something.

  4. ridiculousfish commented on Aug 10, 2015

    @ridiculousfish
    Member

    @faho that is what happens today for abbreviations, and I think everyone likes that.

    But the idea here is a new mode, a sort of "abbreviation template," that expands and then puts the cursor somewhere for you to edit (in this case, presumably a table name). So the command doesn't make sense to run on its own.

    Here's another (not fully formed) idea: maybe abbreviations should just be functions:

    function describe --abbreviates
        mysql -u root my_database -e "describe $argv[1]"
    end
    

    and now the abbreviation itself takes an argument: describe some_table, which expands to: mysql -u root my_database -e "describe some_table"

    This also would let us use tab completion with abbreviations. This means abbreviations are starting to look just like functions - well, maybe that's a good thing.

  5. faho commented on Aug 10, 2015

    @faho
    Member

    @faho that is what happens today for abbreviations, and I think everyone likes that.

    It's not.

    $ abbr -s
    abbr pm pulsemixer
    $ type pm
    type: Could not find 'pm'
    $ pm #<ENTER>
    # launches pulsemixer
    

    Here's another (not fully formed) idea: maybe abbreviations should just be functions:

    That's just what alias does, isn't it? Or do you want it do be expanded when you enter it interactively? In that case, the function would need to be parsed for a "$argv" - and how would that work with multiple occurences of it?

    Instead, I'd rather have a "special token" for abbr, like

    abbr describe mysql -u root my_database -e "describe @"
    

    or, considering find and xargs as prior art "{}" - though of course there's a bug about that.

    If that token occurs, after expansion the cursor is placed at that position (with the token removed).

    The underlying assumptions are of course that the token will be reasonably uncommon (since it would need to be masked if it were to occur) and that there isn't much more functionality to add to abbr, so it makes sense not to generalize it much more.

  6. Hettomei commented on Aug 11, 2015

    @Hettomei
    Author

    Hi,

    Also, what would you like or expect to happen if you press return after typing the abbreviation but before it expands? Today that expands and then executes it; maybe it should just expand it.

    I see it like this :

    Case their is no $CURSOR (or something else) defined and user press enter
    -> same behavior as now

    Case their is no $CURSOR (or something else) defined and user press space
    -> same behavior as now

    Case their is a $CURSOR defined and user press enter
    -> expand the abbrev, put cursor on $CURSOR : no surprise, no error

    Case their is a $CURSOR defined and user press space
    -> expand the abbrev, put cursor on $CURSOR : no surprise, no error, delete the last space added by keyboard

  7. ByScripts commented on Sep 14, 2015

    @ByScripts
    Contributor

    Hope this will be integrated to fish.

    We plan to work with "GitFlow" git workflow and I'll set some abbreviations. But for some abbreviations, I need to place the cursor inside the command:

    • master => git checkout master
    • develop => git checkout develop
    • feature => git checkout -b feature-$CURSOR develop
    • release => git checkout -b release-$CURSOR develop
    • hotfix => git checkout -b hostfix-$CURSOR master

    This would allow typing quickly:

    • feature 21-add-product-details => git checkout -b feature-21-add-product-details develop
    • release 0.0.6 => git checkout -b release-0.0.6 develop
    • hotfix 12-unable-to-login => git checkout -b hotfix-12-unable-to-login master
  8. pickfire commented on Sep 14, 2015

    @pickfire
    Contributor

    fish currently doesn't use Git Workflow. In My Humble Opinion, the pros is stable developments, the cons is that it slows down developments, forcing developers to use develop branch, master branch currently doesn't not have a lot of bugs either. If the users need stable release, they can just use a fish release.

    What do you think?

    Sorry that I replied that stupid message.

  9. ByScripts commented on Sep 14, 2015

    @ByScripts
    Contributor

    I think you didn't understand my message ^^ I never talked about Fish workflow ;)

  10. pickfire commented on Sep 14, 2015

    @pickfire
    Contributor

    I am sorry that I didn't understand your message. I know what you mean now. I think you can just:

    • feature 21-add-product-details -> git checkout develop -b feature-21-add-product-details
    • release 0.0.6 -> git checkout develop -b release-0.0.6

    For example, abbr feature to git checkout develop feature- but the downside is that you need to press extra backspace. I just can't figured out how to put a backspace into the abbr, using \b doesn't work.

    In addition, I think you can also create a function to just feature 21-add-product-details.

  11. dmsmidt commented on May 1, 2017

    @dmsmidt

    I'm also interested in creating abbreviations where you can define the final caret position. My use case is similar to what @pickfire describes above (need to get rid of the space after expanding).
    Is there any progress on this?

  12. cmarqu commented on Aug 21, 2017

    @cmarqu
    Contributor

    If I define an abbr like abbr -a svnci 'svn commit -m ""', it would be enough for me to have something like a post-abbr function that moves the cursor one position to the left to end up inside the double quotes.
    A caret marker saying "please let the cursor end up here" would be a bit overkill IMO.

  13. laughedelic commented on Aug 21, 2017

    @laughedelic
    Contributor

    Hey @cmarqu, in the particular case of placing cursor between the quotes, you may be interested in using pisces plugin (I'm the author), then you can define your alias like abbr -a svnci 'svn commit -m', type first quote " and it will get autoclosed with the cursor staying inside 👌

    For the issue in general, there is a plugin with similar functionality: oh-my-fish/plugin-expand, it's like abbr but more advanced (I'm not using it myself, but it seems relevant here).

  14. shilangyu commented on Jul 7, 2019

    @shilangyu
    Contributor

    any progress on this?

  15. ridiculousfish commented on Jul 12, 2019

    @ridiculousfish
    Member

    Nobody is working on this AFAIK

  16. JeanMertz commented on Jan 8, 2020

    @JeanMertz
    Contributor

    I came across this while looking for a way to expand one of my abbreviations without having the extra whitespace added at the end. It seems that isn't possible right now, and this proposal would make that (and more) possible.

    Is there an appetite for a smaller scoped "expand without whitespace" feature in lieu of this one being implemented?

  17. franciscod commented on Jun 19, 2020

    @franciscod

    This would be super useful for pasting URLs on various commands.

    1. are there any other ways of "auto-quoting" a pasted URL?
    2. what would be a good starting point to work on this from a fish outsider?
  18. faho commented on Jun 19, 2020

    @faho
    Member

    are there any other ways of "auto-quoting" a pasted URL?

    Paste it inside of single-quotes:

    curl '

    then paste. This will escape all ' and \, so you can just close the quote after. (or close it before and move the cursor inside)

  19. rien333 commented on Feb 14, 2021

    @rien333

    Is there an appetite for a smaller scoped "expand without whitespace" feature in lieu of this one being implemented?

    I would really like such an option, actually (lets denote it -X). For example. it would be cool if you could use abbreviations to construct paths:

    # I sometimes need to call binaries from /usr/local/bin/ 
    abbr -X -a -- ul /usr/local/bin/

    Or to construct abbreviations for programs that require an single argument without any spaces:

    # search bibliography based on either author or title
    abbr -X -a -- pla 'pubs list author:'
    abbr -X -a -- plt 'pubs list title:'
  20. krobelus commented on Feb 14, 2021

    @krobelus
    Contributor

    abbr -X -a -- ul /usr/local/bin/

    You can use a key binding, let's say Alt+AAlt+U
    bind \ea\eu 'commandline -i /usr/local/bin/'

  21. peey commented on May 8, 2021

    @peey

    Another use case: when using fish's begin and end to set environment variables just for the command, this feature would be useful to place the cursor before end

  22. ElijahSink commented on Aug 6, 2021

    @ElijahSink

    Is anyone working on this, either the -X (no whitespace) option, or the cursor movement feature? I might take a crack at it.

  23. faho commented on Aug 6, 2021

    @faho
    Member

    I am not aware of anyone working on it.

  24. krobelus commented on Dec 17, 2022

    @krobelus
    Contributor

    this is now implemented by the new abbr --set-cursor switch from #9313

  25. locked as resolved and limited conversation to collaborators on May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions