diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 95984c33..03d44ae2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,6 +1,8 @@
# Contribution Guide
-## Issues
+## How to contribute
+
+### Issues
You can freely create an issue using the following links:
@@ -9,21 +11,109 @@ You can freely create an issue using the following links:
- Feature request [[Here]](https://github.com/akinomyoga/ble.sh/issues/new?template=help.md)
- Others (suggestions, projects, discussion, complaints, news, information or anything) [[Here]](https://github.com/akinomyoga/ble.sh/issues/new?template=free_style.md)
-## Pull requests
+### Pull requests
We always welcome following types of pull requests. Any changes will be considered to be provided under the BSD 3-Clause License.
If you do not know whether your changes would be appropriate for merge, please feel free to create a pull request and let us talk with each other!
- Better translation to English, typo fixes
- Fixes, optimization, test cases
-- Feature suggestions
-- New color theme
+- New features
+- New color themes ... We accept new themes in [`contrib`](https://github.com/akinomyoga/blesh-contrib/pulls) repository.
- Others
-## Wiki
+### Wiki
You can freely edit [wiki pages](https://github.com/akinomyoga/ble.sh/wiki).
- Translations
- Typo fixes
- Create new pages
+
+## For package maintainers
+
+If you are a package maintainer for a repository of Linux distribution, etc.
+you may provide a package-specific setting by preparing
+a file `/path/to/blesh/lib/_package.sh` (e.g. `/usr/share/blesh/lib/_package.sh`)
+which will be sourced after the load of `ble.sh` just before sourcing user's configuration (`~/.blerc`).
+
+- In the file, the shell variable `_ble_base_package_type=TYPE` should be
+ set up to have a repository-specific name (such as `AUR`).
+
+- The function named `ble/base/package:TYPE/update` (where `TYPE`
+ matches with a value assigned to `_ble_base_package_type`) may be
+ provided to define a custom updating procedure. The exit status of the function can be
+ - `0` ... when the update successed
+ - `6` ... when the update was skipped because the package was up to date.
+ - `125` ... when it wants to fallback to the built-in updating procedure of `ble.sh`.
+ - Other ... when the update failed
+
+An example `lib/_package.sh` might be
+
+```bash
+_ble_base_package_type=apt
+
+function ble/base/package:apt/update {
+ sudo apt upgrade blesh
+}
+```
+
+You can also find a real example for AUR (Arch User Repository) [here](https://aur.archlinux.org/cgit/aur.git/tree/blesh-update.sh?h=blesh-git).
+
+## Summary of codebase
+
+The core script file `ble.sh` is generated by combining the following files:
+
+- `ble.pp` ... Basic initialiation
+- `src/def.sh` ... Prototype definitions
+- `src/util.sh` ... Basic utility functions
+- `src/decode.sh` ... User-input decoder and keybindings
+- `src/color.sh` ... Terminal graphic attributes
+- `src/canvas.sh` ... Terminal layout engine
+ - `src/canvas.emoji.sh` ... Emoji database
+- `src/history.sh` ... Command history management
+- `src/edit.sh` ... Line editor
+- `src/benchmark.sh` ... Measure processing time
+- `lib/core-completion.sh` ... Prototype definition for completions
+- `lib/core-syntax.sh` ... Prototype definitions for syntax analyzer
+
+Useful features are implemented in separate modules:
+
+- `keymap/vi.sh` ... Vim mode
+ - `lib/vim-arpeggio.sh` ... `vim-arpeggio`-like plugin
+ - `lib/vim-surround.sh` ... `vim-surround`-like plugin
+- `keymap/emacs.sh` ... Emacs mode
+- `lib/core-syntax.sh` ... Shell parser and syntax highlighting
+ - `lib/core-syntax-ctx.def` ... Definition of parser states
+- `lib/core-complete.sh` ... Completions including `menu-complete`, `auto-complete`, `menu-filter`, `dabbrev`, `sabbrev`, etc.
+
+The following files are initialization scripts:
+
+- `lib/init-term.sh` ... Initialize terminal escape sequences (host-to-terminal, i.e. control sequences)
+- `lib/init-cmap.sh` ... Initialize terminal escape sequences (terminal-to-host, i.e. key sequences)
+- `lib/init-bind.sh` ... Initialize readline attacher
+- `lib/init-msys1.sh` ... Workaround for MSYS1 with broken pipes
+ - `lib/init-msys1-helper.c` ... Helper C program for the workaround of broken pipes
+
+## Tests
+
+Tests can be run by one of the following commands:
+
+```bash
+$ make check
+$ make check-all
+$ bash out/ble.sh --test
+
+```
+
+Currently test coverage is very small
+partly because the testing for interactive behavior and terminal rendering results is hard.
+Nevertheless, the tests are defined in the following files:
+
+- `lib/core-test.sh` ... Library for tests
+- `lib/test-main.sh`
+- `lib/test-util.sh`
+- `lib/test-canvas.sh`
+- `lib/test-edit.sh`
+- `lib/test-complete.sh`
+- `lib/test-syntax.sh`
diff --git a/README-ja_JP.md b/README-ja_JP.md
index 41ccfbf7..27aa1b4d 100644
--- a/README-ja_JP.md
+++ b/README-ja_JP.md
@@ -15,6 +15,11 @@
現時点では、文字コードとして `UTF-8` のみの対応です。
このスクリプトは [**BSD License**](LICENSE.md) (3条項 BSD ライセンス) の下で提供されます。
+免責: ラインエディタ本体は **ピュア Bash** で書かれていますが、
+ユーザーコマンド実行時には TTY 設定の為に `stty` (POSIX) を呼び出します。
+他にも処理の高速化の為に、初期化・終了処理、
+巨大なデータの処理 (補完、貼り付けなど) の局面でPOSIX 標準コマンドを利用しています。
+
## 簡単設定
`ble.sh` インストールには `git`, `make` (GNU make), and `gawk` が必要です。
@@ -34,10 +39,14 @@ git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh
-# 更新 (ble.sh をロードした状態で実行して下さい)
+# 更新 (ble.sh をロードした状態で)
ble-update
+# 更新 (ble.sh 外部から)
+
+bash /path/to/ble.sh --update
+
# パッケージ作成用コマンド
git clone --recursive https://github.com/akinomyoga/ble.sh.git
@@ -52,18 +61,34 @@ make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local
- **構文着色**: `fish` や `zsh-syntax-highlighting` のような文法構造に従った着色を行います。
`zsh-syntax-highlighting` のような単純な着色ではなく、構文の入れ子構造や複数のヒアドキュメントなども正しく解析して着色します。
-- **補完増強**: 補完を大幅に増強します。
- 文法構造に応じた補完、クォートやパラメータ展開を展開した上でのプログラム補完、**曖昧補完**に対応しています。
- また、候補をカーソルキーや TAB, S-TAB で選択できる**メニュー補完**、
- `fish` や `zsh-autosuggestions` のような**自動補完** (Bash 4.0 以上) の機能もあります。
- 更に、従来 `peco` や `fzf` を呼び出さなければならなかった補完候補の絞り込みも**メニュー絞り込み** (Bash 4.0 以上) として自然な形で組み込んでいます。
- 他に、**動的略語展開**や、`zsh-abbreviations` のような**静的略語展開**にも対応しています。
+ 着色は[全て設定可能](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A72-%E6%8F%8F%E7%94%BB)です。
+- **補完増強**: [補完](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A77-%E8%A3%9C%E5%AE%8C)を大幅に増強します。
+ **文法構造に応じた補完**、クォートやパラメータ展開を展開した上でのプログラム補完、**曖昧補完**に対応しています。
+ また、候補をカーソルキーや TAB, S-TAB で選択できる
+ [**メニュー補完**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A77-%E8%A3%9C%E5%AE%8C#user-content-sec-menu-complete)、
+ `fish` や `zsh-autosuggestions` のような
+ [**自動補完**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A77-%E8%A3%9C%E5%AE%8C#user-content-sec-auto-complete)
+ (Bash 4.0 以上) の機能もあります。
+ 更に、従来 `peco` や `fzf` を呼び出さなければならなかった補完候補の絞り込みも
+ [**メニュー絞り込み**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A77-%E8%A3%9C%E5%AE%8C#user-content-sec-menu-filter)
+ (Bash 4.0 以上) として自然な形で組み込んでいます。
+ 他に、[**動的略語展開**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A77-%E8%A3%9C%E5%AE%8C#user-content-sec-dabbrev)
+ や、`zsh-abbreviations` のような
+ [**静的略語展開**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A77-%E8%A3%9C%E5%AE%8C#user-content-sec-sabbrev)
+ にも対応しています。
- **Vim編集モード**: `set -o vi` による編集モードを増強します。
挿入・ノーマルモードの他に(行・矩形)ビジュアルモード、置換モードなどの各種モードに対応しています。
テキストオブジェクト・各種レジスタ・オペレータ・キーボードマクロなどにも対応しています。
拡張として `vim-surround` も提供しています。
-
-★`ble.sh` はよくある Bash 設定集のようにプロンプト (`PS1`)、エイリアス、関数を提供するものではありません。
+- 他にも
+ [**ステータス行**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A74-%E7%B7%A8%E9%9B%86#user-content-bleopt-prompt_status_line),
+ [**コマンド履歴共有**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A74-%E7%B7%A8%E9%9B%86#user-content-bleopt-history_share),
+ [**右プロンプト**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A74-%E7%B7%A8%E9%9B%86#user-content-bleopt-prompt_rps1),
+ [**過渡的プロンプト**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A74-%E7%B7%A8%E9%9B%86#user-content-bleopt-prompt_ps1_transient),
+ [**xterm タイトル**](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A74-%E7%B7%A8%E9%9B%86#user-content-bleopt-prompt_xterm_title),
+ など様々な機能に対応しています。
+
+注意: `ble.sh` は、(プロンプト (`PS1`)、エイリアス、関数などを提供する) 典型的な Bash 設定集と異なります。
`ble.sh` はより低層の基盤を提供するもので、ユーザは自分でプロンプトやエイリアスを設定する必要があります。
勿論 `bash-it` や `oh-my-bash` の様な他の Bash 設定と一緒に使っていただくことも可能です。
@@ -123,9 +148,9 @@ Make 変数 `DESTDIR` または `PREFIX` が指定されている時、`ble.sh`
現在、安定版は開発版に比べてかなり古いので様々な機能が欠けている事にご注意下さい。
- 開発版 [v0.4.0-devel2](https://github.com/akinomyoga/ble.sh/releases/tag/v0.4.0-devel2) (2020-12)
-- 安定版 [v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3) (2019-02 fork)
-- 安定版 [v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6) (2018-03 fork)
-- 安定版 [v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14) (2015-12 fork)
+- 安定版 [v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3) (2019-02 fork) +拡張補完
+- 安定版 [v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6) (2018-03 fork) +Vim モード
+- 安定版 [v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14) (2015-12 fork) 構文着色
## 1.2 `ble.sh` をダウンロードして試す (旧バージョン ble-0.3 201902版)†
@@ -190,6 +215,12 @@ Git (`git'), GNU awk (`gawk`), 及び GNU make (`make`) が必要になります
$ ble-update
```
+`ble-0.4` 以上をお使いの場合は `ble.sh` をロードしなくても以下のコマンドで更新可能です。
+
+```bash
+$ bash /path/to/ble.sh --update
+```
+
それ以外の場合には、以下のように `git pull` で最新版を入手・インストールできます。
```bash
diff --git a/README.md b/README.md
index 8e6b9b83..5e2239da 100644
--- a/README.md
+++ b/README.md
@@ -15,9 +15,15 @@ This script supports Bash 3.0 or higher although we recommend to use `ble.sh` wi
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).
+Disclaimer: The core part of the line editor is written in **pure Bash**, but
+`ble.sh` relies on POSIX `stty` to set up TTY states before and after the execution of user commands.
+It also use other POSIX utilities for acceleration
+in some part of initialization and cleanup code,
+processing of large data in completions, paste of large data, etc.
+
## Quick instructions
-Installation requires the commands `git`, `make` (GNU make), and `gawk`.
+Installation requires the commands `git`, `make` (GNU make), and `gawk` (in addition to `bash` and POSIX standard utilities).
For detailed descriptions, see [Sec 1.1](#get-from-source) and [Sec 1.2](#get-from-tarball) for trial/installation,
[Sec 1.3](#set-up-bashrc) for the setup of your `~/.bashrc`.
@@ -38,6 +44,10 @@ source ble.sh/out/ble.sh
ble-update
+# UPDATE (outside ble.sh sessions)
+
+bash /path/to/ble.sh --update
+
# PACKAGE (for package maintainers)
git clone --recursive https://github.com/akinomyoga/ble.sh.git
@@ -51,17 +61,32 @@ You may also install `ble.sh` through package-management systems (currently only
## Features
- **Syntax highlighting**: Highlight command lines input by users as in `fish` and `zsh-syntax-highlighting`.
- Unlike the simple highlighting in `zsh-syntax-highlighting`, `ble.sh` performs syntactic analysis to enable the correct highlighting of complex structures such as nested command substitutions, multiple here documents, etc.
+ Unlike the simple highlighting in `zsh-syntax-highlighting`, `ble.sh` performs syntactic analysis
+ to enable the correct highlighting of complex structures such as nested command substitutions, multiple here documents, etc.
+ Highlighting colors and styles are [fully configurable](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A72-Graphics).
- **Enhanced completion**:
- Support syntax-aware completion, completion with quotes and parameter expansions in prefix texts, ambiguous candidate generation, etc.
- Also **menu-complete** supports selection of candidates in menu (candidate list) by cursor keys, TAB and S-TAB.
- The feature **auto-complete** supports the automatic suggestion of completed texts as in `fish` and `zsh-autosuggestions` (with Bash 4.0+).
- The feature **menu-filter** integrates automatic filtering of candidates into menu completion (with Bash 4.0+).
- There are other functionalities such as **dabbrev** and **sabbrev** like `zsh-abbreviations`.
+ Extend [completion](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A77-Completion)
+ by **syntax-aware completion**, completion with quotes and parameter expansions in prefix texts, **ambiguous candidate generation**, etc.
+ Also, [**menu-complete**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A77-Completion#user-content-sec-menu-complete)
+ supports selection of candidates in menu (candidate list) by cursor keys, TAB and S-TAB.
+ The feature [**auto-complete**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A77-Completion#user-content-sec-auto-complete)
+ supports the automatic suggestion of completed texts as in `fish` and `zsh-autosuggestions` (with Bash 4.0+).
+ The feature [**menu-filter**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A77-Completion#user-content-sec-menu-filter)
+ integrates automatic filtering of candidates into menu completion (with Bash 4.0+).
+ There are other functionalities such as
+ [**dabbrev**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A77-Completion#user-content-sec-dabbrev) and
+ [**sabbrev**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A77-Completion#user-content-sec-sabbrev) like `zsh-abbreviations`.
- **Vim editing mode**: Enhance `readline`'s vi editing mode available with `set -o vi`.
- Vim editing mode supports various vim modes such as char/line/block visual/select mode, replace mode, command mode, operator pending mode as well as insert mode and normal mode.
+ Vim editing mode supports various vim modes such as char/line/block visual/select mode, replace mode,
+ command mode, operator pending mode as well as insert mode and normal mode.
Vim editing mode supports various operators, text objects, registers, keyboard macros, marks, etc.
It also provides `vim-surround` as an option.
+- Other interesting features include
+ [**status line**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A74-Editing#user-content-bleopt-prompt_status_line),
+ [**history share**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A74-Editing#user-content-bleopt-history_share),
+ [**right prompt**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A74-Editing#user-content-bleopt-prompt_rps1),
+ [**transient prompt**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A74-Editing#user-content-bleopt-prompt_ps1_transient),
+ [**xterm title**](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A74-Editing#user-content-bleopt-prompt_xterm_title), etc.
Note: ble.sh does not provide a specific settings for the prompt, aliases, functions, etc.
ble.sh provides a more fundamental infrastructure so that users can set up their own settings for prompts, aliases, etc.
@@ -77,7 +102,7 @@ Of course ble.sh can be used in combination with other Bash configurations such
### Generate
-To generate `ble.sh`, `gawk` (GNU awk) and `gmake` (GNU make) is required.
+To generate `ble.sh`, `gawk` (GNU awk) and `gmake` (GNU make) (in addition to Bash and POSIX standard utilities) is required.
The file `ble.sh` can be generated using the following commands.
If you have GNU make installed on `gmake`, please use `gmake` instead of `make`.
```bash
@@ -123,9 +148,9 @@ For download, trial and install, see the description at each release page.
The stable versions are significantly old compared to the devel version, so many features are unavailable.
- Devel [v0.4.0-devel2](https://github.com/akinomyoga/ble.sh/releases/tag/v0.4.0-devel2) (2020-12)
-- Stable [v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3) (2019-02 fork)
-- Stable [v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6) (2018-03 fork)
-- Stable [v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14) (2015-12 fork)
+- Stable [v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3) (2019-02 fork) +Enhanced completions
+- Stable [v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6) (2018-03 fork) +Vim mode
+- Stable [v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14) (2015-12 fork) Syntax highlighting
## 1.3 Set up `.bashrc`†
@@ -164,12 +189,18 @@ If you want to change the default path of the init script, you can add the optio
## 1.5 Update
You need Git (`git`), GNU awk (`gawk`) and GNU make (`make`).
-For `ble-0.3+`, run `ble-update` in the session with `ble.sh` loaded:
+For `ble-0.3+`, you can run `ble-update` in the session with `ble.sh` loaded:
```bash
$ ble-update
```
+For `ble.0.4+`, you can also update it outside the `ble.sh` session using
+
+```bash
+$ bash /path/to/ble.sh --update
+```
+
You can instead download the latest version by `git pull` and install it:
```bash
diff --git a/ble.pp b/ble.pp
index ec20b619..fc8479c5 100644
--- a/ble.pp
+++ b/ble.pp
@@ -4,6 +4,19 @@
#%[measure_load_time = 0]
#%[debug_keylogger = 1]
#%#----------------------------------------------------------------------------
+#%if measure_load_time
+_ble_debug_measure_fork_count=$(echo $BASHPID)
+TIMEFORMAT='[Elapsed %Rs; CPU U:%Us S:%Ss (%P%%)]'
+function ble/debug/measure-set-timeformat {
+ local title=$1 opts=$2
+ local new=$(echo $BASHPID)
+ local fork=$(((new-_ble_debug_measure_fork_count-1)&0xFFFF))
+ _ble_debug_measure_fork_count=$new
+ TIMEFORMAT="[Elapsed %Rs; CPU U:%Us S:%Ss (%P%%)] $title"
+ [[ :$opts: != *:nofork:* ]] &&
+ TIMEFORMAT=$TIMEFORMAT" ($fork forks)"
+}
+#%end
#%define inc
#%%[guard_name = "@_included".replace("[^_a-zA-Z0-9]", "_")]
#%%expand
@@ -14,8 +27,8 @@
#%%%%if measure_load_time
time {
-echo @.sh >&2
#%%%%%include @.sh
+ble/debug/measure-set-timeformat '@.sh'
}
#%%%%else
#%%%%%include @.sh
@@ -34,6 +47,7 @@
#%if measure_load_time
echo "ble.sh: $EPOCHREALTIME load start" >&2
time {
+echo "ble.sh: $EPOCHREALTIME parsed" >&2
# load_time (2015-12-03)
# core 12ms
# decode 10ms
@@ -42,7 +56,6 @@
# syntax 5ms
# ble-initialize 14ms
time {
-echo prologue >&2
#%end
#------------------------------------------------------------------------------
# check --help or --version
@@ -99,9 +112,7 @@
' --debug-bash-output' \
' Internal settings for debugging' \
'' ;;
- --test) _ble_init_command=test ;;
- --update) _ble_init_command=update ;;
- --clear-cache) _ble_init_command=clear-cache ;;
+ --test | --update | --clear-cache) _ble_init_command=1 ;;
esac
done
if [ -n "$_ble_init_exit" ]; then
@@ -126,10 +137,15 @@
return 1 2>/dev/null || exit 1
fi 3>&2 >/dev/null 2>&1 # set -x 対策 #D0930
-if [[ $- != *i* && ! $_ble_init_command ]]; then
- { ((${#BASH_SOURCE[@]})) && [[ ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} == *bashrc ]]; } ||
- builtin echo "ble.sh: This is not an interactive session." >&3
- return 1 2>/dev/null || builtin exit 1
+if [[ ! $_ble_init_command ]]; then
+ if ((BASH_SUBSHELL)); then
+ builtin echo "ble.sh: ble.sh cannot be loaded into a subshell." >&3
+ return 1 2>/dev/null || builtin exit 1
+ elif [[ $- != *i* ]]; then
+ { ((${#BASH_SOURCE[@]})) && [[ ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} == *bashrc ]]; } ||
+ builtin echo "ble.sh: This is not an interactive session." >&3
+ return 1 2>/dev/null || builtin exit 1
+ fi
fi 3>&2 &>/dev/null # set -x 対策 #D0930
{
@@ -312,7 +328,7 @@ function ble/base/reinforce-bash-options {
# WA #D1534 workaround for msys2 .inputrc
if [[ $OSTYPE == msys* ]]; then
- [[ $(bind -m emacs -p | grep '"\\C-?"') == '"\C-?": backward-kill-line' ]] &&
+ [[ $(builtin bind -m emacs -p | grep '"\\C-?"') == '"\C-?": backward-kill-line' ]] &&
builtin bind -m emacs '"\C-?": backward-delete-char'
fi
@@ -364,6 +380,8 @@ function ble/util/print-lines { builtin printf '%s\n' "$@"; }
function ble/base/read-blesh-arguments {
local opts=
local opt_attach=prompt
+
+ _ble_init_command= # 再解析
while (($#)); do
local arg=$1; shift
case $arg in
@@ -401,7 +419,13 @@ function ble/base/read-blesh-arguments {
opts=$opts:keep-rlvars ;;
(--debug-bash-output)
bleopt_internal_suppress_bash_output= ;;
- (--test | --update | --clear-cache) ;;
+ (--test | --update | --clear-cache)
+ if [[ $_ble_init_command ]]; then
+ ble/util/print "ble.sh ($arg): the option '--$_ble_init_command' has already been specified." >&2
+ opts=$opts:E
+ else
+ _ble_init_command=${arg#--}
+ fi ;;
(--*)
ble/util/print "ble.sh: unrecognized long option '$arg'" >&2
opts=$opts:E ;;
@@ -454,6 +478,7 @@ function ble/base/read-blesh-arguments {
fi
if [[ $_ble_base ]]; then
+ [[ $_ble_init_command ]] && _ble_init_attached=$_ble_attached
if ! ble/base/unload-for-reload; then
builtin echo "ble.sh: an old version of ble.sh seems to be already loaded." >&2
ble/base/restore-bash-options
@@ -933,9 +958,15 @@ function ble-update/.make {
fi
}
function ble-update/.reload {
- if [[ $- == *i* && $_ble_attached ]]; then
- ble-reload
+ local ext=$?
+ if [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then
+ if [[ $- == *i* && $_ble_attached ]] && ! ble/util/is-running-in-subshell; then
+ ble-reload
+ fi
+ return $?
fi
+ ((ext==6)) && ext=0
+ return "$ext"
}
function ble-update {
if (($#)); then
@@ -948,11 +979,9 @@ function ble-update {
ble/base/package:"$_ble_base_package_type"/update; local ext=$?
if ((ext==125)); then
ble/util/print 'ble-update: fallback to the default update process.' >&2
- elif [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then
- ble-update/.reload
- return $?
else
- return "$ext"
+ ble-update/.reload "$ext"
+ return $?
fi
fi
@@ -1001,19 +1030,16 @@ function ble-update {
ble-update/.make --sudo INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install
else
ble-update/.make INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install
- fi ); local ext=$?
- if [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then
- ble-update/.reload
- return $?
- fi
- return "$ext"
+ fi )
+ ble-update/.reload $?
+ return $?
fi
fi
if ((EUID!=0)) && ! ble-update/.check-install-directory-ownership; then
# _ble_base が自分の物でない時は sudo でやり直す
sudo "$BASH" "$_ble_base/ble.sh" --update &&
- ble-update/.reload
+ ble-update/.reload 6
return $?
else
# _ble_base/src 内部に clone して make install
@@ -1028,6 +1054,7 @@ function ble-update {
return 1
}
#%if measure_load_time
+ble/debug/measure-set-timeformat ble.pp/prologue
}
#%end
@@ -1059,6 +1086,9 @@ function ble-update {
bleopt/check-all
#------------------------------------------------------------------------------
+#%if measure_load_time
+time {
+#%end
## @fn ble [SUBCOMMAND]
##
@@ -1324,7 +1354,13 @@ function ble/base/process-blesh-arguments {
fi
_ble_base_rcfile=$_ble_base_arguments_rcfile
+#%if measure_load_time
+time {
+#%end
ble/base/load-rcfile # blerc
+#%if measure_load_time
+ble/debug/measure-set-timeformat "blerc: '$_ble_base_rcfile'"; }
+#%end
ble/util/invoke-hook BLE_ONLOAD
# attach
@@ -1359,6 +1395,7 @@ function ble/base/initialize/.clean-up {
builtin unset -v _ble_init_arg
builtin unset -v _ble_init_exit
builtin unset -v _ble_init_command
+ builtin unset -v _ble_init_attached
# 状態復元
if [[ $_ble_init_original_IFS_set ]]; then
@@ -1394,22 +1431,26 @@ function ble/base/sub:clear-cache {
(shopt -u failglob; ble/bin/rm -rf "$_ble_base_cache"/*)
}
+#%if measure_load_time
+ble/debug/measure-set-timeformat ble.pp/epilogue; }
+#%end
+
ble-import -f lib/_package
if [[ $_ble_init_command ]]; then
- if ! ble/base/sub:"$_ble_init_command"; then
- ble/base/initialize/.clean-up 2>/dev/null # set -x 対策 #D0930
- { return $? || exit $?; } 2>/dev/null # set -x 対策 #D0930
- fi
+ ble/base/sub:"$_ble_init_command"; _ble_init_exit=$?
+ [[ $_ble_init_attached ]] && ble-attach
+ ble/util/setexit "$_ble_init_exit"
else
ble/base/process-blesh-arguments "$@"
fi
-ble/base/initialize/.clean-up 2>/dev/null # set -x 対策 #D0930
-
#%if measure_load_time
-}
+ble/debug/measure-set-timeformat Total nofork; }
+_ble_init_exit=$?
echo "ble.sh: $EPOCHREALTIME load end" >&2
+ble/util/setexit "$_ble_init_exit"
#%end
-{ return 0 || exit 0; } &>/dev/null # set -x 対策 #D0930
+ble/base/initialize/.clean-up 2>/dev/null # set -x 対策 #D0930
+{ return $? || exit $?; } 2>/dev/null # set -x 対策 #D0930
###############################################################################
diff --git a/make_command.sh b/make_command.sh
index da9c28bb..eccb2bd9 100755
--- a/make_command.sh
+++ b/make_command.sh
@@ -373,6 +373,8 @@ function sub:scan {
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zinvalid bind typeZd
\Zline = "bind"Zd
+ \Z'\'' bindZd
+ \Z\(bind\) ble-bindZd
g'
sub:scan/builtin 'read' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
@@ -397,7 +399,7 @@ function sub:scan {
g'
sub:scan/builtin 'unset' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
- \Zunset _ble_init_(version|arg|exit|test)\bZd
+ \Zunset _ble_init_(version|arg|exit|command)\bZd
\Zreadonly -f unsetZd
\Zunset -f builtinZd
g'
@@ -421,7 +423,7 @@ function sub:scan {
sub:scan/array-count-in-arithmetic-expression
sub:scan/unset-variable |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
- \Zunset _ble_init_(version|arg|exit|test)\bZd
+ \Zunset _ble_init_(version|arg|exit|command)\bZd
\Zbuiltins1=\(.* unset .*\)Zd
\Zfunction unsetZd
\Zreadonly -f unsetZd
diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md
index 5b16f6ad..0454a5a4 100644
--- a/memo/ChangeLog.md
+++ b/memo/ChangeLog.md
@@ -9,8 +9,8 @@
- mandb: fix BS contamination used by nroff to represent bold (reported by rlnore) `#D1429` b5c875a
- mandb: fix an encoding prpblem of utf8 manuals `#D1446` 7a4a480
- mandb: improve extraction and cache for each locale `#D1480` 3588158
- - mandb: fix an infinite loop by a leak variable (reported by rlanore, riblo) `#D1550` 0000000
- - mandb: work around old groff in macOS (reported by killermoehre) `#D1551` 0000000
+ - mandb: fix an infinite loop by a leak variable (reported by rlanore, riblo) `#D1550` 0efcb65
+ - mandb: work around old groff in macOS (reported by killermoehre) `#D1551` d4f816b
- decode (`ble-decode-kbd`): support various specifications of key sequences `#D1439` 0f01cab
- edit: support new options `bleopt edit_line_type={logical,graphical}` (motivated by 3ximus) `#D1442` 40ae242
- complete: support new options `bleopt complete_limit{,_auto}` (contributed by timjrd) `#D1445` b13f114 5504bbc
@@ -100,6 +100,8 @@
- progcomp: fix non-working `complete -C prog` (reported by Archehandoro) `#D1535` 026432d
- bind: fix a problem that `bind '"seq":"key"'` causes a loop macro `bind -s key key` (reported by thanosz) `#D1536` ea05fc5
- bind: fix errors on readline macros (reported by RakibFiha) `#D1537` c257299
+- main: work around sourcing `ble.sh` inside subshells `#D1554` 0000000
+- main: work around `. ble.sh --{test,update,clear-cache}` in intereactive sessions `#D1555` 0000000
## Compatibility
@@ -132,7 +134,7 @@
- main: prefer `nawk` over `mawk` and `gawk` `#D1523` `#D1524` c89aa23
- main (`ble/bin/.freeze-utility-path`): fix unupdated temporary implementations `#D1528` c70a3b4
- test (`test-canvas`): fix dependency on `ext/contra` `#D1525` c89aa23
-- util: inherit special file descriptors `#D1552` 0000000
+- util: inherit special file descriptors `#D1552` 98835b5
# ble-0.4.0-devel2
diff --git a/note.txt b/note.txt
index 47e9c256..b64ee4cf 100644
--- a/note.txt
+++ b/note.txt
@@ -805,6 +805,12 @@ bash_tips
Memo
-------------------------------------------------------------------------------
+2021-05-16
+
+ * Linux パッケージのチェック (by killermoehre) [#M0021]
+ どの Linux にどのパッケージのどの version が入っているかを調べられるサイト
+ https://pkgs.org/search/?q=groff
+
2021-05-15
* PKGBUILD の説明は此処にある [#M0020]
@@ -1265,6 +1271,12 @@ bash_tips
bug-bash, third-party bugs
-------------------------------------------------------------------------------
+2021-05-16
+
+ * complete: tar xf groff-1.19.2.ta[TAB] でエラーが発生する
+
+ と思ったらこれは bash-completion だった。
+
2021-05-06
* bash: complete -p の -F はやはり quote するべきなのではないか。
@@ -1367,8 +1379,22 @@ bash_tips
0.5 ControlPanel/TUI Framework
0.4 progcolor
+2021-05-19
+
+ * sabbrev: 単語でなくても任意の文脈で発動する sabbrev が欲しい。\ 等で前置す
+ れば特に問題ないのではないか?
+
2021-05-17
+ * 此処で思ったのだが nawk は Unicode の対象を取り扱えるのだろうか。。。UTF-8
+ ならば通常の制御文字はそのままなので問題は生じないのではないかという気もす
+ るが。文字数を数えて何かする様な処理では何か変な事が起こるかもしれないが、
+ そうでなければ大丈夫の気がする。
+
+ 問題が起こるかもしれないのは brace expansion の形式でファイル名一覧を挿入す
+ る処理。これに関しては UTF-8 だと例えば平仮名の途中で分断されたりして変な事
+ が起こる可能性がある。
+
* global: /dev/null を $_ble_util_fd_null に置き換える?
#D1552 で議論した。毎回 open するよりも dup した方が高速である。一方で
@@ -1381,9 +1407,6 @@ bash_tips
$ exec {}>/dev/null
$ exec {_ble_base_fd_null}>/dev/null
- * 現在の初期化だと ble.sh session で source --test 等すると変な事になるのでは
- ないか。これは取り敢えず独立した項目として取り扱う事にする。
-
* history: 履歴が余りに消滅するので ble.sh の側で独立した履歴の仕組みを作りたい
然し何処に履歴ファイルを置くのかという問題がある。
@@ -1455,50 +1478,16 @@ bash_tips
また右端から入力を始めた時の折返しが正しくできていない。
- * Linux パッケージのチェック (by killermoehre) [#Mxxxx]
- どの Linux にどのパッケージのどの version が入っているかを調べられるサイト
- https://pkgs.org/search/?q=groff
-
- * complete: tar xf groff-1.19.2.ta[TAB] でエラーが発生する
-
- と思ったらこれは bash-completion だった。
-
2021-05-15
- * AUR blesh-git について
-
- * requirements: ble-update の為に git, gawk があった方が良いのかもしれない?
- 然し、最終的に AUR helper を呼び出すのであれば余り関係ないのかもしれない。
-
- * https://aur.archlinux.org/cgit/aur.git/tree/blesh-update.sh?h=blesh-git#n29
-
- (()) の中の quote のルールは変更されている。然し何故か PKGBUILD はそのま
- ま何事もなく動作しているどういう事だろうか。shopt が調整されているのだろ
- うか。或いは bash の version が違うのだろうか。適当な PKGBUILD を作ってそ
- の辺りを出力させたらはっきりするのかもしれない。何れにしても将来的に変更
- されるかもしれないという事などを考えると修正した方が良い。
-
- * local variables
- local PRE_VERSION
- local POST_VERSION
-
- 恐らく他の所で使うという訳ではないだろう。というか、この関数は PKGBUILD
- で使われるのではなくて ble.sh から呼び出しているのであるから他の場所から
- 使っているという事はない気がする。
-
- * _package.sh は実の所 source するだけなので実行属性は必要ない。唯、source
- path を経由して source したい時には実行属性がついている必要があるのだった
- か? man bash を確認したがちゃんと実行可能である必要はないとの事が明記され
- ている。
-
- というか今知ったがカレントディレクトリよりも PATH の方が優先されるのだそ
- うだ。だとすると結構変な事が起こるの可能性もあったのでは。今試しに ~/bin
- に ble.sh を登録して、bash --norc から ble.sh ディレクトリの外で source
- ble.sh を実行したらちゃんとロードされた。うーん。
+ * AUR blesh-git のカスタム update について
+ https://aur.archlinux.org/packages/blesh-git/
+ https://aur.archlinux.org/cgit/aur.git/tree/blesh-update.sh?h=blesh-git
- * done: contributing に lib/_package.sh を追加する
+ * {PRE,POST}_VERSION を local で宣言する
+ * _package.sh の属性は 644
- * test: 失敗する様になっている
+ * test: BUG 失敗する様になっている
* quote-command の test に失敗している @ bash-4.3 直した
@@ -1517,8 +1506,6 @@ bash_tips
にならず ^A^A になっているのは関数内で実行している時である。対話でも ^A^A
にしかならない。
- * README: 様々な機能へのリンクを貼った方が良いのではないかという事
-
2021-05-13
* vi_imap が empty と表示されるとの事
@@ -1769,6 +1756,8 @@ bash_tips
るというのは不自然すぎる。それならば ble.sh 自体が変数を定義するのでそれに
よって被覆されてしまうと説明した方が自然である。
+ グローバルでない変数を列挙する方法は存在するだろうか。
+
2021-04-26
* keymap/vi: vi における既定の keymap を imap ではなく nmap にするオプション
@@ -4611,6 +4600,64 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------
+2021-05-19
+
+ * README: 様々な機能へのリンクを貼った方が良いのではないかという事 [#D1556]
+
+ * 現在の初期化だと ble.sh session で source --test 等すると [#D1555]
+
+ 変な事になるのではないか。これは取り敢えず独立した項目として取り扱う事にする。
+
+ * main: subshell 内部で source/reload したら何が起こるのか [#D1554]
+
+ source した場合には何も起こらない。うーん。これは単に attach 戦略が prompt
+ だから attach する前に終了しているという事の気がする。
+
+ reload については reload が実際に実行されて色々と _ble_base_run のデータが
+ 破棄される。この状態で ble-detach を実行すると制御できなくなる。tty 状態は
+ 別に問題はない様だ。
+
+ * main: AUR blesh-git について [#D1553]
+
+ * ok: requirements: ble-update の為に git, gawk があった方が良いのかもしれ
+ ない? 然し、最終的に AUR helper を呼び出すのであれば余り関係ないのかもし
+ れない。特に package としては fallback になる事は想定していないので。
+
+ * ok: (("$helper_prog" != 0))
+ https://aur.archlinux.org/cgit/aur.git/tree/blesh-update.sh?h=blesh-git#n29
+
+ (()) の中の quote のルールは変更されている。然し何故か PKGBUILD はそのま
+ ま何事もなく動作しているどういう事だろうか。shopt が調整されているのだろ
+ うか。或いは bash の version が違うのだろうか。適当な PKGBUILD を作ってそ
+ の辺りを出力させたらはっきりするのかもしれない。何れにしても将来的に変更
+ されるかもしれないという事などを考えると修正した方が良い。
+
+ と思ったが改めて試してみたが問題はない様だ。単に手許で試す時に
+ (("$xxx"!=0)) が ((!=0)) に展開されてエラーになっていただけなのであった。
+ bash-5.1 で振る舞いが変更されたのは '' による quote の方であった。
+
+ * local variables
+ local PRE_VERSION
+ local POST_VERSION
+
+ 恐らく他の所で使うという訳ではないだろう。というか、この関数は PKGBUILD
+ で使われるのではなくて ble.sh から呼び出しているのであるから他の場所から
+ 使っているという事はない気がする。
+
+ * _package.sh は実の所 source するだけなので実行属性は必要ない。唯、source
+ path を経由して source したい時には実行属性がついている必要があるのだった
+ か? man bash を確認したがちゃんと実行可能である必要はないとの事が明記され
+ ている。
+
+ というか今知ったがカレントディレクトリよりも PATH の方が優先されるのだそ
+ うだ。だとすると結構変な事が起こるの可能性もあったのでは。今試しに ~/bin
+ に ble.sh を登録して、bash --norc から ble.sh ディレクトリの外で source
+ ble.sh を実行したらちゃんとロードされた。うーん。
+
+ * done: contributing に lib/_package.sh を追加する
+
+ 取り敢えず残っている物については簡単に纏めてこの項目はOKとする。
+
2021-05-17
* util: inherit special file descriptors [#D1552]
@@ -4676,6 +4723,7 @@ bash_tips
* done: wiki で openat_base の項目を編集する
* macOS で groff のエラーが出る (reported by killermoehre) [#D1551]
+ https://github.com/akinomyoga/ble.sh/issues/112
groff -k というオプションが使えないという事。macOS の groff は v1.19 らしく
これは 2004 の version である。実に17年前の groff である。このオプションは
@@ -4729,15 +4777,6 @@ bash_tips
たらその時にまた考え直せば良い。取り敢えず遠隔で実装できるのは此処までであ
る。
- * 此処で思ったのだが nawk は Unicode の対象を取り扱えるのだろうか。。。UTF-8
- ならば通常の制御文字はそのままなので問題は生じないのではないかという気もす
- るが。文字数を数えて何かする様な処理では何か変な事が起こるかもしれないが、
- そうでなければ大丈夫の気がする。
-
- 問題が起こるかもしれないのは brace expansion の形式でファイル名一覧を挿入す
- る処理。これに関しては UTF-8 だと例えば平仮名の途中で分断されたりして変な事
- が起こる可能性がある。
-
* complete: ssh -option の後の補完が固まる (reported by rlanore, riblo) [#D1550]
https://github.com/akinomyoga/ble.sh/issues/98
diff --git a/src/benchmark.sh b/src/benchmark.sh
index 49a0b726..1e1f8b05 100644
--- a/src/benchmark.sh
+++ b/src/benchmark.sh
@@ -190,6 +190,7 @@ function ble-measure/.read-arguments {
## @var[out] nsec
## 実行時間を nsec 単位で返します。
function ble-measure {
+ local TIMEFORMAT=
if [[ ! $_ble_measure_base ]]; then
_ble_measure_base=0 nsec=0
# : よりも a=1 の方が速い様だ
diff --git a/src/decode.sh b/src/decode.sh
index ec723c84..2565655b 100644
--- a/src/decode.sh
+++ b/src/decode.sh
@@ -2730,8 +2730,8 @@ function ble/decode/bind/.generate-source-to-unbind-default/.process {
mode = 1;
}
- # Note: Solaris xpg4 awk では gsub の置換後のエスケープシーケンス
- # も処理されるので、バックスラッシュをエスケープする。
+#% # Note: Solaris xpg4 awk では gsub の置換後のエスケープシーケンス
+#% # も処理されるので、バックスラッシュをエスケープする。
function str2rep(str) {
if (IS_XPG4) sub(/\\/, "\\\\\\\\", str);
return str;
@@ -2770,8 +2770,8 @@ function ble/decode/bind/.generate-source-to-unbind-default/.process {
if (match(line0, /^"(([^"\\]|\\.)+)"/) > 0) {
_seq = substr(line0, 2, RLENGTH - 2);
- #%# ※bash-3.1 では bind -sp で \e ではなく \M- と表示されるが、
- #%# bind -r では \M- ではなく \e と指定しなければ削除できない。
+#% # ※bash-3.1 では bind -sp で \e ではなく \M- と表示されるが、
+#% # bind -r では \M- ではなく \e と指定しなければ削除できない。
gsub(/\\M-/, "\\e", _seq);
print "builtin bind -r " quote(_seq);
@@ -2796,14 +2796,14 @@ function ble/decode/bind/.generate-source-to-unbind-default/.process {
line = $0;
- #%# ※bash-4.3..5.0 では bind -r しても bind -X に残る。
- #%# 再登録を防ぐ為 ble-decode-bind を明示的に避ける
+#% # ※bash-4.3..5.0 では bind -r しても bind -X に残る。
+#% # 再登録を防ぐ為 ble-decode-bind を明示的に避ける
if (line ~ /(^|[^[:alnum:]])ble-decode\/.hook($|[^[:alnum:]])/) next;
- #%# ※bind -X で得られた物は直接 bind -x に用いる事はできない。
- #%# コマンド部分の "" を外して中の escape を外す必要がある。
- #%# escape には以下の種類がある: \C-a など \C-? \e \\ \"
- #%# \n\r\f\t\v\b\a 等は使われない様だ。
+#% # ※bind -X で得られた物は直接 bind -x に用いる事はできない。
+#% # コマンド部分の "" を外して中の escape を外す必要がある。
+#% # escape には以下の種類がある: \C-a など \C-? \e \\ \"
+#% # \n\r\f\t\v\b\a 等は使われない様だ。
if (match(line, /^("([^"\\]|\\.)*":) "(([^"\\]|\\.)*)"/) > 0) {
rlen = RLENGTH;
match(line, /^"([^"\\]|\\.)*":/);
@@ -3798,17 +3798,17 @@ function ble/builtin/bind/.reconstruct-user-settings {
if (mode == 0 || mode == 3) {
match(keyseq, /^\\C-\\(\\"$)?|^\\M-|^\\.|^./);
} else {
- #%# bind -X, bind -s には問題はない
+#% # bind -X, bind -s には問題はない
match(keyseq, /^\\[CM]-|^\\.|^./);
}
unit = substr(keyseq, 1, RLENGTH);
keyseq = substr(keyseq, 1 + RLENGTH);
if (unit == "\\C-\\") {
- #%# Bash 3.0--5.0 Bug https://lists.gnu.org/archive/html/bug-bash/2020-01/msg00037.html
+#% # Bash 3.0--5.0 Bug https://lists.gnu.org/archive/html/bug-bash/2020-01/msg00037.html
unit = unit "\\";
} else if (unit == "\\M-") {
- #%# Bash 3.1 以下では ESC は \M- と出力される
+#% # Bash 3.1 以下では ESC は \M- と出力される
unit = "\\e";
}
out = out unit;
diff --git a/src/history.sh b/src/history.sh
index fa39cca5..ebaa9860 100644
--- a/src/history.sh
+++ b/src/history.sh
@@ -314,10 +314,10 @@ else
builtin history $arg_count | ble/bin/awk -v apos="'" '
BEGIN { n = ""; }
- # 何故かタイムスタンプがコマンドとして読み込まれてしまう
+#% # 何故かタイムスタンプがコマンドとして読み込まれてしまう
/^ *[0-9]+\*? +(__ble_ext__|\?\?)#[0-9]/ { next; }
- # ※rcfile として読み込むと HISTTIMEFORMAT が ?? に化ける。
+#% # ※rcfile として読み込むと HISTTIMEFORMAT が ?? に化ける。
/^ *[0-9]+\*? +(__ble_ext__|\?\?)/ {
if (n != "") {
n = "";
@@ -472,7 +472,7 @@ if ((_ble_bash>=30100)); then
if (t) print "#" t > filename_section;
print c > filename_section;
}
- # Note: HISTTIMEFORMAT を指定するのは bash-4.4 で複数行読み取りを有効にする為。
+#% # Note: HISTTIMEFORMAT を指定するのは bash-4.4 で複数行読み取りを有効にする為。
print "HISTTIMEFORMAT=%s builtin history -r " filename_section > filename_source;
} else {
for (i = 0; i < command_count; i++) {
diff --git a/src/util.sh b/src/util.sh
index 46761790..fc1aee74 100644
--- a/src/util.sh
+++ b/src/util.sh
@@ -2024,7 +2024,7 @@ function ble/util/writearray {
return s;
}
- # 制御文字が要素に含まれていない場合は全て [1]="..." の形式になっている筈。
+#% # 制御文字が要素に含まれていない場合は全て [1]="..." の形式になっている筈。
function analyze_elements_dq(decl, _, arr, i, n) {
if (decl ~ /^\[[0-9]+\]="([^'$'\1\2''"\n\\]|\\.)*"( \[[0-9]+\]="([^\1\2"\\]|\\.)*")*$/) {
if (IS_GAWK) {
@@ -2056,14 +2056,14 @@ function ble/util/writearray {
printf("%s%c", arr[i], 0);
}
- # [N]="" の形式の時は要素内改行はないと想定
+#% # [N]="" の形式の時は要素内改行はないと想定
if (FLAG_NLFIX) printf("\n");
return 1;
}
return 0;
}
- # 任意の場合は多少遅くなるがこちらの関数で処理する。
+#% # 任意の場合は多少遅くなるがこちらの関数で処理する。
function analyze_elements_general(decl, _, arr, i, n, nlfix_indices) {
n = split(decl, arr, / /);
nlfix_indices = "";
@@ -2111,24 +2111,24 @@ function ble/util/writearray {
}
function process_declaration(decl, _, mlen, line) {
- # declare 除去
+#% # declare 除去
sub(/^declare +(-[-aAilucnrtxfFgGI]+ +)?(-- +)?/, "", decl);
- # 全体 quote の除去
+#% # 全体 quote の除去
if (decl ~ /^([_a-zA-Z][_a-zA-Z0-9]*)='\''\(.*\)'\''$/) {
sub(/='\''\(/, "=(", decl);
sub(/\)'\''$/, ")", decl);
gsub(/'\'\\\\\'\''/, "'\''", decl);
}
- # bash-3.0 の declare -p は改行について誤った出力をする。
+#% # bash-3.0 の declare -p は改行について誤った出力をする。
if (_ble_bash < 30100) gsub(/\\\n/, "\n", decl);
- # #D1238 bash-4.3 以前の declare -p は ^A, ^? を
- # ^A^A, ^A^? と出力してしまうので補正する。
- # #D1325 更に Bash-3.0 では "x${_ble_term_DEL}y" とすると
- # _ble_term_DEL の中身が消えてしまうので
- # "x""${_ble_term_DEL}""y" とする必要がある。
+#% # #D1238 bash-4.3 以前の declare -p は ^A, ^? を
+#% # ^A^A, ^A^? と出力してしまうので補正する。
+#% # #D1325 更に Bash-3.0 では "x${_ble_term_DEL}y" とすると
+#% # _ble_term_DEL の中身が消えてしまうので
+#% # "x""${_ble_term_DEL}""y" とする必要がある。
if (_ble_bash < 40000) {
gsub(/\001\001\001\001/, "\001", decl);
gsub(/\001\001\001\177/, "\177", decl);
@@ -2140,10 +2140,10 @@ function ble/util/writearray {
sub(/^([_a-zA-Z][_a-zA-Z0-9]*)=\([[:space:]]*/, "", decl);
sub(/[[:space:]]*\)[[:space:]]*$/, "", decl);
- # 空配列
+#% # 空配列
if (decl == "") return 1;
- # [N]="value" だけの時の高速実装。mawk だと却って遅くなる様だ
+#% # [N]="value" だけの時の高速実装。mawk だと却って遅くなる様だ
if (AWKTYPE != "mawk" && analyze_elements_dq(decl)) return 1;
return analyze_elements_general(decl);
@@ -2587,6 +2587,9 @@ else
ble/util/assign BASHPID 'ble/bin/sh -c "$command"'
}
function ble/util/is-running-in-subshell {
+ # Note: bash-4.3 以下では BASH_SUBSHELL はパイプやプロセス置換で増えないの
+ # で信頼性が低いらしい。唯、関数内で実行している限りは大丈夫なのかもしれ
+ # ない。
((BASH_SUBSHELL)) && return 0
local BASHPID; ble/util/getpid
[[ $$ != $BASHPID ]]
@@ -2709,14 +2712,14 @@ function ble/util/declare-print-definitions {
BEGIN {
decl = "";
- # 対策 #D1270: MSYS2 で ^M を代入すると消える
+#% # 対策 #D1270: MSYS2 で ^M を代入すると消える
flag_escape_cr = OSTYPE == "msys";
}
function declflush(_, isArray) {
if (decl) {
isArray = (decl ~ /^declare +-[ilucnrtxfFgGI]*[aA]/);
- # declare 除去
+#% # declare 除去
sub(/^declare +(-[-aAilucnrtxfFgGI]+ +)?(-- +)?/, "", decl);
if (isArray) {
if (decl ~ /^([_a-zA-Z][_a-zA-Z0-9]*)='\''\(.*\)'\''$/) {
@@ -2724,9 +2727,9 @@ function ble/util/declare-print-definitions {
sub(/\)'\''$/, ")", decl);
gsub(/'\'\\\\\'\''/, "'\''", decl);
- # Note: bash-3.* の配列表記では ^A, ^? が二重にエスケープされて
- # ^A^A^A^A, ^A^A^A^? になってしまう。一つ目のエスケープをここで
- # 外しておく。
+#% # Note: bash-3.* の配列表記では ^A, ^? が二重にエスケープされて
+#% # ^A^A^A^A, ^A^A^A^? になってしまう。一つ目のエスケープをここで
+#% # 外しておく。
if (_ble_bash < 40000) {
gsub(/\001\001/, "\001", decl);
gsub(/\001\177/, "\177", decl);
@@ -2734,14 +2737,14 @@ function ble/util/declare-print-definitions {
}
}
- # bash-3.0 の declare -p は改行について誤った出力をする。
+#% # bash-3.0 の declare -p は改行について誤った出力をする。
if (_ble_bash < 30100) gsub(/\\\n/, "\n", decl);
- # #D1238 bash-4.3 以前の declare -p は ^A, ^? を
- # ^A^A, ^A^? と出力してしまうので補正する。
- # #D1325 更に Bash-3.0 では "x${_ble_term_DEL}y" とすると
- # _ble_term_DEL の中身が消えてしまうので
- # "x""${_ble_term_DEL}""y" とする必要がある。
+#% # #D1238 bash-4.3 以前の declare -p は ^A, ^? を
+#% # ^A^A, ^A^? と出力してしまうので補正する。
+#% # #D1325 更に Bash-3.0 では "x${_ble_term_DEL}y" とすると
+#% # _ble_term_DEL の中身が消えてしまうので
+#% # "x""${_ble_term_DEL}""y" とする必要がある。
if (_ble_bash < 30100) {
gsub(/\001\001/, "\"\"${_ble_term_SOH}\"\"", decl);
gsub(/\001\177/, "\"\"${_ble_term_DEL}\"\"", decl);