Skip to content

Commit

Permalink
highlight: fix a bug that "bleopt filename_ls_colors" is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 12, 2022
1 parent fb7bd0b commit b568ade
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 deletions.
17 changes: 14 additions & 3 deletions README-ja_JP.md
Expand Up @@ -543,7 +543,7 @@ $ ble-color-show
ble-bind -f 'C-x h' 'insert-string "Hello, world!"'
```

<kbd>C-x</kbd> 等のキー表記については
上記の <kbd>C-x h</kbd> の様なキー表記については
[マニュアル §3.1](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A73-%E3%82%AD%E3%83%BC%E3%83%90%E3%82%A4%E3%83%B3%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0#user-content-sec-kspecs) で詳細に説明されています。
スペース・タブ・エンター・バックスペース・エスケープなどの特殊キーの表記については
[マニュアル §3.1.1](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A73-%E3%82%AD%E3%83%BC%E3%83%90%E3%82%A4%E3%83%B3%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0#user-content-sec-kspecs-ret) で説明されています:
Expand All @@ -552,7 +552,7 @@ ble-bind -f 'C-x h' 'insert-string "Hello, world!"'
エンター・リターンキーは端末によって <kbd>C-m</kbd> または <kbd>RET</kbd> と表現します。
バックスペースは端末によって <kbd>C-?</kbd>, <kbd>DEL</kbd>, <kbd>C-h</kbd>, または <kbd>BS</kbd> 等様々な表現があります。
<kbd>Ctrl+Return</kbd> や <kbd>Shift+Return</kbd> などの修飾された特殊キーの取り扱いについては
[マニュアル §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A73-%E3%82%AD%E3%83%BC%E3%83%90%E3%82%A4%E3%83%B3%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0#sec-modifyOtherKeys-manual) で説明されています。
[マニュアル §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/%E8%AA%AC%E6%98%8E%E6%9B%B8-%C2%A73-%E3%82%AD%E3%83%BC%E3%83%90%E3%82%A4%E3%83%B3%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0#user-content-sec-modifyOtherKeys-manual) で説明されています。
お使いの端末が `modifyOtherKeys` に対応していない場合、手動で各キーの組み合わせに対応するエスケープシーケンスを設定する必要があります。


Expand Down Expand Up @@ -599,6 +599,17 @@ ble-bind -f C-t my/example1
`fzf``ble.sh` と一緒にお使いいただく場合には、[`contrib/fzf` 統合機能](https://github.com/akinomyoga/blesh-contrib#pencil-fzf-integration) を用いて `fzf` を設定していただく必要があります。
詳細についてはリンク先の説明を御覧ください。

```bash
# blerc

# 注意: fzf を bash_completion と組み合わせて使用する場合は、fzf-completion よ
# りも先に bash_completion をロードしておく必要があります。
source /etc/profile.d/bash_completion.sh

ble-import -d contrib/fzf-completion
ble-import -d contrib/fzf-key-bindings
```

# 3 ヒント

## 3.1 複数行モード
Expand All @@ -622,7 +633,7 @@ Bash 4.0 以降では自動補完が有効になり、予測候補が表示さ
候補を確定するには <kbd>S-RET</kbd> を入力します (編集文字列の末尾にいる時は <kbd>right</kbd>, <kbd>C-f</kbd> または <kbd>end</kbd> でも確定できます)。
表示されている候補の初めの単語だけ部分的に確定する時は <kbd>M-f</kbd> または <kbd>M-right</kbd> を入力します。
現在の候補で確定しそのままコマンドを実行する場合には <kbd>C-RET</kbd> (※お使いの端末が対応している時) を入力します。
お使いの端末が対応していない時は [マニュアル §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#sec-modifyOtherKeys-manual) を参照して下さい。
お使いの端末が対応していない時は [マニュアル §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-modifyOtherKeys-manual) を参照して下さい。


## 3.4 静的略語展開
Expand Down
27 changes: 20 additions & 7 deletions README.md
Expand Up @@ -516,24 +516,26 @@ For example, with the following setting, "Hello, world!" will be inserted on typ
ble-bind -f 'C-x h' 'insert-string "Hello, world!"'
```

The details on the key representation like <kbd>C-x</kbd> is described in [Manual §3.1](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-kspecs).
The representations of space/tab/enter/backspace/escape, etc. are described in [Manual §3.1.1](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-kspecs-ret):
The details on the key representation, such as <kbd>C-x h</kbd> in the above example,
are described in [Manual §3.1](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-kspecs).
The representations of <kbd>Space</kbd>, <kbd>Tab</kbd>, <kbd>Enter</kbd>, <kbd>Backspace</kbd>, <kbd>Escape</kbd>, etc. are described
in [Manual §3.1.1](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-kspecs-ret):
The space is represented as <kbd>SP</kbd>,
the tab key is represented as <kbd>C-i</kbd> or <kbd>TAB</kbd> depending on the terminal,
the enter/return key is represented as <kbd>C-m</kbd> or <kbd>RET</kbd> depending on the terminal,
and the backspace key is represented as <kbd>C-?</kbd>, <kbd>DEL</kbd>, <kbd>C-h</kbd>, or <kbd>BS</kbd> depending on the terminal.
The representations of modified special keys such as <kbd>Ctrl+Return</kbd> and <kbd>Shift+Return</kbd> are described
in [Manual §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#sec-modifyOtherKeys-manual):
in [Manual §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-modifyOtherKeys-manual):
If your terminal does not support `modifyOtherKeys`, you need to manually configure the escape sequences of modified special keys.


For another example, if you want to invoke a command on typing <kbd>M-c</kbd>, you can write as follows:
For another example, if you want to invoke a command on typing <kbd>M-c</kbd>, you can write it as follows:

```bash
ble-bind -c 'M-c' 'my-command'
```

Or, if you want to invoke a edit function (designed for Bash `bind -x`) on typing <kbd>C-r</kbd>, you can write as follows:
Or, if you want to invoke a edit function (designed for Bash `bind -x`) on typing <kbd>C-r</kbd>, you can write it as follows:

```bash
ble-bind -x 'C-r' 'my-edit-function'
Expand Down Expand Up @@ -568,7 +570,18 @@ ble-bind -f C-t my/example1
## 2.8 fzf integration

If you would like to use `fzf` in combination with `ble.sh`, you need to configure `fzf` using [the `contrib/fzf` integration](https://github.com/akinomyoga/blesh-contrib#pencil-fzf-integration).
Please follow the instructions in the link.
Please follow the instructions in the link for the detailed description.

```bash
# blerc

# Note: If you want to combine fzf-completion with bash_completion, you need to
# load bash_completion earilier than fzf-completion.
source /etc/profile.d/bash_completion.sh

ble-import -d contrib/fzf-completion
ble-import -d contrib/fzf-key-bindings
```

# 3 Tips

Expand Down Expand Up @@ -596,7 +609,7 @@ The suggested contents can be inserted by typing <kbd>S-RET</kbd>
If you want to insert only first word of the suggested contents, you can use <kbd>M-right</kbd> or <kbd>M-f</kbd>.
If you want to accept the suggestion and immediately run the command, you can use <kbd>C-RET</kbd>
(if your terminal does not support special key combinations like <kbd>C-RET</kbd>, please check
[Manual §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#sec-modifyOtherKeys-manual)).
[Manual §3.6.4](https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A73-Key-Binding#user-content-sec-modifyOtherKeys-manual)).

## 3.4 Use `sabbrev` (static abbrev expansions)

Expand Down
2 changes: 1 addition & 1 deletion contrib
Submodule contrib updated 1 files
+19 −4 README.md
2 changes: 2 additions & 0 deletions docs/ChangeLog.md
Expand Up @@ -330,6 +330,7 @@
- main: fix adjustments of bash options (reported by rashil2000) `#D1895` 138c476
- complete: suppress error messages for non-bash_completion `_parse_help` (reported by nik312123) `#D1900` 267de7f
- prompt: fix the marker position for the readline variable `show-mode-in-prompt` (reported by Strykar) `#D1903` 09bb4d3
- highlight: fix a bug that `bleopt filename_ls_colors` is not working (reported by qoreQyaS) `#D1919` xxxxxxx

## Documentation

Expand All @@ -342,6 +343,7 @@
- wiki/Q&A: add item for defining a widget calling multiple widgets (motivated by micimize) `#D1898` e19b796
- blerc: rename from `blerc` to `blerc.template` `#D1899` e19b796
- 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 xxxxxxx
- README: add links to Manual pages for *kspec* and `modifyOtherKeys` `#D1917` xxxxxxx

## Optimization
Expand Down
34 changes: 19 additions & 15 deletions lib/core-syntax.sh
Expand Up @@ -6438,8 +6438,12 @@ function ble/syntax/highlight/ls_colors/.parse {
done
}

## @fn ble/syntax/highlight/ls_colors
## @var[in,out] type
## @fn ble/syntax/highlight/ls_colors filename
## 対応する LS_COLORS 設定が見つかった時に g を上書きし成功します。
## それ以外の場合は g は変更せず失敗します。
## @param[in] filename
## @var[in] type
## @var[in,out] g
function ble/syntax/highlight/ls_colors {
local file=$1
if ((type==ATTR_FILE_FILE)); then
Expand All @@ -6448,15 +6452,18 @@ function ble/syntax/highlight/ls_colors {
ext=${ext#*.}
[[ $ext ]] || break
if ble/syntax/highlight/ls_colors/.read-extension "$ext"; then
type=g:$ret
local g1=$ret
ble/color/face2g filename_ls_colors; g=$ret
ble/color/g#append g "$g1"
return 0
fi
done
fi

local g=${_ble_syntax_highlight_lscolors[type]}
if [[ $g ]]; then
type=g:$g
local g1=${_ble_syntax_highlight_lscolors[type]}
if [[ $g1 ]]; then
ble/color/face2g filename_ls_colors; g=$ret
ble/color/g#append g "$g1"
return 0
fi

Expand All @@ -6467,9 +6474,7 @@ function ble/syntax/highlight/getg-from-filename {
local filename=$1 type=
ble/syntax/highlight/filetype "$filename"
if [[ $bleopt_filename_ls_colors ]]; then
if ble/syntax/highlight/ls_colors "$filename" && [[ $type == g:* ]]; then
local ret; ble/color/face2g filename_ls_colors; g=$ret
((g|=${type:2}))
if ble/syntax/highlight/ls_colors "$filename"; then
return 0
fi
fi
Expand Down Expand Up @@ -6758,8 +6763,10 @@ function ble/progcolor/highlight-filename/.pathspec.wattr {

if ble/syntax/util/is-directory "$epath"; then
local type
ble/syntax/highlight/filetype "$epath" &&
ble/syntax/attr2g "$type"
if ble/syntax/highlight/filetype "$epath"; then
ble/syntax/highlight/ls_colors ||
ble/syntax/attr2g "$type"
fi
elif ((wtype==CTX_CMDI)); then
# コマンド名の時はディレクトリが存在する必要 #D1419
ble/syntax/attr2g "$ATTR_ERR"
Expand Down Expand Up @@ -6839,10 +6846,7 @@ function ble/progcolor/highlight-filename/.pathspec-by-name.wattr {

local g=
if [[ $bleopt_filename_ls_colors ]]; then
if ble/syntax/highlight/ls_colors "$value" && [[ $type == g:* ]]; then
local ret; ble/color/face2g filename_ls_colors; g=$ret
type=g:$((${type:2}|g))
fi
ble/syntax/highlight/ls_colors "$value"
fi
[[ $type && ! $g ]] && ble/syntax/attr2g "$type"

Expand Down
24 changes: 23 additions & 1 deletion note.txt
Expand Up @@ -6664,6 +6664,24 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-12-13

* highlight: パス名着色において ls_colors が動いていなかった (reported by qoreQyaS) [#D1919]
https://github.com/akinomyoga/ble.sh/issues/263

どうも type=g:* の形で指定した後にそれを外側で g に反映させる事になっている
のが反映させていなかったのが問題であった。いつ壊れたのか確認した。3f1f472d
#D1095 で type == g:* の時の特別の処理が削除されている。実に3年半も動かない
状態で放置されていた事になる。

ディレクトリ名に関しては単純に今まで対応していなかった。

ble/syntax/highlight/ls_colors の値の返し方自体を変更する事にした。この関数
は今迄二箇所でしか呼び出していなくて、両方で呼び出し側で同様に色の合成など
を行っていたので、その色の合成も ble/syntax/highlight/ls_colors に統合する
事にした。そして直接に g に書き込む様に振る舞いを変更した。その上で / の前
のディレクトリ名の ls_colors による着色にも対応した。動いている。

2022-12-11

* colorglass: オプションで指定した時に256色(またはより少ない色に)に減色する機能? [#D1918]
Expand Down Expand Up @@ -6846,8 +6864,9 @@ bash_tips

2022-12-05

* README: fzf-integration について記述する (motivated by SuperSandro2000) [#D1907]
* README: fzf-integration について記述する (motivated by SuperSandro2000, tbagrel1) [#D1907]
https://github.com/akinomyoga/ble.sh/issues/259
https://github.com/akinomyoga/ble.sh/issues/261#issuecomment-1346450426

* display-shell-version にも integration が入っていない時にメッセージを表示
する様にする。fzf についてはメッセージを出力した。
Expand Down Expand Up @@ -6882,6 +6901,9 @@ bash_tips

https://github.com/ajeetdsouza/zoxide/commit/d106f4e3580d5594d8f1c96c256a8f085e2781a4

2022-12-13 更に bash_completion を先にロードしておくべきという事についても
記述した。

* colorglass: saturation (彩度) についての設定を追加する (motivated by auwsom) [#D1906]
https://github.com/akinomyoga/ble.sh/issues/258

Expand Down

0 comments on commit b568ade

Please sign in to comment.