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)
This commit is contained in:
MorganGeek 2020-07-15 22:15:19 +02:00
parent 8d00c2d2f2
commit a85ab418ed

View File

@ -135,21 +135,21 @@ function whichfunc() {
type -a $1 type -a $1
} }
# TODO : suggest using long parameter names instead of short ones.... # TODO : suggest using long parameter names instead of short ones....
# TODO : suggest spelling fixes
function suggest_code_refactoring() { function suggest_code_refactoring() {
#inspired by : \grep 'awk '\''{$1=$1};1'\' $HOME/Code/dotfiles/dot_zsh* #inspired by : \grep 'awk '\''{$1=$1};1'\' $HOME/Code/dotfiles/dot_zsh*
header "code refactoring suggestions" header "code refactoring suggestions"
while read -r line; do while read -r line; do
local short_name=$(echo "$line" | sed -E "s/='.*//g") local short_name=$(echo "$line" | sed -E "s/='.*//g")
local alias_value=$(echo "$line" | sed -E 's/[a-zA-Z_-]+=//g') local alias_value=$(echo "$line" | sed -E 's/[a-zA-Z_-]+=//g')
local alias_value_truncated=${alias_value:1:$((${#alias_value}-2))} local alias_value_truncated=${alias_value:1:$((${#alias_value} - 2))}
#arrow "looking for opportunities to use alias $short_name instead of $alias_value_truncated" \fgrep $alias_value_truncated "$@" 2>/tmp/error.log | \grep -v "alias $short_name=" 1>/dev/null
\grep "$alias_value_truncated" $HOME/Code/dotfiles/dot_zsh_funct* 2>/tmp/error.log #/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
success "found $short_name --> $alias_value_truncated" 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 else
local error_message=$(\cat /tmp/error.log) 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" error "issue occured when looking for $alias_value_truncated : $error_message"
fi fi
fi fi