On Wed, 30 May 2018, Jason Franklin wrote:
> I would like for bash to be able to discern whether it is being run with :shell or with :term. I would assume this would need to be done with an environment variable. Does this feature to do something like this already exist?
The method I know to use in scripts
is the expression (mostly in 'if':
... [ -t 0 -a -t 1 ] ...
Meanig '-t N' (asks for STDIN 0 and STDOUT 1):
'is filedescriptor N connected to a terminal ?'
So e.g. you can write in all (non C shell)shells:
-------------------------------------------------
if [ -t 0 -a -t 1 ]; then
do_terminal
else
non_terminal
fi
-------------------------------------------------
alternatively:
-------------------------------------------------
[ -t 0 -a -t 1 ] && do_terminal || non_terminal
-------------------------------------------------
AND on modern shells you better use the shell-internal
test with [[ and ]], instead of [ and ], which was
using the real program 'test'.
BUT 'or' and 'and' are different then:
-------------------------------------------------
positively negatively
[ -t 0 -a -t 1 ] != [ ! -t 0 -o ! -t 1 ]
[[ -t 0 && -t 1 ]] != [[ ! -t 0 || ! -t 1 ]]
-------------------------------------------------
May be this is all you need?
I end lots of my scripts with code for
"if called in terminal, list on pager",
because I always forget "... | less" (:-)
or "if input not a terminal, do not ask".
--
Christoph von Stuckrad * * | also XMPP = |Mail <stucki@mi.fu-berlin.de> \
Freie Universitaet Berlin |/_*| 'jabber' via|Tel(Mo.,Mi.):+49 30 838-75 459|
IT Mathematik & Informatik|\ *|stucki@jabber| (Di,Do,Fr):+49 30 77 39 6600|
Takustr. 9 / 14195 Berlin * * |.fu-berlin.de|Fax(home): +49 30 77 39 6601/
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wednesday, May 30, 2018
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment