Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto strip cwd prefix if fd >= 8.3.0 #18

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions functions/_fifc.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function _fifc
set -l fish_version (string split -- '.' $FISH_VERSION)
set -l result
set -Ux _fifc_extract_regex
set -gx _fifc_complist_path (string join '' (mktemp) "_fifc")
Expand All @@ -16,8 +15,7 @@ function _fifc
set fifc_commandline $argv
end

# --escape is only available on fisher 3.4+
if test \( $fish_version[1] -eq 3 -a $fish_version[2] -ge 4 \) -o \( $fish_version[1] -gt 3 \)
if _fifc_test_version "$FISH_VERSION" -ge "3.4"
set complete_opts --escape
end

Expand Down
8 changes: 6 additions & 2 deletions functions/_fifc_source_files.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ function _fifc_source_files -d "Return a command to recursively find files"
end

if type -q fd
if _fifc_test_version (fd --version) -ge "8.3.0"
set fd_custom_opts --strip-cwd-prefix
end

if test "$path" = {$PWD}/
echo "fd . --color=always $fifc_fd_opts"
echo "fd . --color=always $fd_custom_opts $fifc_fd_opts"
else if test "$path" = "."
echo "fd . --color=always --hidden $fifc_fd_opts"
echo "fd . --color=always --hidden $fd_custom_opts $fifc_fd_opts"
else if test -n "$hidden"
echo "fd . --color=always --hidden $fifc_fd_opts -- $path"
else
Expand Down
18 changes: 18 additions & 0 deletions functions/_fifc_test_version.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function _fifc_test_version -d "Compare version numbers"
set -l arg_1 (string replace --regex --all '[^\d]' '' -- "$argv[1]")
set -l arg_2 (string replace --regex --all '[^\d]' '' -- "$argv[3]")
set -l op "$argv[2]"

set -l v_diff (math (string length -- $arg_1) - (string length -- $arg_2))

# Ensure both versions are the same length
if test $v_diff -gt 0
set arg_2 (string join '' -- "$arg_2" (string repeat -N -n $v_diff '0'))
else if test $v_diff -lt 0
set v_diff (math abs $v_diff)
set arg_1 (string join '' -- "$arg_1" (string repeat -N -n $v_diff '0'))
end

set -l cmd (string collect -- "test " "$arg_1" " $op " "$arg_2")
eval $cmd
end
32 changes: 32 additions & 0 deletions tests/version_test.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set -l actual (_fifc_test_version "3.4" -gt "3.0")
@test "version test basic gt" $status = 0

set -l actual (_fifc_test_version "3.4" -ge "3.4")
@test "version test basic ge equal" $status = 0

set -l actual (_fifc_test_version "3.5" -ge "3.4")
@test "version test basic ge greater" $status = 0

set -l actual (_fifc_test_version "3.4" -lt "3.5")
@test "version test basic lt" $status = 0

set -l actual (_fifc_test_version "3.4" -le "3.4")
@test "version test basic le equal" $status = 0

set -l actual (_fifc_test_version "3.4" -le "3.5")
@test "version test basic le lower" $status = 0

set -l actual (_fifc_test_version "3.4" -gt "3")
@test "version test length not equal" $status = 0

set -l actual (_fifc_test_version "3.4" -gt "3")
@test "version test length not equal 1" $status = 0

set -l actual (_fifc_test_version "3" -gt "3.4")
@test "version test length not equal 2" $status = 1

set -l actual (_fifc_test_version "fish 3.5.0" -gt "3.4.2")
@test "version test extract version left" $status = 0

set -l actual (_fifc_test_version "3.5.0" -gt "fish 3.4.2")
@test "version test extract version right" $status = 0