No Such Shell Function 'Zle Line Init' in Zsh

No Such Shell Function 'Zle Line Init' in Zsh

  • coding
  • 2024-04-25
  • 3 minutes to read

Introduction

I had an error pop up recently in zsh. The error message was no such shell function 'zle line init'. I did some research and discovered it was an error related to OhMyPosh. I have been exploring the concept of dotfiles recently (more on that in another post) and by consolidating my dotfiles, turns out I inadvertently caused this error. The ohmyposh FAQ goes some way to explain this error, but mine was a little convoluted so I thought I’d write it out.

dotfiles?

I am going to write a very short summary of this concept as it will help explain how I caused this issue. Dotfiles are files that are hidden in your home directory. They are used to configure your shell and other programs such as git. They are called dotfiles because they start with a .. For example, .gitconfig is a dotfile. I typically will want the same configuration on all my machines and I have in the past used a sync app to at the very least sync my git config however, it was a little convoluted and limited in its functionality long term.

I have been exploring the idea of managing dotfiles through a git repository. There are a lot of different ways this can be done, I will write a post on this in the future. But for the purpose of this post, know that I have pushed some of my dotfiles (including those related to zsh) to a git repository and have then worked through the consolidation of these files between my machines to the point where I thought I had finalised on configuration to rule them all.

no such shell function ‘zle line init’

I opened terminal today and spotted this error:

a terminal window showing the error no such shell function 'zle line init' under the command prompt

After a quick search, it was clear that this was an error related to OhMyPosh and as per the FAQ it would suggest that I have duplicate commands in my .zrsc file, but that wasn’t the case:

## .zshrc
# >>> oh my posh >>>
eval "$(oh-my-posh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/amro.omp.json' init zsh)"
# <<< oh my posh <<<

There are however, multiple dotfiles that are used by zsh and after I started digging into my home directory for traces of ohmyposh (another cool feature of having my dotfiles in git is I can use vscode search for searching files), I found a duplicate command in my .zprofile file:

## .zprofile
# >>> oh my posh >>>
eval "$(oh-my-posh init zsh)"
# <<< oh my posh <<<

By simply removing the duplicate command from the .zprofile file the error was resolved.

Be careful rationalising dotfiles

As much a lesson for myself I guess, it was pretty easy rationalising my config in a dotfile, but I also need to make sure they make sense across the dotfiles!

Read the instructions more carefully

It also suggests I have set up OhMyPosh inconsistently between machines! The OhMyPosh instructions say to put your OhMyPosh configuration in the .zshrc file, and logically I must have put it in the wrong place on one of my machines which is why I ended up with two commands once I rationalised them. It hasn’t really affected the functionality of OhMyPosh on any single machine, only once I rationalised the files, but it’s a good reminder to read the instructions more carefully.

#mtfbwy



Recent Posts

Connecting Azure Data Studio to Postgres

Connecting Azure Data Studio to Postgres

  • 2024-05-09
  • 2 minutes to read

How to connect Azure Data Studio to a Postgres database.

Read More
Creating a Postgres docker container and connecting dbt

Creating a Postgres docker container and connecting dbt

  • 2024-05-09
  • 5 minutes to read

How to get started with dbt and the Postgres adapter.

Read More
Setting up the dbt SQL Server Adapter

Setting up the dbt SQL Server Adapter

  • 2024-05-09
  • 6 minutes to read

How to get started with dbt and the SQL Server adapter including fixing issues on macOS.

Read More