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

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

Closed
Hettomei opened this issue Aug 10, 2015 · 23 comments
Closed

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

Hettomei opened this issue Aug 10, 2015 · 23 comments

Comments

@Hettomei
Copy link

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 ;)

@ridiculousfish
Copy link
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.

@faho
Copy link
Member

faho commented Aug 10, 2015

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.

@ridiculousfish
Copy link
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.

@faho
Copy link
Member

faho commented Aug 10, 2015

@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.

@Hettomei
Copy link
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

@ByScripts
Copy link
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

@pickfire
Copy link
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.

@ByScripts
Copy link
Contributor

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

@pickfire
Copy link
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.

@dmsmidt
Copy link

dmsmidt commented May 1, 2017

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?

@krader1961 krader1961 added the RFC label Jun 12, 2017
@cmarqu
Copy link
Contributor

cmarqu commented Aug 21, 2017

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.

@laughedelic
Copy link
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).

@shilangyu
Copy link
Contributor

any progress on this?

@ridiculousfish
Copy link
Member

Nobody is working on this AFAIK

@JeanMertz
Copy link
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?

@franciscod
Copy link

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?

@faho
Copy link
Member

faho commented Jun 19, 2020

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)

@rien333
Copy link

rien333 commented Feb 14, 2021

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:'

@krobelus
Copy link
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/'

@peey
Copy link

peey commented May 8, 2021

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

@ElijahSink
Copy link

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

@faho
Copy link
Member

faho commented Aug 6, 2021

I am not aware of anyone working on it.

@krobelus krobelus removed the RFC label Dec 17, 2022
@krobelus krobelus modified the milestones: fish-future, fish 3.6.0 Dec 17, 2022
@krobelus
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests