diff --git a/.config/fish/config.fish b/.config/fish/config.fish index ec7ca58..19dffe5 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -15,7 +15,13 @@ if status is-interactive abbr -a rootnvim sudo -Es nvim - fzf --fish | source + if fish_version_test (fzf --version | cut -d ' ' -f 1) -gt '0.48.0' + fzf --fish | source + else + source /usr/share/doc/fzf/examples/key-bindings.fish + fzf_key_bindings + end + # keeping this in the end zoxide init fish | source end diff --git a/.config/fish/functions/fish_version_test.fish b/.config/fish/functions/fish_version_test.fish new file mode 100644 index 0000000..81062f4 --- /dev/null +++ b/.config/fish/functions/fish_version_test.fish @@ -0,0 +1,37 @@ +function fish_version_test + if test (count $argv) = 2 + if test -n "$version" + set operand_a "$version" + else + set operand_a "$FISH_VERSION" + end + set op "$argv[1]" + set operand_b "$argv[2]" + else if test (count $argv) = 3 + set operand_a "$argv[1]" + set op "$argv[2]" + set operand_b "$argv[3]" + else + echo "fish_version_test can be called in two forms:" + echo "fish_version_test -op version" + echo "fish_version_test version_a -op version_b" + exit 1 + end + + set -l arg_1 (string replace --regex --all '[^\d]' '' -- "$operand_a") + set -l arg_2 (string replace --regex --all '[^\d]' '' -- "$operand_b") + + + 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