2014-01-20 14:19:41 +08:00
|
|
|
function fish_vi_cursor -d 'Set cursor shape for different vi modes'
|
2016-10-28 05:04:12 +08:00
|
|
|
# Check hard if we are in a supporting terminal.
|
|
|
|
#
|
|
|
|
# Challenges here are term-in-a-terms (emacs ansi-term does not support this, tmux does),
|
|
|
|
# that we can only figure out if we are in konsole/iterm/vte via exported variables,
|
|
|
|
# and ancient xterm versions.
|
|
|
|
#
|
|
|
|
# tmux defaults to $TERM = screen, but can do this if it is in a supporting terminal.
|
|
|
|
# Unfortunately, we can only detect this via the exported variables, so we miss some cases.
|
|
|
|
#
|
|
|
|
# We will also miss some cases of terminal-stacking,
|
|
|
|
# e.g. tmux started in suckless' st (no support) started in konsole.
|
|
|
|
# But since tmux in konsole seems rather common and that case so uncommon,
|
|
|
|
# we will just fail there (though it seems that tmux or st swallow it anyway).
|
2016-12-03 20:25:46 +08:00
|
|
|
|
|
|
|
if set -q INSIDE_EMACS
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# vte-based terms set $TERM = xterm*, but only gained support relatively recently.
|
|
|
|
# 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 ^/dev/null
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-10-28 05:04:12 +08:00
|
|
|
# We use the `tput` here just to see if terminfo thinks we can change the cursor.
|
|
|
|
# We cannot use that sequence directly as it's not the correct one for konsole and iTerm,
|
|
|
|
# and because we may want to change the cursor even though terminfo says we can't (tmux).
|
2016-11-28 13:27:22 +08:00
|
|
|
if not tput Ss >/dev/null ^/dev/null
|
2016-10-28 05:04:12 +08:00
|
|
|
# Whitelist tmux...
|
|
|
|
and not begin
|
|
|
|
set -q TMUX
|
|
|
|
# ...in a supporting term...
|
|
|
|
and begin set -q KONSOLE_PROFILE_NAME
|
|
|
|
or set -q ITERM_PROFILE
|
2016-12-03 20:25:46 +08:00
|
|
|
or set -q VTE_VERSION # which version is already checked above
|
2017-03-01 01:51:48 +08:00
|
|
|
or begin
|
|
|
|
set -q XTERM_VERSION
|
|
|
|
and test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280
|
|
|
|
end
|
2016-10-28 05:04:12 +08:00
|
|
|
end
|
|
|
|
# .. unless an unsupporting terminal has been started in tmux inside a supporting one
|
|
|
|
and begin string match -q "screen*" -- $TERM
|
|
|
|
or string match -q "tmux*" -- $TERM
|
|
|
|
end
|
2016-10-27 16:16:57 +08:00
|
|
|
end
|
2016-10-28 05:04:12 +08:00
|
|
|
and not string match -q "konsole*" -- $TERM
|
2016-11-19 02:17:23 +08:00
|
|
|
or begin
|
|
|
|
# TERM = xterm is special because plenty of things claim to be it, but aren't fully compatible
|
|
|
|
# This includes old vte-terms (without $VTE_VERSION), old xterms (without $XTERM_VERSION or < 280)
|
|
|
|
# and maybe other stuff.
|
|
|
|
# This needs to be kept _at least_ as long as Ubuntu 14.04 is still a thing
|
|
|
|
# because that ships a gnome-terminal without support and without $VTE_VERSION.
|
|
|
|
string match -q 'xterm*' -- $TERM
|
|
|
|
and not begin set -q KONSOLE_PROFILE_NAME
|
|
|
|
or set -q ITERM_PROFILE
|
2016-12-03 20:25:46 +08:00
|
|
|
or set -q VTE_VERSION # which version is already checked above
|
2016-11-19 02:17:23 +08:00
|
|
|
# If $XTERM_VERSION is undefined, this will return 1 and print an error. Silence it.
|
|
|
|
or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280 ^/dev/null
|
|
|
|
end
|
|
|
|
end
|
2016-11-28 13:27:22 +08:00
|
|
|
|
2016-10-28 05:04:12 +08:00
|
|
|
return
|
2016-10-27 16:16:57 +08:00
|
|
|
end
|
|
|
|
|
2016-05-30 22:36:25 +08:00
|
|
|
set -l terminal $argv[1]
|
|
|
|
set -q terminal[1]
|
|
|
|
or set terminal auto
|
|
|
|
set -l uses_echo
|
2014-01-20 14:19:41 +08:00
|
|
|
|
2016-05-30 22:36:25 +08:00
|
|
|
set -l function
|
|
|
|
switch "$terminal"
|
|
|
|
case auto
|
|
|
|
if set -q KONSOLE_PROFILE_NAME
|
|
|
|
set function __fish_cursor_konsole
|
|
|
|
set uses_echo 1
|
2016-12-02 13:56:59 +08:00
|
|
|
else if set -q ITERM_PROFILE
|
|
|
|
set function __fish_cursor_1337
|
|
|
|
set uses_echo 1
|
2016-10-28 05:04:12 +08:00
|
|
|
else
|
2016-05-30 22:36:25 +08:00
|
|
|
set function __fish_cursor_xterm
|
|
|
|
set uses_echo 1
|
|
|
|
end
|
|
|
|
case konsole
|
|
|
|
set function __fish_cursor_konsole
|
|
|
|
set uses_echo 1
|
|
|
|
case xterm
|
|
|
|
set function __fish_cursor_xterm
|
|
|
|
set uses_echo 1
|
|
|
|
end
|
2014-01-20 14:19:41 +08:00
|
|
|
|
2016-05-30 22:36:25 +08:00
|
|
|
set -l tmux_prefix
|
|
|
|
set -l tmux_postfix
|
|
|
|
if set -q TMUX
|
2016-11-28 13:27:22 +08:00
|
|
|
and set -q uses_echo[1]
|
2016-05-30 22:36:25 +08:00
|
|
|
set tmux_prefix echo -ne "'\ePtmux;\e'"
|
|
|
|
set tmux_postfix echo -ne "'\e\\\\'"
|
|
|
|
end
|
2014-01-21 01:28:54 +08:00
|
|
|
|
2016-05-30 22:36:25 +08:00
|
|
|
set -q fish_cursor_unknown
|
|
|
|
or set -g fish_cursor_unknown block blink
|
2014-01-20 20:07:32 +08:00
|
|
|
|
2016-05-30 22:36:25 +08:00
|
|
|
echo "
|
2016-09-05 07:20:12 +08:00
|
|
|
function fish_vi_cursor_handle --on-variable fish_bind_mode --on-event fish_postexec
|
2016-05-30 22:36:25 +08: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-05 07:20:12 +08: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 14:19:41 +08:00
|
|
|
end
|
2014-01-21 01:28:54 +08:00
|
|
|
|