diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-04-16 20:03:14 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-04-19 18:38:58 -0700 |
commit | 2f8d0e9aba3662fcb1032ffe33bc6faf2e04eb8f (patch) | |
tree | dd98834c4104f74f02d745fc2e35034f8579dd65 /share/functions/__fish_toggle_comment_commandline.fish | |
parent | bd4622a0d01c7d882c37c46f6730567750dda657 (diff) |
add way to comment/uncomment a command
Fixes #2375
Diffstat (limited to 'share/functions/__fish_toggle_comment_commandline.fish')
-rw-r--r-- | share/functions/__fish_toggle_comment_commandline.fish | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/share/functions/__fish_toggle_comment_commandline.fish b/share/functions/__fish_toggle_comment_commandline.fish new file mode 100644 index 00000000..8bdd7e82 --- /dev/null +++ b/share/functions/__fish_toggle_comment_commandline.fish @@ -0,0 +1,17 @@ +# 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 +# opportunity to modify the command. + +function __fish_toggle_comment_commandline --description 'Comment/uncomment the current command' + set -l cmdlines (commandline -b) + if test "$cmdlines" = "" + return + end + set -l cmdlines (printf '%s\n' '#'$cmdlines | string replace -r '^##' '') + commandline -r $cmdlines + string match -q '#*' $cmdlines[1]; and commandline -f execute +end |