mirror of
https://github.com/Aloxaf/fzf-tab.git
synced 2026-09-10 07:26:16 -04:00
* Feat: support different styling for the group labels
* Fix: improved portability of code to macOS
* Refactor: use robust template file for ftb_preview_init
* refactor: retrieve active-group-style as array, simplify normalization
Keeps the type prefix consistent with the project history. It covers both changes: switching from -s to -a (which also changes the user-facing syntax to space-separated, consistent with all other multi-value zstyles), and replacing the 60-line anonymous function with a clean four-step variable breakdown.
---
```zsh
test_normalize() {
local -a active_group_style=("$@")
local -a _active_style_lower=(${(L)active_group_style})
local -a _active_style_valid=(${(M)_active_style_lower:#(bold|underline|none)})
local -a _active_style_sorted=(${(ou)_active_style_valid})
local normalized=${${(j:,:)_active_style_sorted}:-none}
echo "input=(${(j: :)active_group_style}) → \"$normalized\""
}
test_normalize bold
test_normalize underline
test_normalize bold underline
test_normalize underline bold # order should not matter
test_normalize BOLD UNDERLINE # uppercase
test_normalize bold bold # duplicates
test_normalize none
test_normalize italic # unknown → none fallback
test_normalize bold italic # mixed valid+invalid
test_normalize # empty → none fallback
```
input=(bold) → "bold"
input=(underline) → "underline"
input=(bold underline) → "bold,underline"
input=(underline bold) → "bold,underline"
input=(BOLD UNDERLINE) → "bold,underline"
input=(bold bold) → "bold"
input=(none) → "none"
input=(italic) → "none"
input=(bold italic) → "bold"
input=() → "none"
* fix: avoid code duplication in `initial_command` array and `reload_command` with 0 appended as the offset
Note: (z) splits the string using shell word-splitting rules, turning the string back into an array of tokens, then 0 is appended as the offset for the initial render.
Co-authored-by: Aloxaf <aloxafx@gmail.com>
* fix: restoring the (z) flag on $fzf_command. The original code used ${(z)fzf_command} which splits the command string into words. The PR changed it to just $fzf_command.
Co-authored-by: Aloxaf <aloxafx@gmail.com>
* refactor: changed `"${initial_command[@]}"` (POSIX-style expansion) to `$initial_command` (zsh-idiomatic expansion of an array)
Co-authored-by: Aloxaf <aloxafx@gmail.com>
* refactor: avoided anonymous function
Co-authored-by: Aloxaf <aloxafx@gmail.com>
* refactor: replaced echo for `print -r --` and removed trailing spaces
Co-authored-by: Aloxaf <aloxafx@gmail.com>
---------
Co-authored-by: Aloxaf <aloxafx@gmail.com>
22 lines
571 B
Smarty
Executable file
22 lines
571 B
Smarty
Executable file
zmodload zsh/mapfile
|
|
local -a _ftb_compcap=("${(@f)mapfile[__FTB_COMPCAP__]}")
|
|
local -a _ftb_groups=("${(@f)mapfile[__FTB_GROUPS__]}")
|
|
local bs=$'\2'
|
|
|
|
# get description
|
|
export desc=${${"$(<'{f}')"%$'\0'*}#*$'\0'}
|
|
# get ctxt for current completion
|
|
local -A ctxt=("${(@0)${_ftb_compcap[(r)${(b)desc}$bs*]#*$bs}}")
|
|
# get group
|
|
if (( $+ctxt[group] )); then
|
|
export group=$_ftb_groups[$ctxt[group]]
|
|
fi
|
|
# get original word
|
|
export word=${(Q)ctxt[word]}
|
|
# get real path if it is file
|
|
if (( $+ctxt[realdir] )); then
|
|
export realpath=${ctxt[realdir]}$word
|
|
fi
|
|
__FTB_WORDS_DUMP__
|
|
|