From 884c3b1dec9d2125ff640ada374c811ae3d855bf Mon Sep 17 00:00:00 2001 From: LangLangbart <92653266+LangLangBart@users.noreply.github.com> Date: Fri, 17 May 2024 15:43:26 +0200 Subject: [PATCH] fix: trim whitespace before checking query --- gh-find-code | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gh-find-code b/gh-find-code index 0e3535e..2b09ace 100755 --- a/gh-find-code +++ b/gh-find-code @@ -39,9 +39,8 @@ if ((GHFC_DEBUG_MODE)); then exec 6>>"$store_all_debug" BASH_XTRACEFD=6 # Use a more detailed execution trace prompt. - # Check if the date command supports milliseconds; macOS native 'date' doesn't support '%3N' PS4='+ $(date +%H:%M:%S:%3N) [${BASH_SOURCE[0]:+${BASH_SOURCE[0]##*/}}:${FUNCNAME[0]:+${FUNCNAME[0]}():}${LINENO}]: ' - # Fall back to zsh for displaying milliseconds with prompt sequences + # Use zsh for milliseconds in prompt; macOS 'date' lacks '%3N' support if command -v zsh &>/dev/null && [[ "$(date +%3N 2>/dev/null)" == "3N" ]]; then PS4='+ $(zsh -c "print -Pr -- %D{%T:%3.}") [${BASH_SOURCE[0]:+${BASH_SOURCE[0]##*/}}:${FUNCNAME[0]:+${FUNCNAME[0]}():}${LINENO}]: ' fi @@ -434,7 +433,11 @@ gh_query() { local matched_line error_encountered update_preview_window_size redirect_location index_color local base_name dir_name declare -a line_numbers - if [[ -z $FZF_QUERY ]]; then + + # delete leading and trailing whitespace from the query + trimmed_query=$(command awk '{$1=$1;print}' <<<"$FZF_QUERY") + + if [[ -z $trimmed_query ]]; then # in cases where the user enters a space, causing a failure in search, and then deletes the # space, the prompt needs to be reset reset_default_prompt @@ -442,9 +445,6 @@ gh_query() { return fi - # delete leading and trailing whitespace from the query - trimmed_query=$(command awk '{$1=$1;print}' <<<"$FZF_QUERY") - # If the query is the same as before, don't bother running it again, provided that the results # of the last query are still there and there was no error. Useful when switching between fuzzy # mode and search mode.