ble.sh (Bash Line Editor)

repository·master·Indexed 26 days ago

https://github.com/akinomyoga/ble.sh

A command line editor written in pure Bash that replaces the default GNU Readline. It provides advanced features including syntax highlighting, enhanced completion, and Vim editing mode. The project includes tools for managing Unicode character-width tables, color themes, and integration with Bash configuration via .bashrc and .blerc.

Tokens
10K
Snippets
31
Records
57
Agent score
88%

What's inside ble.sh

  1. Overview of ble.sh features

    master

    ble.sh (Bash Line Editor) is a pure Bash command-line editor that replaces GNU Readline. Key features include:

    • Syntax Highlighting: Advanced syntax highlighting that understands nested structures and heredocs.
    • Enhanced Completion: Supports grammar-aware completion, parameter expansion-aware completion, fuzzy completion, menu completion, and auto-completion (for Bash 4.0+).
    • Vim Editing Mode: Enhances set -o vi with support for visual modes (line/block), replacement modes, text objects, registers, operators, and keyboard macros. Includes vim-surround extension.
    • Additional Features: Status lines, command history sharing, right prompts (rps1), transient prompts, and xterm title support.
  2. Install ble.sh to a directory

    master

    Use make install to install ble.sh. You can specify the installation directory using the INSDIR variable.

    By default, if no directory is specified, it installs to ${XDG_DATA_HOME:-$HOME/.local/share}/blesh.

    Available make variables:

    • INSDIR: The base installation directory.
    • INSDIR_LICENSE: Location for license files (defaults to $INSDIR/licenses).
    • INSDIR_DOC: Location for documentation files (defaults to $INSDIR/doc).
    • USE_DOC=no: Disables installation of documentation files.
    • strip_comment=no: Prevents stripping of comment lines and blank lines during installation.
  3. Update airline themes in the contrib repository

    master

    To update airline themes, follow these steps:

    1. Install vim-airline and vim-airline-themes using vim-plug.
    2. Create the output directory: mkdir -p out/data/airline.
    3. Open Vim and execute the following commands to dump the themes:
      :source make/vim-airline.DumpAirlineThemes.vim
      :call DumpAirlineThemeAll()
    4. Once finished, run the conversion script in a ble.sh session:
      (source make/vim-airline.ConvertAirlineThemes.sh)
  4. Install ble.sh

    master

    You can install ble.sh to a specific directory using make install.

    By default, if no directory is specified, it installs to ${XDG_DATA_HOME:-$HOME/.local/share}/blesh.

    Key Make variables:

    • INSDIR: The installation directory for the main ble.sh and related scripts. Defaults to $data/blesh.
    • INSDIR_LICENSE: Installation directory for licenses. Defaults to $INSDIR/licenses.
    • INSDIR_DOC: Installation directory for documentation. Defaults to $INSDIR/doc.
    • USE_DOC: Set to no to disable documentation installation.
    • strip_comment: Set to no to prevent the automatic removal of comment lines and empty lines during installation.
  5. Use `sabbrev` for static abbreviation expansions

    master

    You can register words to sabbrev to expand them into predefined strings. When the cursor is immediately after a registered word, pressing <Space> (SP) triggers the expansion.

    To avoid conflicts with real words in your commands, it is recommended to use names starting with a backslash (e.g., \L).

    Additionally, abbreviations starting with ~ can be expanded by pressing /. This is useful for creating shortcuts similar to Zsh's named directories.

  6. Build and package ble.sh for distribution

    master

    Since ble.sh is a collection of shell scripts, it is noarch. You can distribute it by downloading a tarball and placing it in a target directory. If you need to build it manually (requires the .git repository), use make install with DESTDIR and PREFIX.

    git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
    make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local
  7. Install ble.sh nightly build using curl

    master

    You can download and use the nightly build without a full build process. This requires curl, tar (with -J support), and xz.

    Trial without installation: Download the tarball, extract it, and source ble.sh from the extracted directory.

    Quick installation: Download, extract, and use the --install flag to specify a directory, then add the source command to your ~/.bashrc.

    # TRIAL without installation
    curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf -
    source ble-nightly/ble.sh
    
    # Quick INSTALL to BASHRC
    curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf -
    bash ble-nightly/ble.sh --install ~/.local/share
    echo 'source -- ~/.local/share/blesh/ble.sh' >> ~/.bashrc
  8. Use Multiline Mode

    master

    When the command line contains newlines, ble.sh enters MULTILINE mode.

    • Insert a newline: Use C-v C-j or C-q C-j to insert a newline as part of the command.
    • Execute command: In multiline mode, the RET (C-m) key inserts a new line instead of executing. Use C-j to execute the command.
    • Automatic behavior: If shopt -s cmdhist is enabled (default), RET will insert a newline if the command line is not syntactically closed.
  9. Update Unicode version in ble.sh

    master

    When a new Unicode standard is published, you must update the character-width and emoji support files.

    1. Update tables: Use make/canvas.c2w.generate-table.sh to regenerate canvas.GraphemeClusterBreak.sh, canvas.c2w.sh, and canvas.emoji.sh.
    2. Update detection codes: To identify new code points for testing Unicode version support, run make/canvas.c2w.list-ucsver-detection-codes.sh. Pick a code point from the output (e.g., from lines starting with verXX) and add it to the codes array in the shell function ble/util/c2w:auto/test.buff within src/canvas.sh. You must also update the corresponding tests in ble/util/c2w/test.hook.
  10. Use Auto-completion

    master

    For Bash 4.0+, ble.sh provides predictive auto-completion.

    • Accept suggestion: Press S-RET. (If at the end of the string, right, C-f, or end also work).
    • Partial acceptance: Press M-f or M-right to accept only the first word of the suggestion.
    • Accept and execute: Press C-RET (if supported by your terminal) to accept the suggestion and immediately run the command.
  11. Use `auto-complete` suggestions

    master

    If Bash 4.0 or later is used, auto-complete provides real-time suggestions.

    • Accept suggestion: Press S-RET (Shift+Enter) to insert the suggestion. If the cursor is at the end, right, C-f, or end also work.
    • Insert first word only: Press M-right or M-f.
    • Accept and execute: Press C-RET (Ctrl+Enter) to accept the suggestion and immediately run the command.