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

__fish_prepend_sudo: Toggle "sudo" on multiple presses #7012

Merged
merged 2 commits into from May 17, 2020

Conversation

enricozb
Copy link
Contributor

At the moment calling __fish_prepend_sudo multiple times does not toggle
sudo, and also unnecessarily uses the -c flag to commandline to see if
the first token on the commandline is "sudo".

This change removes the -c switch and also toggles "sudo" on multiple
calls to __fish_prepend_sudo, while maintaining the cursor position and
while maintaining any spaces between "sudo" and the next token on the
commandline.

The additional logic around the new_cursor position is because the
cursor could be in the "sudo" during the toggle.

Description

Talk about your changes here.

Fixes issue #

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.md

At the moment calling __fish_prepend_sudo multiple times does not toggle
sudo, and also unnecessarily uses the `-c` flag to `commandline` to see if
the first token on the commandline is "sudo".

This change removes the `-c` switch and also toggles "sudo" on multiple
calls to __fish_prepend_sudo, while maintaining the cursor position and
while maintaining any spaces between "sudo" and the next token on the
commandline.
commandline -C 0
commandline -i "sudo "
commandline -C (math $cursor + 5)
else
commandline -r (string sub --start=6 (commandline -p))
set -l new_cursor (math $cursor - 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do the same with commandline -C -- (math $cursor - 5)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I can't believe I didn't think of this... any negative result of the math is being counted as an option to commandline that doesn't exist. Nice catch.

@krobelus krobelus added this to the fish 3.2.0 milestone May 17, 2020
@krobelus krobelus merged commit f10de5f into fish-shell:master May 17, 2020
@krobelus
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants