aboutsummaryrefslogtreecommitdiffhomepage
path: root/share
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-04-16 20:03:14 -0700
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2016-04-28 14:58:15 +0800
commitce41e3468ec77acb958de244f86ed65f6c5cbedf (patch)
treedc233deae0ec7949466281fe94622a4bc9feb984 /share
parent75064ed786ed41f962ac146a89102b4ce71f4e2f (diff)
add way to comment/uncomment a command
Fixes #2375 (cherry picked from commit 2f8d0e9aba3662fcb1032ffe33bc6faf2e04eb8f)
Diffstat (limited to 'share')
-rw-r--r--share/functions/__fish_toggle_comment_commandline.fish17
-rw-r--r--share/functions/fish_default_key_bindings.fish5
-rw-r--r--share/functions/fish_vi_key_bindings.fish8
3 files changed, 29 insertions, 1 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
diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish
index 8d86c7ee..c65cd49e 100644
--- a/share/functions/fish_default_key_bindings.fish
+++ b/share/functions/fish_default_key_bindings.fish
@@ -144,5 +144,8 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis
bind $argv \eOc forward-word
bind $argv \eOd backward-word
end
-end
+ # Make it easy to turn an unexecuted command into a comment in the shell history. Also,
+ # remove the commenting chars so the command can be further edited then executed.
+ bind \e\# __fish_toggle_comment_commandline
+end
diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish
index f6395667..2518ab74 100644
--- a/share/functions/fish_vi_key_bindings.fish
+++ b/share/functions/fish_vi_key_bindings.fish
@@ -224,4 +224,12 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish'
bind -M visual -m default \e end-selection force-repaint
set fish_bind_mode $init_mode
+
+ # Make it easy to turn an unexecuted command into a comment in the shell history. Also, remove
+ # the commenting chars so the command can be further edited then executed.
+ bind -M default \# __fish_toggle_comment_commandline
+ bind -M visual \# __fish_toggle_comment_commandline
+ bind -M default \e\# __fish_toggle_comment_commandline
+ bind -M insert \e\# __fish_toggle_comment_commandline
+ bind -M visual \e\# __fish_toggle_comment_commandline
end