diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-07-09 10:28:35 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-07-09 10:28:35 +0900 |
| commit | 5f2313deb7c1187f8710724303aea078c24c7c0d (patch) | |
| tree | c95b60af4f25058ed60a73b419ed0bff136d2b11 /ar/.local/bin/rgafiles | |
| parent | 2088e95117ce98190e817593d3a7c9b781110d42 (diff) | |
modified bin/rgafiles, modified statusbar/sb-mic, created statusbar/sb-micup
Diffstat (limited to 'ar/.local/bin/rgafiles')
| -rwxr-xr-x | ar/.local/bin/rgafiles | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/ar/.local/bin/rgafiles b/ar/.local/bin/rgafiles index 57b19d4..02d8752 100755 --- a/ar/.local/bin/rgafiles +++ b/ar/.local/bin/rgafiles @@ -68,26 +68,27 @@ search_term() { count=$(echo "$files" | wc -l) if [ "$count" -eq 1 ]; then # Find the first matching line number in the selected file - line=$(rga --max-count=1 --line-number --no-filename ${case_flag:+$case_flag} --no-messages "$query" "$files" 2>/dev/null | head -1 | cut -d: -f1) - if [ -n "$line" ]; then - ${EDITOR:-nvim} "+${line}" "$(realpath "$files")" - else - openfiles "$files" - fi + line=$(rga --follow --no-ignore --hidden --text --max-count=1 --line-number --no-filename ${case_flag:+$case_flag} --no-messages "$query" "$files" 2>/dev/null | head -1 | cut -d: -f1) + case "$line" in + '' | *[!0-9]*) openfiles "$files" ;; + *) ${EDITOR:-nvim} "+${line}" "$(realpath "$files")" ;; + esac else # Multiple files: open at matching lines via quickfix tmpfile=$(mktemp) echo "$files" | while IFS= read -r file; do - match=$(rga --max-count=1 --line-number --no-filename ${case_flag:+$case_flag} --no-messages "$query" "$file" 2>/dev/null | head -1) - if [ -n "$match" ]; then - printf '%s:%s\n' "$(realpath "$file")" "$match" >> "$tmpfile" - else - printf '%s:1:\n' "$(realpath "$file")" >> "$tmpfile" - fi + match=$(rga --follow --no-ignore --hidden --text --max-count=1 --line-number --no-filename ${case_flag:+$case_flag} --no-messages "$query" "$file" 2>/dev/null | head -1) + # Entries must be 'path:LINE:non-empty-message' or nvim marks them + # invalid and :cc silently keeps the previous buffer in the split + linenum=${match%%:*} + case "$linenum" in + '' | *[!0-9]*) printf '%s:1:no match\n' "$(realpath "$file")" >> "$tmpfile" ;; + *) printf '%s:%s\n' "$(realpath "$file")" "$match" >> "$tmpfile" ;; + esac done if [ "$count" -lt 5 ]; then ${EDITOR:-nvim} -q "$tmpfile" \ - -c 'for i in range(2,len(getqflist())) | vsplit | execute "cc ".i | endfor | wincmd t' + -c 'let n=len(getqflist()) | if n >= 2 | vsplit | cc 2 | endif | if n >= 3 | split | cc 3 | endif | if n >= 4 | wincmd h | split | cc 4 | endif | wincmd t' else first_line=$(head -1 "$tmpfile" | cut -d: -f2) file_args="" @@ -149,26 +150,27 @@ list_or_open_project_files() { # Open files at matching lines file_count=$(echo "$rga_output" | wc -w) if [ "$file_count" -eq 1 ]; then - line=$(rga --max-count=1 --line-number --no-filename --no-messages "$project_tag" "$rga_output" 2>/dev/null | head -1 | cut -d: -f1) - if [ -n "$line" ]; then - ${EDITOR:-nvim} "+${line}" "$(realpath "$rga_output")" - else - openfiles "$rga_output" - fi + line=$(rga --follow --no-ignore --hidden --text --max-count=1 --line-number --no-filename --no-messages "$project_tag" "$rga_output" 2>/dev/null | head -1 | cut -d: -f1) + case "$line" in + '' | *[!0-9]*) openfiles "$rga_output" ;; + *) ${EDITOR:-nvim} "+${line}" "$(realpath "$rga_output")" ;; + esac else # Multiple files: open at matching lines via quickfix tmpfile=$(mktemp) for file in $rga_output; do - match=$(rga --max-count=1 --line-number --no-filename --no-messages "$project_tag" "$file" 2>/dev/null | head -1) - if [ -n "$match" ]; then - printf '%s:%s\n' "$(realpath "$file")" "$match" >> "$tmpfile" - else - printf '%s:1:\n' "$(realpath "$file")" >> "$tmpfile" - fi + match=$(rga --follow --no-ignore --hidden --text --max-count=1 --line-number --no-filename --no-messages "$project_tag" "$file" 2>/dev/null | head -1) + # Entries must be 'path:LINE:non-empty-message' or nvim marks them + # invalid and :cc silently keeps the previous buffer in the split + linenum=${match%%:*} + case "$linenum" in + '' | *[!0-9]*) printf '%s:1:no match\n' "$(realpath "$file")" >> "$tmpfile" ;; + *) printf '%s:%s\n' "$(realpath "$file")" "$match" >> "$tmpfile" ;; + esac done if [ "$file_count" -lt 5 ]; then ${EDITOR:-nvim} -q "$tmpfile" \ - -c 'for i in range(2,len(getqflist())) | vsplit | execute "cc ".i | endfor | wincmd t' + -c 'let n=len(getqflist()) | if n >= 2 | vsplit | cc 2 | endif | if n >= 3 | split | cc 3 | endif | if n >= 4 | wincmd h | split | cc 4 | endif | wincmd t' else ${EDITOR:-nvim} -q "$tmpfile" \ -c 'silent! for i in range(2,len(getqflist())+1) | execute "silent! cc ".i | endfor | silent! cfirst' |
