2016-04-17 11:03:14 +08:00
|
|
|
# This is meant to be bound to key sequences such as \e#. It provides a simple way to quickly
|
|
|
|
# comment/uncomment the current command. This is something introduced by the Korn shell (ksh) in
|
|
|
|
# 1993. It allows you to capture a command in the shell history without executing it. Then
|
|
|
|
# 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
|
2020-06-25 00:35:36 +08:00
|
|
|
# opportunity to modify the command. Also if the commandline is empty, the most recently commented
|
|
|
|
# out history item is uncommented and presented.
|
2016-04-17 11:03:14 +08:00
|
|
|
|
|
|
|
function __fish_toggle_comment_commandline --description 'Comment/uncomment the current command'
|
|
|
|
set -l cmdlines (commandline -b)
|
2022-08-02 15:30:06 +08:00
|
|
|
if test -z "$cmdlines"
|
2021-06-20 13:28:14 +08:00
|
|
|
set cmdlines (history search -p "#" --max=1)
|
2016-04-17 11:03:14 +08:00
|
|
|
end
|
|
|
|
set -l cmdlines (printf '%s\n' '#'$cmdlines | string replace -r '^##' '')
|
|
|
|
commandline -r $cmdlines
|
2016-11-28 13:27:22 +08:00
|
|
|
string match -q '#*' $cmdlines[1]
|
|
|
|
and commandline -f execute
|
2016-04-17 11:03:14 +08:00
|
|
|
end
|