vi_cursor: Refactor detection logic

Makes it a bit easier to read.

Now we can begin reworking it (again) to make iTerm work.
This commit is contained in:
Fabian Homborg 2016-12-03 13:25:46 +01:00
parent 59fa04bd91
commit 029d88e962

View file

@ -12,7 +12,18 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
# e.g. tmux started in suckless' st (no support) started in konsole. # 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, # 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). # we will just fail there (though it seems that tmux or st swallow it anyway).
#
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
# We use the `tput` here just to see if terminfo thinks we can change the cursor. # 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, # 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). # and because we may want to change the cursor even though terminfo says we can't (tmux).
@ -23,7 +34,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
# ...in a supporting term... # ...in a supporting term...
and begin set -q KONSOLE_PROFILE_NAME and begin set -q KONSOLE_PROFILE_NAME
or set -q ITERM_PROFILE or set -q ITERM_PROFILE
or test "0$VTE_VERSION" -ge 4000 or set -q VTE_VERSION # which version is already checked above
or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280 or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280
end end
# .. unless an unsupporting terminal has been started in tmux inside a supporting one # .. unless an unsupporting terminal has been started in tmux inside a supporting one
@ -32,14 +43,6 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
end end
end end
and not string match -q "konsole*" -- $TERM and not string match -q "konsole*" -- $TERM
# Blacklist
or begin
# 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
set -q VTE_VERSION
and test "$VTE_VERSION" -lt 4000
end
or set -q INSIDE_EMACS
or begin or begin
# TERM = xterm is special because plenty of things claim to be it, but aren't fully compatible # 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) # This includes old vte-terms (without $VTE_VERSION), old xterms (without $XTERM_VERSION or < 280)
@ -49,7 +52,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes'
string match -q 'xterm*' -- $TERM string match -q 'xterm*' -- $TERM
and not begin set -q KONSOLE_PROFILE_NAME and not begin set -q KONSOLE_PROFILE_NAME
or set -q ITERM_PROFILE or set -q ITERM_PROFILE
or test "0$VTE_VERSION" -ge 4000 or set -q VTE_VERSION # which version is already checked above
# If $XTERM_VERSION is undefined, this will return 1 and print an error. Silence it. # 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 or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280 ^/dev/null
end end