Home > Enterprise >  after switching to zsh from bash receiving: parse error near `PROMPT_COMMAND=vim'
after switching to zsh from bash receiving: parse error near `PROMPT_COMMAND=vim'

Time:12-23

code around `PROMPT_COMMAND=vim' in the .zprofile I am trying to source is:

function vim
{
    printf "\e]1;"`basename "$1"`"\a"
    /usr/bin/vim "$1" } PROMPT_COMMAND=vim
function nvim
{
    printf "\e]1;"`basename "$1"`"\a"
    /usr/local/bin/nvim "$1"
}
PROMPT_COMMAND=nvim

This is the only instance of PROMPT_COMMAND=vim in the file.

This worked fine when I was using .bash_profile. It broke when I set up zsh and migrated this to .zprofile. Same result happens if I use .zshrc instead of .zprofile.

The goal of this code is to use nvim whenever I type in vim to ease the migration to nvim and speed up typing.

I am very new to programming so this may be a low level question, but I could not find an answer online.

CodePudding user response:

A bit long for a comment, plus format matters ...

I got the following to work in bash:

function vim
{
    printf "\e]1;"`basename "$1"`"\a"
    /usr/bin/vim "$1"; } ; PROMPT_COMMAND=vim      # add a ";" before function's ending "}"
                                                   # and separate trailing "}" from the next command

# or 

function vim
{
    printf "\e]1;"`basename "$1"`"\a"
    /usr/bin/vim "$1"
}; PROMPT_COMMAND=vim                              # place function's ending "}" on a new line
                                                   # but also separate the "}" and the next command

# or

function vim
{
    printf "\e]1;"`basename "$1"`"\a"
    /usr/bin/vim "$1"
}                                                  # again, place trailing "}" on separate line
PROMPT_COMMAND=vim                                 # place next command on it's own line

As pointed out in Ted's comment ... PROMPT_COMMAND=vim may not do the same thing in bash as it did in zsh ...

  • Related