0

I am using zsh as my shell and I am trying to achieve this:

In my .zshrc file I want to have a function that modifies my .zshrc, saves it and reloads it.

So far I have to functions (in my .zshrc file):

function zshrd(){
    cp $HOME/config/.zshrc $HOME/
    source $HOME/.zshrc
}

function zshed(){
    message=${1:-Automated message}
    nano $HOME/.zshrc
    git add $HOME/config/
    git commit -m $message
    zshrd
} 

Whenever I call zshrd it does work. But whenever I call zshed, it doesn't. It opens up the file in nano, but does not save any changes made to the file and does not commit anything. Maybe it has something to do with stdin/stdout?

Do you have any idea why? I am open to other solutions if I am doing things the "wrong way".

Thanks!

1 Answer 1

0

Correct me if I don't get you right but you open $HOME/.zshrc with nano, add some changes and save. Then you try to add and commit $HOME/config/ but there are no changes made in this directory so no commit is made. You then call zshrd and override the previous changed $HOME/.zshrc with $HOME/config/.zshrc which never changed.

I think you should call nano $HOME/config/.zshrc in your script.

Then your function would change the $HOME/config/.zshrc, commit its changes and then override your $HOME/.zshrc with your new $HOME/config/.zshrc and reloads it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .