ble.sh icon indicating copy to clipboard operation
ble.sh copied to clipboard

Multi-line nano mode

Open SpiderUnderUrBed opened this issue 1 year ago • 6 comments

When you are writing a multi-line command. It would be useful if there was a option to use nano, I know some friends and people who I would recommend this too, who only use nano out of preference and its simplicity, so I would like it if there was a option to use nano for multi-line commands if there isnt it already.

SpiderUnderUrBed avatar Jan 17 '25 23:01 SpiderUnderUrBed

bash does this by default ctrl+x +e does this with EDITOR=nano but outside of ble-sh

personally I prefer EDITOR=nvim

Kreijstal avatar Jan 27 '25 19:01 Kreijstal

Yeah, and I actually realized that I broke C-x C-e in ble.sh in commit c395eb33 last month, but I wasn't sure if it was what the OP has asked. A tentative fix is here, but I am currently working on other parts of ble.sh in free time, so I'll push the fix after I finish them.

akinomyoga avatar Jan 27 '25 20:01 akinomyoga

Sorry for the delay. I pushed the fix for C-x C-e in commit https://github.com/akinomyoga/ble.sh/commit/cc47acc2767784fb4d413ea4abd8b209b7092788, though I'm not sure if this solves the OP's original request.

@SpiderUnderUrBed Could you describe your request in a bit more detail?

Bash's line editor and Nano are separate editors, so one cannot use the text editor Nano to edit the command inline. However, you might have just meant something like Nano-like keybinding in the line editor. In that case, you may change the keybindings using ble-bind as briefly described in README, or you can find the full description in the manual §3.

Or if you actually wanted to launch the text editor Nano and execute the command after closing the text editor Nano, you can use C-x C-e as @Kreijstal has explained. You can set EDITOR=nano in your ~/.bashrc, and you can press C-x C-e to start the text editor Nano.

akinomyoga avatar Feb 09 '25 12:02 akinomyoga

Hm, I was not aware of this functionality but it works, my fault for not reading the documentation. But, would it be possible for ble.sh to just use nano directly IF EDITOR was set to nano, which it was on my system, would this be a useful feature? I don't know if ble.sh had to make a custom implementation of vim to get it to work as is, but if not, then something simular can be done for nano.

SpiderUnderUrBed avatar Feb 09 '25 22:02 SpiderUnderUrBed

Thanks for you reply. I'm still very confused about your request. What do you mean by "use nano directly"? It sounds like requesting Vim to use Nano for text editing or requesting Emacs to use Nano for text editing.

I don't know if ble.sh had to make a custom implementation of vim to get it to work as is,

So, was your assumption that ble.sh would not implement the line editor but would call another text editor internally to somehow achieve the editing of the command line? That's not the case. ble.sh is a separate text editor like Readline, Emacs, Vim, etc. Essentially, you appear to request a text editor to use another text editor, which doesn't seem to make much sense, but maybe I'm misunderstanding your request.

Readline and ble.sh's emacs/vi editing modes do not use the text editors, Emacs or Vim, but they implement emacs/vim-like keybindings. Then, you can also achieve Nano-like keybindings with ble-bind as I described in my previous reply:

In that case, you may change the keybindings using ble-bind as briefly described in README, or you can find the full description in the manual §3.

There is currently no preset configuration for the nano-like keybindings (i.e., nano editing mode). We may add it, but we need to investigate dozens of key combinations of Nano, which I'm unfamiliar with, and convert the keybindings of the existing editing mode to the nano editing mode. Could you help me implementing that? As the first step, you can dump the keybindings of the emacs editing mode by the following command:

$ set -o emacs
$ ble-bind -m emacs -P > nano.bash

Then you can edit the file nano.bash to adjust the keybindings. Could you adjust the key combination after -f to reassign the key to each function? For example, to change the key of the pasting feature from C-y (Ctrl+y) to C-u (Ctrl+u), you can edit it in the following way:

--- nano.bash~^I2025-02-10 07:34:26.941477156 +0900
+++ nano.bash^I2025-02-10 07:34:42.617468175 +0900
@@ -122,7 +122,7 @@
 ble-bind -m 'emacs' -f 'C-x C-v' 'display-shell-version'
 ble-bind -m 'emacs' -f 'C-x C-x' 'exchange-point-and-mark'
 ble-bind -m 'emacs' -f 'C-x C-S-u' 'emacs/redo'
-ble-bind -m 'emacs' -f 'C-y' 'yank'
+ble-bind -m 'emacs' -f 'C-u' 'yank'
 ble-bind -m 'emacs' -c 'C-z' 'fg'
 ble-bind -m 'emacs' -f 'C-DEL' 'emacs/undo'
 ble-bind -m 'emacs' -f 'C-insert' 'copy-region-or copy-backward-uword'

To test the behavior, you can simply source nano.bash by running source nano.bash. After finishing it, could you send me your final version of nano.bash? If there would be additional functions that are available in Nano, but not in the existing emacs/vim editing modes, please also let me know that.

akinomyoga avatar Feb 09 '25 22:02 akinomyoga

I assume you are requesting a "nano editing mode", where ble.sh's keybindings are adjusted to be similar to Nano, (which doesn't use the Nano text editor itself, though). Another way is to mimic a nano editing mode of another shell, if any.

@SpiderUnderUrBed Are there any existing shells that implement nano editing modes? If so, we can port their keybindings including the ones specific to shell operations. It should be noted that the Nano text editor doesn't provide keybindings for shells, so it doesn't tell us how we should set up the shell keybindings in the nano editing mode.

akinomyoga avatar Feb 12 '25 23:02 akinomyoga