Some sharing for other beginners like me when playing around with Wezterm config #6348
haphamdev
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been playing around with Wezterm for more than a week.
I built up my own status bar and key mappings, trying to replicate what I had with tmux before to ensure my workflow was still smooth after migrating from Alacritty to Wezterm. You can find the code in my dot-files.
Now, I just want to write down some of my experiences for other beginners.
For NeoVim users:
Lua coding in NeoVim is a really nice experience. However, I faced the auto-completion issue when configuring Wezterm.
I was using lua_ls for the Language Server.
And my lua config for Wezterm looks like this
There is no special thing there, just follow the instructions from Wezterm docs for Lua configuration, except the
.luarc.json
file, which is the point of this section.Inside the entrypoint
wezterm.lua
, I had to import other lua files.However,
lua_ls
will not recognize those modules, which means I could not jump around the code or no code completion. That was painful.After checking the config doc or lua_ls, I found a workaround by adding
.luarc.json
to thewezterm/
directory as you can see in the above directory tree.Content of
.luarc.json
:You can see that I added the
wezterm
directory to the library to solve the issue.Now I can smoothly configure my Wezterm with NeoVim 👍 💯
Debugging Wezterm Lua configuration
Please read this page if you want to debug your config. I missed that page when I started and struggled with it for 2-3 days before posting a question here
Some helper functions for Wezterm config
You can find some helper function here which were really useful for me
map
: Just like the map function in other languages, it requires in input table, iterates through the table and apply a function on each item to generate an output table. For example: Get a list of names from a list of people.inspect
: Not much here.wezterm.log_info()
(or other variants for errors and warnings) is really helpful with text messages. But for Lua table, we needwezterm.to_string()
rather than having a bunch of memory addresses on the log output.mergeTable
: Just to join two Lua arrays. I use it to merge allFormatItem
s to build the right status barformatSegment
: My status bar contains different segments (for git info, current directory, battery info, key layouts). I just want a function to help me format the text.wezterm.nerdfonts
is really useful if you need an icon for your status barCheck it out
Running a shell command in Wezterm config
In many cases that you want to run a shell command and get the output. For example, checking git status of the current working directory or checking which song is playing by Spotify CLI. It's quite complicated to do that in Lua. Luckily, Wezterm already covered that for us with
wezterm.run_child_process()
. Check it out.Btw, background_child_process is also cool.
Configuring your status bar or tab bar
You can configure your status bar by handling the event update-status (or update-right-status which is considered deprecated). For the tab bar, we use format-tab-title event. You can see an example there.
Notes: As you can see from the docs, those events might be triggered multiple times, some of which do not behave as expected. For example,
pane:get_current_working_dir()
returns unexpectednil
. Please ensure that you do the safety check in your code. Something like:That's pretty much it for my sharing. Hope you enjoys Wezterm and looking forward to new awesome plugins.
Beta Was this translation helpful? Give feedback.
All reactions