質問

I'm trying to write a command in my bash_profile to replace the default emacs command that will emacs a file if it exists, and if it doesn't exist, will copy a template to the new file and then emacs that.

What I attempted was:

function emacs()
{
if [ ! -f ${1} ]; then \
cp /FILEPATH/template.sh ${1}; fi;
builtin emacs ${1}
}

but the error I'm getting is "-bash: builtin: emacs: not a shell builtin"

How do I create a new function to replace the emacs command and then call the original emacs command within that function if emacs is not a builtin command?

役に立ちましたか?

解決

You want command emacs, not builtin emacs. See help command.

As an aside, doesn't emacs have some sort of internal support for new-file templates? You might want to take a look at this: http://www.emacswiki.org/emacs/TemplatesMode. (Disclaimer: I don't use emacs; this was just one of the first pages I found while searching for "emacs new file template.)

他のヒント

(edit: sorry, command emacs in the other answer is better, use that.)

builtin only works for actual shell builtins like test, read, ...

Use the explicit path to emacs instead:

function emacs()
{
if [ ! -f ${1} ]; then \
cp /FILEPATH/template.sh ${1}; fi;
/usr/bin/emacs ${1}
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top