2014-01-20 06:19:41 +00:00
|
|
|
function fish_vi_cursor -d 'Set cursor shape for different vi modes'
|
2018-06-01 18:26:54 +00:00
|
|
|
# If we're not interactive, there is effectively no bind mode.
|
|
|
|
if not status is-interactive
|
|
|
|
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
|
|
|
|
|
2019-04-28 16:06:39 +00:00
|
|
|
# Emacs Makes All Cursors Suck
|
2016-12-03 12:25:46 +00:00
|
|
|
if set -q INSIDE_EMACS
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-04-28 10:07:38 +00:00
|
|
|
# vte-based terms set $TERM = xterm*, but only gained support in 2015.
|
2016-12-03 12:25:46 +00:00
|
|
|
# From https://bugzilla.gnome.org/show_bug.cgi?id=720821, it appears it was version 0.40.0
|
|
|
|
if set -q VTE_VERSION
|
2018-04-01 20:42:38 +00:00
|
|
|
and test "$VTE_VERSION" -lt 4000 2>/dev/null
|
2016-12-03 12:25:46 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-04-28 10:07:38 +00:00
|
|
|
# Similarly, genuine XTerm can do it since v280.
|
2019-04-28 09:59:11 +00:00
|
|
|
if set -q XTERM_VERSION
|
|
|
|
and not test (string replace -r "XTerm\((\d+)\)" '$1' -- "$XTERM_VERSION") -ge 280 2>/dev/null
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-04-28 10:07:38 +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
|
|
|
|
#
|
2019-04-28 10:50:06 +00:00
|
|
|
# So we just don't care about $TERM, unless it is one of the few terminals that actually have their own entry.
|
2019-04-28 10:07:38 +00:00
|
|
|
#
|
|
|
|
# Note: Previous versions also checked $TMUX, and made sure that then $TERM was screen* or tmux*.
|
|
|
|
# We don't care, since we *cannot* handle term-in-a-terms 100% correctly.
|
|
|
|
if not set -q KONSOLE_PROFILE_NAME
|
|
|
|
and not set -q ITERM_PROFILE
|
|
|
|
and not set -q VTE_VERSION # which version is already checked above
|
|
|
|
and not set -q XTERM_VERSION
|
2019-04-28 10:50:06 +00:00
|
|
|
and not string match -rq '^st(-.*)$' -- $TERM
|
|
|
|
and not string match -q 'xterm-kitty*' -- $TERM
|
|
|
|
and not string match -q 'rxvt*' -- $TERM
|
2016-10-27 21:04:12 +00:00
|
|
|
return
|
2016-10-27 08:16:57 +00:00
|
|
|
end
|
|
|
|
|
2019-05-05 11:01:02 +00:00
|
|
|
# HACK: Explicitly disable on ITERM because of #3696, which is weirdness with multi-line prompts.
|
|
|
|
# We allow an explicit "--force-iterm" as first argument to skip this.
|
|
|
|
# It's recommended only if you don't use a multi-line prompt.
|
2019-05-05 11:04:50 +00:00
|
|
|
if contains -- $argv[1] --force-iterm
|
|
|
|
set -e argv[1]
|
|
|
|
else if set -q ITERM_PROFILE
|
|
|
|
return
|
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
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
set -l function
|
|
|
|
switch "$terminal"
|
|
|
|
case auto
|
2019-04-28 16:06:39 +00:00
|
|
|
# TODO: Konsole as of 18.08 knows the xterm sequences,
|
|
|
|
# but there's still bugs with it (as of konsole 19.04.0).
|
|
|
|
#
|
|
|
|
# If it is fixed, we'd have to read $KONSOLE_VERSION for a while,
|
|
|
|
# though that was only introduced in 18.08 as well.
|
2016-05-30 14:36:25 +00:00
|
|
|
if set -q KONSOLE_PROFILE_NAME
|
|
|
|
set function __fish_cursor_konsole
|
2016-12-02 05:56:59 +00:00
|
|
|
else if set -q ITERM_PROFILE
|
|
|
|
set function __fish_cursor_1337
|
2016-10-27 21:04:12 +00:00
|
|
|
else
|
2016-05-30 14:36:25 +00:00
|
|
|
set function __fish_cursor_xterm
|
|
|
|
end
|
|
|
|
case konsole
|
|
|
|
set function __fish_cursor_konsole
|
|
|
|
case xterm
|
|
|
|
set function __fish_cursor_xterm
|
|
|
|
end
|
2014-01-20 06:19:41 +00:00
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
set -l tmux_prefix
|
|
|
|
set -l tmux_postfix
|
|
|
|
if set -q TMUX
|
|
|
|
set tmux_prefix echo -ne "'\ePtmux;\e'"
|
|
|
|
set tmux_postfix echo -ne "'\e\\\\'"
|
|
|
|
end
|
2014-01-20 17:28:54 +00:00
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
set -q fish_cursor_unknown
|
|
|
|
or set -g fish_cursor_unknown block blink
|
2014-01-20 12:07:32 +00:00
|
|
|
|
2016-05-30 14:36:25 +00:00
|
|
|
echo "
|
2018-03-07 10:06:23 +00:00
|
|
|
function fish_vi_cursor_handle --on-variable fish_bind_mode --on-event fish_postexec --on-event fish_focus_in
|
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
|
|
|
|
$tmux_prefix
|
|
|
|
$function \$\$varname
|
|
|
|
$tmux_postfix
|
|
|
|
end
|
|
|
|
" | source
|
2016-09-04 23:20:12 +00:00
|
|
|
|
|
|
|
echo "
|
|
|
|
function fish_vi_cursor_handle_preexec --on-event fish_preexec
|
|
|
|
set -l varname fish_cursor_default
|
|
|
|
if not set -q \$varname
|
|
|
|
set varname fish_cursor_unknown
|
|
|
|
end
|
|
|
|
$tmux_prefix
|
|
|
|
$function \$\$varname
|
|
|
|
$tmux_postfix
|
|
|
|
end
|
|
|
|
" | source
|
2014-01-20 06:19:41 +00:00
|
|
|
end
|
2014-01-20 17:28:54 +00:00
|
|
|
|