Uncomment most recent comment if commandline is empty when using toggle comment binding (#7137)

* functions/__fish_toggle_comment_commandline: Uncomment most recent comment if commandline is empty

* Refactor variable setting in functions/__fish_toggle_comment_commandline.fish

* Update changelog regarding toggle comment binding
This commit is contained in:
Gokul Soumya 2020-06-24 22:05:36 +05:30 committed by GitHub
parent d0c1f2a2cc
commit 2fd78fd5c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -94,6 +94,8 @@ New or improved bindings
- ``__fish_prepend_sudo`` (Alt-S) now toggles a ``sudo`` prefix (#7012).
- ``__fish_prepend_sudo`` (Alt-S) now uses the previous commandline if the current one is empty,
to simplify rerunning the previous command with ``sudo`` (#7079).
- ``__fish_toggle_comment_commandline`` (Alt-#) now uncomments and presents the last comment
from history if the commandline is empty (#7137).
Improved prompts
^^^^^^^^^^^^^^^^

View file

@ -4,12 +4,13 @@
# retrieving the command from the shell history and removing the comment chars.
#
# This deliberately does not execute the command when removing the comment characters to give you an
# opportunity to modify the command.
# opportunity to modify the command. Also if the commandline is empty, the most recently commented
# out history item is uncommented and presented.
function __fish_toggle_comment_commandline --description 'Comment/uncomment the current command'
set -l cmdlines (commandline -b)
if test "$cmdlines" = ""
return
history search -p "#" -z | read -z cmdlines
end
set -l cmdlines (printf '%s\n' '#'$cmdlines | string replace -r '^##' '')
commandline -r $cmdlines