From a85ab418edd96dbaf49f49dbbcd56f13d81a8485 Mon Sep 17 00:00:00 2001 From: MorganGeek Date: Wed, 15 Jul 2020 22:15:19 +0200 Subject: [PATCH] improve: decrease rate of errors/false positives - avoid showing useless results (e.g : alias found himself...) - better handling of quotes/double quotes/dollars sign in searches, by switching to fgrep (thanks to https://unix.stackexchange.com/q/32018/220566 for the idea) --- dot_zsh_functions | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dot_zsh_functions b/dot_zsh_functions index 258e8fd..5fa302d 100644 --- a/dot_zsh_functions +++ b/dot_zsh_functions @@ -135,21 +135,21 @@ function whichfunc() { type -a $1 } # TODO : suggest using long parameter names instead of short ones.... +# TODO : suggest spelling fixes function suggest_code_refactoring() { #inspired by : \grep 'awk '\''{$1=$1};1'\' $HOME/Code/dotfiles/dot_zsh* header "code refactoring suggestions" while read -r line; do local short_name=$(echo "$line" | sed -E "s/='.*//g") local alias_value=$(echo "$line" | sed -E 's/[a-zA-Z_-]+=//g') - local alias_value_truncated=${alias_value:1:$((${#alias_value}-2))} - #arrow "looking for opportunities to use alias $short_name instead of $alias_value_truncated" - \grep "$alias_value_truncated" $HOME/Code/dotfiles/dot_zsh_funct* 2>/tmp/error.log #/dev/null + local alias_value_truncated=${alias_value:1:$((${#alias_value} - 2))} + \fgrep $alias_value_truncated "$@" 2>/tmp/error.log | \grep -v "alias $short_name=" 1>/dev/null if [ $? -eq 0 ]; then success "found $short_name --> $alias_value_truncated" - \grep "$alias_value_truncated" $HOME/Code/dotfiles/dot_zsh_funct* --color -n -H --line-buffered #2>/dev/null + \fgrep "$alias_value_truncated" "$@" --color -n -H --line-buffered | \grep -v "alias $short_name=" else local error_message=$(\cat /tmp/error.log) - if [ ! -z "$error_message" ]; then + if [ -n "$error_message" ]; then error "issue occured when looking for $alias_value_truncated : $error_message" fi fi