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

Running Sql Server on Macos Using SQLCMD CLI

Running Sql Server on Macos Using SQLCMD CLI

  • 2024-05-08
  • 6 minutes to read

It's really easy to run SQL Server on MacOS using the new SQLCMD CLI tool. Here's how to do it.

Read More
How to Search for a Lost File in the Git Log

How to Search for a Lost File in the Git Log

  • 2024-04-27
  • 4 minutes to read

I have lost a file in my Git repository. How can I find it by searching the git log?

Read More
Getting Started With Python in Vscode

Getting Started With Python in Vscode

  • 2024-04-05
  • 2 minutes to read

This post will help you get started with Python in Vscode and identify some of the useful extensions to install.

Read More