0

I'm facing a problem while trying to make an emacs daemon management function in Bash.

Here is the function snippet:

function ne
{
if [ $# -ge 2 -a "$1" '==' "-s" ]
then
    server="$2";
    param=${@:3};
else
    server="default";
    param=${@:1};
fi
nbsrv=`ls ~/.emacs.d/server | grep "$server" | wc --chars`
if [ "$nbsrv" '==' "0" ]
then
    echo "Starting server '$server'";
    emacs --daemon=$server
fi
emacsclient --server-file=$server -nw $param;
}

It almost works, the problem is with:

param=${@:x}

For exemple, if I run:

ne -s srv1 file1 file2

It does not open me 2 new files but one named "file1 file2"

Have you got an idea of how I can make this works fine?

Thank's !

JM445

PS: Sorry if my english is not perfect, I'm french

1 Answer 1

2

Don't bother with bash arrays for this. Just shift off the positional parameters you don't want, and pass the remainder to emacsclient with "$@"

Your script with this modification looks like:

if [ $# -ge 2 -a "$1" '==' "-s" ]
then
    server="$2";
    shift 2;
else
    server="default";
fi
nbsrv=`ls ~/.emacs.d/server | grep "$server" | wc --chars`
if [ "$nbsrv" '==' "0" ]
then
    echo "Starting server '$server'";
    emacs --daemon=$server
fi
emacsclient --server-file=$server -nw "$@";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.