0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00
vim/runtime/syntax/testdir/input/sh_generic.ksh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

147 lines
3.5 KiB
Bash
Raw Normal View History

runtime(sh): Fix various syntax highlighting problems in ksh93 scripts - Fixed syntax highlighting for ksh93 namespace variables starting with '${.' - Added support for the alarm, eloop, fds, mkservice, pids, poll and sha2sum builtins (which are indeed ksh93 builtins, albeit whether or not they are available depends on the ksh release and the compiled SHOPT options). - Added support for the many Unix commands provided by ksh93's libcmd as builtin commands (since these are general commands, scripts for other shells like bash will also highlight these). - The dumps for the sh_0{2,5,6,8,9}.sh were recreated due to this change affecting commands those scripts call (e.g. 'wc'). - Enabled ${parameter/pattern/string} and friends for ksh syntax. - Enabled case modification for ksh. See also: https://github.com/ksh93/ksh/commit/c1762e03 - Enabled ;;& support for ksh. See also: https://github.com/ksh93/ksh/commit/fc89d20a - Added many special ksh variables using 93u+m's data/variables.c as a reference. If vim can't figure out which ksh release is in play using e.g. the hashbang path, in such a case a generic default that enables everything and the kitchen sink will be used. Otherwise, features will be disabled if it's absolutely known a certain feature will not be present. Examples: - ERRNO is ksh88 specific, so that is locked to ksh88. - Only 93u+m (assumed for generic) has SRANDOM, and only 93u+m and 93v- have case modification support. - 93u+ and 93v- have VPATH and CSWIDTH variables (the latter is vestigal, but still present in the hardcoded variable table). - 93v- and ksh2020 have (buggy and near unusable) implementations of compgen and complete. - Only mksh provides function substitutions, i.e. ${|command;}. This took the better part of my day to implement. It seems to work well enough though. (Also had to regenerate the dumps again while testing it, as now there are dup scripts with mere hashbang differences, used solely for testing syntax highlighting differences.) closes: #17348 Signed-off-by: Johnothan King <johnothanking@protonmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-05-21 21:21:14 +02:00
#!/bin/ksh
# Rendering namespace variables
echo ${.foo.bar[adsf]} ${foo.bar[1][2]} ${foo.bar[1][az]} ${.foo.bar[1][2]}
echo ${.foo[var]} ${.foo.bar[1]} ${.foo.bar[*]} ${foo.bar##baz} ${.foo.bar##baz}
echo ${.foo.bar[3]##baz} ${.foo.bar[z]##baz} ${sh.version/V/b} ${.sh.version/V/b}
echo ${foo/%bar/foo} ${foo/#bar/foo} ${foo.bar/%bar/foo} ${foo.bar[d]/#bar/foo}
echo ${.foo/%barfoo} ${.foo.bar/#bar/foo} ${.bar.foo/%bar/foo} ${.bar/#bar/foo}
echo ${foo/%barfoo} ${foo/bar/foo} ${barfoo//bar/foo} ${bar/#bar/foo}
echo ${.sh.version^^} ${.sh.version,,} ${KSH_VERSION^} ${KSH_VERSION,}
# 'alarm' builtin (present in ksh93u+, ksh93v- and the 93u+m dev branch).
alarm --man
# The fds and pids builtins. These ksh93 builtins have existed since 2005-05-22
# and 2008-06-02, respectively. However, these were not readily enabled; in
# 93u+m these can be enabled with the builtin command if libcmd.so is present,
# either via 'builtin -f' or (in more recent commits) with a regular invocation
# of the 'builtin' built-in.
# cf. https://github.com/ksh93/ksh/commit/f15e2c41
builtin fds pids
fds; pids
# Unix commands which are provided by ksh as builtins via libcmd.so
basename
cat
chgrp
chmod
chown
cksum
cmp
comm
cp
cut
date
dirname
egrep # Obsolescent
expr
fgrep # Obsolescent
fmt
fold
getconf
grep
head
iconv # 93v-
id
join
ln
logname
ls # 93v-
md5sum
mkdir
mkfifo
mktemp
mv
od # 93v-
paste
pathchk
readlink # 93v-
realpath # 93v-
rev
rm
rmdir
sha1sum # 93v-
sha256sum # 93v-
sha2sum # 93v-
sha384sum # 93v-
sha512sum # 93v-
stty
sum
sync
tail
tee
tr # 93v-
tty
uname
uniq
vmstate # Obsolescent; only available in 93v- and older
wc
xargs # 93v-
xgrep # 93v-
# SHA command not provided as a builtin but included here for completeness
sha224sum
# poll builtin (93v-)
poll --man
# mkservice and eloop (rarely provided; requires SHOPT_MKSERVICE)
mkservice --man; eloop --help
# some mksh builtins
bind; rename
# ;& and ;;& in case statements
case x in
bar) false ${baz:1} ;&
foo) true ${foo:0:0} ;;&
*) print ${bar} ;;
esac
# Below is subshare syntax supported by both ksh93 and mksh.
print ${ echo one }
print ${ echo two
}
print ${
echo three }
print ${ echo 'four'; }
print ${ echo 'five' ;}
print ${ echo 'six'
}
print ${ echo 'seven' }
echo ${ print 'eight' }
typeset nine=${ pwd; }
# Value substitutions of the form ${|command} are only
# supported by mksh, not ksh93.
if ! command eval '((.sh.version >= 20070703))' 2>/dev/null; then
valsubfunc() {
REPLY=$1
}
echo ${|valsubfunc ten}
print "${|valsubfunc eleven;}"
printf '%s' "${|valsubfunc twelve }"
unlucky=${|valsubfunc thirteen
}
typeset notafloat=${|valsubfunc notanumber }
print $unlucky $notanumber
${|echo foo}
${|echo bar
}
fi
# ======
# Shared-state command substitutions using the syntax ${<file;}
# are only supported by ksh93, not mksh.
echo ${
printf %s str
} > /tmp/strfile
echo ${</tmp/strfile;}
exit 0
# ksh88 and ksh93 non-dot special variables
print ${ RANDOM= SRANDOM= SHLVL= JOBMAX= KSH_VERSION= FIGNORE= LC_TIME= LC_NUMERIC= LC_MESSAGES= LC_CTYPE= LC_COLLATE= LC_ALL= LANG= FPATH= PS4= OPTIND= OPTARG= true ;}
print $(LINENO= SECONDS= TMOUT= PPID= LINES= COLUMNS= VISUAL= OLDPWD= PS3= MAILPATH= CDPATH= FCEDIT= HISTCMD= HISTEDIT= HISTSIZE= HISTFILE= ENV= MAILCHECK= EDITOR= SHELL= false)
print $(REPLY= MAIL= HOME= PWD= IFS= PS2= PS1= PATH= SH_OPTIONS= ERRNO= COMP_CWORD= COMP_LINE= COMP_POINT= COMP_WORDS= COMP_KEY= COMPREPLY= COMP_WORDBREAKS= COMP_TYPE= compgen)
print $(BASHPID= EPOCHREALTIME= EXECSHELL= KSHEGID= KSHGID= KSHUID= KSH_MATCH= PATHSEP= PGRP= PIPESTATUS= TMPDIR= USER_ID= VPATH= CSWIDTH= complete)