zed
zed copied to clipboard
Shell Not Changing in Zed Editor Task
Summary
Description:
I am encountering an issue in the Zed editor where the shell does not change to the specified shell in the tasks.json file. Despite specifying the shell command, the editor continues to use the system shell when running tasks.
Steps to Reproduce:
- Open Zed editor.
- In the
tasks.jsonfile, I specified the shell command as follows:[ { "label": "Compile & Run", "command": "/usr/bin/bash ~/.config/zed/compilebuildrun.sh", "description": "compiles & runs the current code file", "use_new_terminal": false, "allow_concurrent_runs": false, "reveal": "always", "show_summary": false, "show_output": false } ] - Save the
tasks.jsonfile. - Run the task.
Expected Behavior:
The task should execute using the specified shell (/usr/bin/bash) and run the script located at ~/.config/zed/compilebuildrun.sh.
Actual Behavior:
The task runs using the system shell (/usr/bin/zsh), as shown below:
⏵ Command: /usr/bin/zsh -i -c 'sh ~/.config/zed/compilebuildrun.sh'
Contents of compilebuildrun.sh:
#!/bin/bash
# Access the full path using ZED_FILE
full_path="$ZED_FILE"
# Extract filename with extension
filename_ext=$(basename "$full_path")
# Extract filename and extension
filename="${filename_ext%.*}"
extension="${filename_ext##*.}"
echo "[running $filename_ext]"
echo ""
if [[ "$extension" == "cpp" ]]; then
g++ "$full_path" -o "$filename" && ./"$filename";
elif [[ "$extension" == "c" ]]; then
gcc "$full_path" -o "$filename" && ./"$filename";
elif [[ "$extension" == "py" ]]; then
python3 "$full_path";
else
echo "no"
fi
Environment:
- Shell specified:
/usr/bin/bash
Additional Information:
- I have verified that the path to the script is correct and that the script is executable.
Zed Version and System Specs
Zed: v0.186.7 (Zed) OS: Linux Wayland Arch
There's a high chance that https://github.com/zed-industries/zed/pull/31720 had fixed this. Will close optimistically until further reports.
No it's not fixed yet @SomeoneToIgnore
You're not specifying a shell, you're specifying a command which includes bash:
[
{
"label": "Compile & Run",
"command": "/usr/bin/bash ~/.config/zed/compilebuildrun.sh",
"description": "compiles & runs the current code file",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"show_summary": false,
"show_output": false
}
]
By default, all tasks are invoked under your current shell (e.g. zsh). As noted in the tasks documentation if you wish invoke this in a different shell, remove the /usr/bin/bash from your command and add a shell specification to your task:
// Which shell to use when running a task inside the terminal.
// May take 3 values:
// 1. (default) Use the system's default terminal configuration in /etc/passwd
// "shell": "system"
// 2. A program:
// "shell": {
// "program": "sh"
// }
// 3. A program with arguments:
// "shell": {
// "with_arguments": {
// "program": "/bin/bash",
// "args": ["--login"]
// }
// }
"shell": "system",
I.e. try adding "shell": { "program": "/bin/bash" },.
Also of note, unless you're trying to avoid loading your zsh environment variables, the outer zsh should be largely harmless. The inclusion of bash shebang in your shell script is sufficient to make bash the interpreter, even if it is invoked by zsh.
@notpeter thanks a lot for clarifying and helping me to fix the issue... I appreciate it 👍