Skip to content

Commit a8c683e

Browse files
josephschmittopencode
andcommitted
Auto-adjust sort order based on fzf layout
- Default layout (search at bottom): Recent URLs first (top of list) - Reverse layout (search at top): Recent URLs last (bottom of list) This ensures recent URLs are always closest to the search bar. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
1 parent d30b94e commit a8c683e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fzf-url.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,24 @@ if [[ "$sort_by" == "alphabetical" ]]; then
5757
# Original behavior: sort alphabetically and remove duplicates
5858
items=$(echo "$all_urls" | cut -d: -f2- | sort -u | nl -w3 -s ' ')
5959
else
60-
# Default recency behavior: most recent URLs first, remove duplicates keeping first occurrence
60+
# Default recency behavior: adjust sort order based on fzf layout
61+
fzf_options="$(get_fzf_options)"
62+
if [[ "$fzf_options" == *"--reverse"* ]]; then
63+
# Reverse layout (search at top): oldest URLs first so recent ones are closest to search
64+
sort_order="-n"
65+
else
66+
# Default layout (search at bottom): newest URLs first so recent ones are closest to search
67+
sort_order="-nr"
68+
fi
69+
6170
items=$(echo "$all_urls" | awk -F: '
6271
{
6372
url = substr($0, index($0, ":") + 1)
6473
if (!seen[url]) {
6574
seen[url] = 1
6675
print $1 ":" url
6776
}
68-
}' | sort -nr | cut -d: -f2- | nl -w3 -s ' ')
77+
}' | sort $sort_order | cut -d: -f2- | nl -w3 -s ' ')
6978
fi
7079
[ -z "$items" ] && tmux display 'tmux-fzf-url: no URLs found' && exit
7180

0 commit comments

Comments
 (0)