Open frostbyte-ninja opened 2 months ago
If you just want to know which shells are available on the system, you can check /etc/shells
for Linux/Mac.
There doesn't seem to be a good way to do this on Windows.
Ran into similar issue where I wanted to use fish if it exists.
I have used homebrew so it install fish at /opt/homebrew/bin/fish
which might not be in the path.
So I have added the following to my western config.
local function file_exists(path)
local f = io.open(path, "r")
if f~=nil then io.close(f) return true else return false end
end
if file_exists("/opt/homebrew/bin/fish") then
config.default_prog = { '/opt/homebrew/bin/fish', '-l' }
else
config.default_prog = { '/bin/bash', '-l' }
end
If I want to add it to launch menu I would also need an if else here.
{ label = "fish", args = {"/opt/homebrew/bin/fish", "-l"}
It almost seems like there should also be an easy way to add /opt/homebrew/bin
to the path and have a function to see if there executable is available so one can set the args as just {"fish", "-l"}
Another option for this is use wezterm.glob
to check if a specific path exists, here I'm in the debug overlay on a system that doesn't have homebrew or fish, but does have zsh at the paths I'm checking:
Debug Overlay
wezterm version: 20240812-215703-30345b36 x86_64-unknown-linux-gnu
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit
> wezterm.glob('/opt/homebrew/bin/fish')
[]
> wezterm.glob('/bin/zsh')
[
"/bin/zsh",
]
>
Glob expressions can include multiple candidates, so you can check for multiple paths at the same time. Here I'm checking for zsh, bash, fish and csh:
> wezterm.glob('/bin/{zsh,bash,fish,csh}')
[
"/bin/bash",
"/bin/zsh",
]
Hi,
I am encountering the same issue as described here. The suggested solution there does not appear to be optimal. To determine the availability of executables in the path, I implemented the following function:
While this performs as expected on Linux, on Windows each call results in the spawning of a shell window. This not only disrupts the visual flow but also significantly increases startup time when multiple checks are performed.
My goal is to determine which shells are available on the system to dynamically create launch_menu entries.
I would greatly appreciate a more efficient approach to address this issue.
Thank you.