Feature request: manually set the syntax when reading from stdin
Closed this issue · 2 comments
kbtz commented
It would be nice to have a option to set a file extension on the temporary file used to read from stdin, so we can handle syntax on these contexts too.
Here's an use case where I'd try to just print a function definition from type
with syntax enabled:
alias ?=wat
function wat() {
shopt -s extdebug
declare -F $1
shopt -u extdebug
typedef=$(type $1)
# Prints the debug output without highlighting
echo "$typedef" | head -n1
typedef=$(echo "$typedef" | tail -n+2)
if [[ ! -z $typedef ]]; then
if tty -s; then
# Prints the function definition with syntax highlighting
# '-s sh' produces /tmp/tmp.aP6kTGvrLT.sh so nvim reads it as a shell script
echo "$typedef" | nvimpager -c -s sh
else
echo "$typedef"
fi
fi
}
Does that make sense?
lucc commented
Nvimpager supports all options that nvim also supports so you could do something like echo foo | nvimpager -c -- -c 'setf sh'
. Does that work for you?
kbtz commented
Very neat! Thank you!