From 2bf5fa27be9201cd8a29d9212550ab989968050e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 27 Jan 2025 19:19:08 +0900 Subject: [PATCH] [completion] Replace 'tr' with built-in string substitution --- shell/completion.bash | 5 +++-- shell/completion.zsh | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/shell/completion.bash b/shell/completion.bash index 0c53e8e6..686ca4c6 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -412,7 +412,7 @@ _fzf_proc_completion() { local transformer transformer=' if [[ $FZF_KEY =~ ctrl|alt|shift ]] && [[ -n $FZF_NTH ]]; then - nths=( $(tr , " " <<< "$FZF_NTH") ) + nths=( ${FZF_NTH//,/ } ) new_nths=() found=0 for nth in ${nths[@]}; do @@ -423,7 +423,8 @@ _fzf_proc_completion() { fi done [[ $found = 0 ]] && new_nths+=($FZF_CLICK_HEADER_NTH) - new_nths=$(echo ${new_nths[@]} | tr " " ,) + new_nths=${new_nths[*]} + new_nths=${new_nths// /,} echo "change-nth($new_nths)+change-prompt($new_nths> )" else if [[ $FZF_NTH = $FZF_CLICK_HEADER_NTH ]]; then diff --git a/shell/completion.zsh b/shell/completion.zsh index 1199ac54..22c662b0 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -293,7 +293,7 @@ _fzf_complete_kill() { local transformer transformer=' if [[ $FZF_KEY =~ ctrl|alt|shift ]] && [[ -n $FZF_NTH ]]; then - nths=( $(tr , " " <<< "$FZF_NTH") ) + nths=( ${FZF_NTH//,/ } ) new_nths=() found=0 for nth in ${nths[@]}; do @@ -304,7 +304,8 @@ _fzf_complete_kill() { fi done [[ $found = 0 ]] && new_nths+=($FZF_CLICK_HEADER_NTH) - new_nths=$(echo ${new_nths[@]} | tr " " ,) + new_nths=${new_nths[*]} + new_nths=${new_nths// /,} echo "change-nth($new_nths)+change-prompt($new_nths> )" else if [[ $FZF_NTH = $FZF_CLICK_HEADER_NTH ]]; then