Skip to content

Commit

Permalink
main (ble/bin/awk): add workaround for macOS awk-32
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 27, 2023
1 parent 10aa9b4 commit e2ec89c
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 92 deletions.
10 changes: 6 additions & 4 deletions README-ja_JP.md
Expand Up @@ -26,6 +26,7 @@
## 簡単設定

`ble.sh` をお使いいただくには Bash 3.0 以上 (及び POSIX の基本的なコマンド) が必要です。
<!-- 但し、macOS では附属の `/usr/bin/awk` (awk-32 以降) でマルチバイト文字セットの問題があるため、`gawk`, `nawk`, または `mawk` を別途インストールする必要があるかもしれません。 -->
`ble.sh` を取得するには主に2つの方法があります: `git` を用いてソースを取得しビルドする方法と `curl` または `wget` を用いて nightly ビルドをダウンロードする方法です。
詳細は、試用またはインストールに関しては [節1.1](#get-from-source)[節1.2](#get-from-tarball) を、
`~/.bashrc` の設定に関しては [節1.3](#set-up-bashrc) を御覧ください。
Expand All @@ -38,20 +39,21 @@
```bash
# 簡単お試し (インストールせずにお試しいただけます)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh

# インストール & .bashrc 簡単設定 (動かない場合は節1.3を御参照下さい)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc
```

生成過程では、複数のBashスクリプトファイルを結合することで `ble.sh` を生成し、
他の関連ファイルを正しく配置し、またソースコード中のコードコメントを削除してロードを最適化します。
生成過程は、C/C++ のコンパイルも伴わずバイナリも生成しませんので、コンパイラを準備していただく必要はありません。

※生成過程は、C/C++ のコンパイルも伴わずバイナリも生成しませんので、コンパイラを準備していただく必要はありません。
</details>

<details><summary><b><code>curl</code> を用いて nightly ビルドをダウンロード</b></summary>
Expand Down Expand Up @@ -126,7 +128,7 @@ bash /path/to/ble.sh --update
```bash
# ビルド & パッケージ作成用コマンド

git clone --recursive https://github.com/akinomyoga/ble.sh.git
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
```

Expand Down
17 changes: 7 additions & 10 deletions README.md
Expand Up @@ -11,7 +11,7 @@
*Bash Line Editor* (`ble.sh`) is a command line editor written in pure Bash which replaces the default GNU Readline.

Current devel version is 0.4.
This script supports Bash 3.0 or higher although we recommend to use `ble.sh` with release versions of Bash 4.0 or higher.
This script supports Bash 3.0 or higher although we recommend to use `ble.sh` with release versions of **Bash 4.0 or higher**.
Currently, only `UTF-8` encoding is supported for non-ASCII characters.
This script is provided under the [**BSD License**](LICENSE.md) (3-clause BSD license).

Expand All @@ -28,6 +28,7 @@ In fact, I personally call it simply /biːɛliː/ or verbosely read it as /biː
## Quick instructions

To use `ble.sh`, Bash 3.0+ and POSIX standard utilities are required.
<!-- In macOS, you might additionally need to install `gawk`, `nawk`, or `mawk` since macOS `/usr/bin/awk` (awk-32 and later) seems to have a problem with some multibyte charsets. -->
There are two ways to get `ble.sh`: to download and build `ble.sh` using `git`, or to download the nightly build using `curl` or `wget`.
For the detailed descriptions, see [Sec 1.1](#get-from-source) and [Sec 1.2](#get-from-tarball) for trial/installation,
and [Sec 1.3](#set-up-bashrc) for the setup of your `~/.bashrc`.
Expand All @@ -40,26 +41,24 @@ In the following, please replace `make` with `gmake` if your system provides GNU
```bash
# TRIAL without installation

git clone --recursive https://github.com/akinomyoga/ble.sh.git
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh

# Quick INSTALL to BASHRC (If this doesn't work, please follow Sec 1.3)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc
```

The build process integrates multiple Bash script files into a single Bash script `ble.sh`,
place other module files in appropriate places, and strip code comments for shorter initialization time.
This does not involve any C/C++/Fortran compilations and generating binaries, so C/C++/Fortran compilers are not needed.

<sup><sub>
[ Some people seem to bilindly believe that one always need to use `make` with C/C++/Fortran compilers to generate binaries.
Note: This does not involve any C/C++/Fortran compilations and generating binaries, so C/C++/Fortran compilers are not needed.
Some people seem to bilindly believe that one always need to use `make` with C/C++/Fortran compilers to generate binaries.
They complain about `ble.sh`'s make process, which comes from the lack of knowledge on `make`.
One should learn the general principle of `make`.

C/C++ programs in the repository is used to update the Unicode character table from the Unicode database when a new Unicode standard appears.
The generated table is included in the repository:
[`canvas.GraphemeClusterBreak.sh`](https://github.com/akinomyoga/ble.sh/blob/master/src/canvas.GraphemeClusterBreak.sh),
Expand All @@ -69,9 +68,7 @@ and [`canvas.emoji.sh`](https://github.com/akinomyoga/ble.sh/blob/master/src/can
so there is no need to run these C/C++ programs in the build process.
Another C file is used as an adapter in a old system MSYS1,
which is used with an old compiler toolchain in Windows, but it will never be used in Unix-like systems.

Each file used in the build process is explained in [make/README.md](make/README.md). ]
</sub></sup>
Each file used in the build process is explained in [`make/README.md`](make/README.md).
</details>

<details><summary><b>Download the nightly build with <code>curl</code></b></summary>
Expand Down
16 changes: 14 additions & 2 deletions ble.pp
Expand Up @@ -1088,9 +1088,21 @@ function ble/bin/awk/.instantiate {
_ble_bin_awk_type=unknown
fi
builtin eval "function ble/bin/awk { '${path//$q/$Q}' -v AWKTYPE=$_ble_bin_awk_type \"\$@\"; }" && ext=0
[[ $_ble_bin_awk_type == [gmn]awk ]] &&
! ble/is-function "ble/bin/$_ble_bin_awk_type" &&
if [[ $OSTYPE == darwin* && $path == /usr/bin/awk && $_ble_bin_awk_type == nawk ]]; then
# Note #D1974: macOS の awk-32 の multibyte character support が怪しい。
# 問題は GitHub Actions の上では再現できていないが特別の入力で失敗す
# るのかもしれない。または、報告者の環境が壊れているだけの可能性もあ
# る。テスト不可能だが、そもそも nawk は UTF-8 に対応していない前提な
# ので、取り敢えず LC_CTYPE=C で実行する。
function ble/bin/awk {
local LC_ALL= LC_CTYPE=C 2>/dev/null
/usr/bin/awk -v AWKTYPE=nawk "$@"; local ext=$?
ble/util/unlocal LC_ALL LC_CTYPE 2>/dev/null
return "$ext"
}
elif [[ $_ble_bin_awk_type == [gmn]awk ]] && ! ble/is-function "ble/bin/$_ble_bin_awk_type" ; then
builtin eval "function ble/bin/$_ble_bin_awk_type { '${path//$q/$Q}' -v AWKTYPE=$_ble_bin_awk_type \"\$@\"; }"
fi
fi
fi
return "$ext"
Expand Down
36 changes: 19 additions & 17 deletions docs/ChangeLog.md
Expand Up @@ -25,7 +25,7 @@
- keymap/vi: add `ble/keymap:vi/script/get-mode` for user-defined mode strings `#D1488` f25a6e8 462918d
- prompt: support multiline `prompt_rps1` `#D1502` 4fa139a
- canvas: fix wrong coordinate calculation on linefolding (reported by telometto) `#D1602` 9badb5f
- prompt: fix coordinates after `prompt_rps1` `#D1972` xxxxxxx
- prompt: fix coordinates after `prompt_rps1` `#D1972` e128801
- syntax: support tilde expansions in parameter expansions `#D1513` 0506df2
- decode: support `ble-bind -m KEYMAP --cursor DECSCUSR` (motivated by jmederosalvarado) `#D1514` `#D1515` `#D1516` 79d671d
- decode: reflect changes after `ble-bind --cursor` `#D1873` 39efcf9
Expand Down Expand Up @@ -64,7 +64,7 @@
- syntax: highlight quotes of the `\?` form `#D1584` 5076a03
- syntax: recognize escape \" in double-quoted strings `#D1641` 4b71449
- prompt: support a new backslash sequence `\g{...}` `#D1609` be31391
- prompt: accept more general `[TYPE:]SPEC` in `\g{...}` like `ble-face` `#D1963` xxxxxxx
- prompt: accept more general `[TYPE:]SPEC` in `\g{...}` like `ble-face` `#D1963` 81b3b0e
- complete: add a new option `bleopt complete_limit_auto_menu` `#D1618` 1829d80
- canvas: support grapheme clusters (motivated by huresche) `#D1619` c0d997b
- canvas (`ble/util/c2w`): use `EastAsianWidth` and `GeneralCategory` to mimic `wcwidth` `#D1645` 9a132b7
Expand All @@ -82,7 +82,7 @@
- prompt: fix hanging by a zero-width `prompt_ruler` `#D1673` 9033f29
- edit: support `bleopt canvas_winch_action` (requested by Johann-Goncalves-Pereira, guptapriyanshu7) `#D1679` 2243e91
- blerc: fix the name of the option `bleopt canvas_winch_action` (reported by Knusper) b1be640
- edit: go back to the previous lines with `redraw-here` more aggressively `#D1966` xxxxxxx
- edit: go back to the previous lines with `redraw-here` more aggressively `#D1966` a125187
- menu (menu-style:desc): improve descriptions (motivated by Shahabaz-Bagwan) `#D1685` 4de1b45
- menu (menu-style:desc): support multicolumns (motivated by Shahabaz-Bagwan) `#D1686` 231dc39
- menu (menu-style:desc): fix not working `bleopt menu_desc_multicolumn_width=` `#D1727` 2140d1e
Expand Down Expand Up @@ -120,12 +120,12 @@
- auto-complete: cancel auto-complete for `magic-space` `#D1913` 01b4f67
- complete: support ambiguous completion for command paths `#D1922` 8a716ad
- complete: preserve original path segments as long as possible `#D1923` `#D1924` e3cdb9d
- main: support `BLE_SESSION_ID` and `BLE_COMMAND_ID` `#D1925` 44d9e10 `#D1947` 46ac426 `#D1954` xxxxxxx
- main: support `BLE_SESSION_ID` and `BLE_COMMAND_ID` `#D1925` 44d9e10 `#D1947` 46ac426 `#D1954` 651c70c
- main: support an option `--inputrc={diff,all,user,none}` `#D1926` 92f2006
- util (`ble/builtin/trap`): support Bash 5.2 `trap -P` `#D1937` 826a275
- syntax: highlight `\?` in here documents `#D1959` xxxxxxx
- syntax: recognize history expansion in here documents, `"...!"` (bash <= 4.2), and `$!` (bash <= 4.1) `#D1959` xxxxxxx
- syntax: support context after `((...))` and `[[ ... ]]` in bash-5.2 `#D1962` xxxxxxx
- syntax: highlight `\?` in here documents `#D1959` e619e73
- syntax: recognize history expansion in here documents, `"...!"` (bash <= 4.2), and `$!` (bash <= 4.1) `#D1959` e619e73
- syntax: support context after `((...))` and `[[ ... ]]` in bash-5.2 `#D1962` 67cb967

## Changes

Expand Down Expand Up @@ -189,7 +189,7 @@
- edit (command-help): show source files for functions `#D1779` 7683ab9
- edit (`ble/builtin/exit`): defer exit in trap handlers (motivated by SuperSandro2000) `#D1782` f62fc04 6fdabf3
- util (`blehook`): fix a bug that the the hook arguments are lost (reported by SuperSandro2000) `#D1804` 479795d
- edit: fix a bug of `ble/builtin/exit` inside subshells in the `EXIT` trap `#D1973` xxxxxxx
- edit: fix a bug of `ble/builtin/exit` inside subshells in the `EXIT` trap `#D1973` 0451521
- complete (`source:command/get-desc`): show function location and body `#D1788` 496e798
- edit (`ble-detach`): prepend a space to `stty sane` for `HISTIGNORE=' *'` `#D1796` 26b532e
- decode (`bind`): do not treat non-beginning `#` as comments `#D1820` 65c4138
Expand Down Expand Up @@ -226,7 +226,7 @@
- canvas: update Unicode version 15.0.0 `#D1880` 49e55f4
- decode (`vi_imap-rlfunc.txt`): update the widget for `backward-kill-word` as `kill-backward-{u => c}word` `#D1896` e19b796
- term (`_ble_term_TERM`): detect wezterm-20220408 `#D1909` 486564a
- color: rearrange color table by `ble palette` (suggested by stackoverflow/caoanan) `#D1961` xxxxxxx
- color: rearrange color table by `ble palette` (suggested by stackoverflow/caoanan) `#D1961` bb8541d

## Fixes

Expand Down Expand Up @@ -364,7 +364,7 @@
- README: add a link to the explanation on the "more reliable setup" of bashrc (motivated by telometto) `#D1905` 09bb4d3
- README: describe `contrib/fzf` integration (reported by SuperSandro2000, tbagrel1) `#D1907` 3bc3bea b568ade
- README: add links to Manual pages for *kspec* and `modifyOtherKeys` `#D1917` fb7bd0b1 b568ade
- README: explain the build process `#D1964` `#D1965` xxxxxxx
- README: explain the build process `#D1964` `#D1965` 14ca1e5

## Optimization

Expand Down Expand Up @@ -468,6 +468,7 @@
- main: never load `/etc/inputrc` in openSUSE (motivated by Ultra980) `#D1926` 92f2006 0ceb0cb
- canvas: refine detection of `bleopt char_width_mode=musl` `#D1929` b0c16dd
- term (`terminology`): work around terminal glitches `#D1946` 9a1b4f9
- main (`ble/bin/awk`): add workaround for macOS `awk-32` `#D1974` xxxxxxx

## Test

Expand Down Expand Up @@ -537,7 +538,7 @@
- edit: update prompts on g2sgr change `#D1906` 40625ac
- util, decode, vi: fix leak variables `#D1933` 8d5cab8
- util: support `bleopt debug_idle` `#D1945` fa10184
- global: work around bash-4.4 no-argument return in trap `#D1970` xxxxxxx
- global: work around bash-4.4 no-argument return in trap `#D1970` eb4ffce

## Contrib

Expand All @@ -560,12 +561,13 @@
- histdb: kill orphan `sqlite3` processes `#D1943` 36e1c89
- histdb: back up the database `#D1944` 36e1c89
- histdb: fix miscellaneous SQL query errors `#D1947` 46ac426
- histdb: output error messages to tty `#D1952` xxxxxxx
- histdb: fix remaining debug function name "assign{2 => }" in bash <= 3.2 `#D1953` xxxxxxx
- histdb: fix a problem that the background process fails to start in bash-3.0 `#D1956` xxxxxxx
- histdb: fix a bug that history search fails with a single quote in the commandline `#D1957` xxxxxxx
- histdb: fix `histdb-word` completions in the middle of the commandline `#D1968` xxxxxxx
- histdb: support `bleopt histdb_remarks` `#D1968` xxxxxxx
- histdb: output error messages to tty `#D1952` 651c70c
- histdb: fix remaining debug function name "assign{2 => }" in bash <= 3.2 `#D1953` 651c70c
- histdb: fix a problem that the background process fails to start in bash-3.0 `#D1956` 651c70c
- histdb: fix a bug that history search fails with a single quote in the commandline `#D1957` 651c70c
- histdb: fix `histdb-word` completions in the middle of the commandline `#D1968` adaec05
- histdb: support `bleopt histdb_remarks` `#D1968` adaec05
- histdb: support timeout of background processes `#D1971` e0566bd
- integration: move `fzf` and `bash-preexec` integrations to subdir `#D1939` 86d9467

<!---------------------------------------------------------------------------->
Expand Down

0 comments on commit e2ec89c

Please sign in to comment.