this post was submitted on 29 Aug 2023
34 points (100.0% liked)

Linux

48052 readers
679 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Some time ago I found xonsh which is a python-based shell. It had really good multiline support, and I am searching for a shell with sameish multiline support as xonsh. Fish shell also has good multiline support, it is around the same level, but it is not posix compatible. I want a shell that has that kind of level of multiline, but zsh (bash is also fine) compatible.

Does anyone know of one?

edit: based on the replies, I get this is unclear. My problem with zsh is that if i press enter and it starts a new line, I can't get back to the prevous line, because a new prompt is started. In fish this is possible, all lines are one prompt. But, fish is not posix compatible. So, I guess I want a posix-compatible shell with fish-like lines (multiple line) editing. I wanted zsh support to keep using my custom oh-my-zsh prompt, but remaking it for a new shell is not a big problem. Sorry for being unclear.

edit 2: solution is here! Thanks to @[email protected] I started thinking and made the following: When on the first line, enter accepts and alt-enter inserts a newline. When not on the first line, enter inserts a newline and alt-enter accepts. Here is the code to put in your .zshrc:

# MULTILINE!!!
bindkey '^[e' push-line-or-edit

# enter accepts when only one line found, else creates newline
function _zle_ml_enter {
    if ! [[ $BUFFER == *$'\n'* ]]; then
        zle accept-line
    else
        zle self-insert-unmeta
    fi
}
zle -N _zle_ml_enter
bindkey '^M' _zle_ml_enter

# alt-enter accepts when more than one line found, else creates newline
function _zle_ml_meta_enter {
    if [[ $BUFFER == *$'\n'* ]]; then
        zle accept-line
    else
        zle self-insert-unmeta
    fi
}
zle -N _zle_ml_meta_enter
bindkey '^[^M' _zle_ml_meta_enter

edit:
changed if [[ "$BUFFERLINES" -le 1 ]]; then to if ! [[ $BUFFER == *$'\n'* ]]; then and if [[ "$BUFFERLINES" -gt 1 ]]; then to if [[ $BUFFER == *$'\n'* ]]; then for improving detection. Also added alt-e shortcut because I had that configured myself but forgot to add here.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 10 points 1 year ago (1 children)

Your use of "multiline" is not obvious to me.

Most multiline features are available, such as having multiple commands between if, elsif, else and fi is definitely possible (ditto similar constructs), and it's possible to extend commands over an explicit carriage return if the end of line is quoted with a backslash.

If you're talking about having Python-like whitespace-only indentation to specify the level of code, I'm not sure there is a shell like that, but if this is what you mean and you confirm, someone who knows better might be able to point us in that direction.

If you're seeking multiline comments, unfortunately most shells don't have this, but there are definitely ways to fool the shell into skipping portions of text. You would be better off with an editor that can insert a # at the beginning of multiple lines however, since that will guarantee that the shell won't accidentally try to process something in that comment block.

[–] [email protected] 0 points 1 year ago

ah, I updated the post to be clearer :).