문제

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