> As a general rule, if I want to use something outside of the interactive
> shell, I use an executable. This applies equally as well to things like
> running :!theCommand from within vim to running theCommand remotely via ssh
> to creating desktop shortcuts that search the $PATH.
According to the Bash manual (man 1 bash), one can use shopt to set
expand_aliases to true. This should allow access to aliases in
non-interactive settings. (I have not tested it, though.)
A workaround I came across a long time ago was to keep aliases in a
separate file, which gets sourced by ~/.bashrc, but which can also be
sourced by a wrapper script like so:
```
#! /bin/bash
. ~/bashrc.d/aliases.sh
ALIAS=$1
ARGS=${@:2}
bash -c "${BASH_ALIASES[$ALIAS]} $ARGS"
```
So, if ~/bashrc.d/aliases.sh contains the line `alias foo="vim ~/bar"`, and
if that wrapper script is named `baz` somewhere in my $PATH, this should
work in non-interactive settings:
baz foo
It will source the aliases file, find the alias foo, and thus execute
`vim ~/bar`.
But if using shopt to set expand_aliases works, it is probably a superior
approach to my workaround.
~ Tim
--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190710230345.GA22826%40sleipnir.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment