diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 710e40c64..c204b20b1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ^^^^^^^^^^^^^^^^ diff --git a/share/functions/__fish_toggle_comment_commandline.fish b/share/functions/__fish_toggle_comment_commandline.fish index d6cba8445..5519d76a2 100644 --- a/share/functions/__fish_toggle_comment_commandline.fish +++ b/share/functions/__fish_toggle_comment_commandline.fish @@ -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