2014-01-20 06:19:41 +00:00
|
|
|
function fish_vi_cursor -d 'Set cursor shape for different vi modes'
|
2023-11-14 17:09:04 +00:00
|
|
|
# if stdin is not a tty, there is effectively no bind mode.
|
|
|
|
if not test -t 0
|
2018-06-01 18:26:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-05-05 15:31:33 +00:00
|
|
|
# This is hard to test in expect, since the exact sequences depend on the environment.
|
|
|
|
# Instead disable it.
|
|
|
|
if set -q FISH_UNIT_TESTS_RUNNING
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-05-14 20:24:52 +00:00
|
|
|
# If this variable is set, skip all checks
|
|
|
|
if not set -q fish_vi_force_cursor
|
2016-12-03 12:25:46 +00:00
|
|
|
|
2020-05-14 20:24:52 +00:00
|
|
|
# Emacs Makes All Cursors Suck
|
|
|
|
if set -q INSIDE_EMACS
|
|
|
|
return
|
|
|
|
end
|
2016-12-03 12:25:46 +00:00
|
|
|
|
2020-05-14 20:24:52 +00:00
|
|
|
# vte-based terms set $TERM = xterm*, but only gained support in 2015.
|
|
|
|
# From https://bugzilla.gnome.org/show_bug.cgi?id=720821, it appears it was version 0.40.0
|
|
|
|
if set -q VTE_VERSION
|
|
|
|
and test "$VTE_VERSION" -lt 4000 2>/dev/null
|
|
|
|
return
|
|
|
|
end
|
2019-04-28 09:59:11 +00:00
|
|
|
|
2020-05-14 20:24:52 +00:00
|
|
|
# Similarly, genuine XTerm can do it since v280.
|
|
|
|
if set -q XTERM_VERSION
|
|
|
|
and not test (string replace -r "XTerm\((\d+)\)" '$1' -- "$XTERM_VERSION") -ge 280 2>/dev/null
|
|
|
|
return
|
|
|
|
end
|
2016-10-27 08:16:57 +00:00
|
|
|
|
2020-05-14 20:24:52 +00:00
|
|
|
# We need one of these terms.
|
|
|
|
# It would be lovely if we could rely on terminfo, but:
|
|
|
|
# - The "Ss" entry isn't a thing in macOS' old and crusty terminfo
|
|
|
|
# - It is set for xterm, and everyone and their dog claims to be xterm
|
|
|
|
#
|
|
|
|
# So we just don't care about $TERM, unless it is one of the few terminals that actually have their own entry.
|
|
|
|
if not set -q KONSOLE_PROFILE_NAME
|
2020-05-19 18:41:47 +00:00
|
|
|
and not test -n "$KONSOLE_VERSION" -a "$KONSOLE_VERSION" -ge 200400 # konsole, but new.
|
2020-05-14 20:24:52 +00:00
|
|
|
and not set -q ITERM_PROFILE
|
|
|
|
and not set -q VTE_VERSION # which version is already checked above
|
2020-05-12 21:10:57 +00:00
|
|
|
and not set -q WT_PROFILE_ID
|
2020-05-14 20:24:52 +00:00
|
|
|
and not set -q XTERM_VERSION
|
2021-11-23 03:55:15 +00:00
|
|
|
and not string match -q Apple_Terminal -- $TERM_PROGRAM
|
2020-05-14 20:24:52 +00:00
|
|
|
and not string match -rq '^st(-.*)$' -- $TERM
|
|
|
|
and not string match -q 'xterm-kitty*' -- $TERM
|
|
|
|
and not string match -q 'rxvt*' -- $TERM
|
|
|
|
and not string match -q 'alacritty*' -- $TERM
|
2024-08-26 17:23:58 +00:00
|
|
|
and not string match -q 'xterm-ghostty*' -- $TERM
|
2021-11-08 19:01:43 +00:00
|
|
|
and not string match -q 'foot*' -- $TERM
|
2022-06-20 15:37:22 +00:00
|
|
|
and not begin
|
|
|
|
set -q TMUX
|
|
|
|
and string match -qr '^screen|^tmux' -- $TERM
|
|
|
|
end
|
2020-05-14 20:24:52 +00:00
|
|
|
return
|
|
|
|
end
|
2019-05-05 11:01:02 +00:00
|
|
|
end
|
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
set -l terminal $argv[1]
|
|
|
|
set -q terminal[1]
|
|
|
|
or set terminal auto
|
2014-01-20 06:19:41 +00:00
|
|
|
|
2023-03-31 18:06:09 +00:00
|
|
|
set -l function __fish_cursor_xterm
|
2014-01-20 06:19:41 +00:00
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
set -q fish_cursor_unknown
|
2022-06-07 12:25:03 +00:00
|
|
|
or set -g fish_cursor_unknown block
|
2014-01-20 12:07:32 +00:00
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
echo "
|
2023-11-14 17:31:35 +00:00
|
|
|
function fish_vi_cursor_handle --on-variable fish_bind_mode --on-event fish_postexec --on-event fish_focus_in --on-event fish_read
|
2016-05-30 14:36:25 +00:00
|
|
|
set -l varname fish_cursor_\$fish_bind_mode
|
|
|
|
if not set -q \$varname
|
|
|
|
set varname fish_cursor_unknown
|
|
|
|
end
|
|
|
|
$function \$\$varname
|
|
|
|
end
|
|
|
|
" | source
|
2016-09-04 23:20:12 +00:00
|
|
|
|
|
|
|
echo "
|
|
|
|
function fish_vi_cursor_handle_preexec --on-event fish_preexec
|
2023-03-14 09:50:20 +00:00
|
|
|
set -l varname fish_cursor_external
|
|
|
|
if not set -q \$varname
|
|
|
|
set varname fish_cursor_default
|
|
|
|
end
|
2016-09-04 23:20:12 +00:00
|
|
|
if not set -q \$varname
|
|
|
|
set varname fish_cursor_unknown
|
|
|
|
end
|
|
|
|
$function \$\$varname
|
|
|
|
end
|
|
|
|
" | source
|
2014-01-20 06:19:41 +00:00
|
|
|
end
|