jesseduffield / jesseduffield/lazygit

Custom command does not work like expected

Open
#1,551 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

**Describe the bug**
`customCommands.command` field can't properly escape characters.

I guess that the escape character will be passed to the executable. In my case the CMD.

**To Reproduce**

Steps to reproduce the behavior:
1. Add to config:

``` yaml
customCommands:
- key: ''
command: "Powershell -NoProfile -WindowStyle Hidden -command \"& { gps > C:\\S\\temp\\test.txt }\""
context: 'localBranches'
subprocess: true
loadingText: 'creating branch'
```
2. navigate to local branches
3. press ctrl+p

**Expected behavior**
I would expect to have a new file at C:\S\temp\test.txt
It works like a charm with:
1. windows -> Open *Run* with `Win+r`
2. enter *the same command without escape characters*
```
C:\WINDOWS\system32\cmd.exe /c Powershell -NoProfile -WindowStyle Hidden -command "& { gps > C:\S\temp\test.txt }"
```

**Screenshots**
- the same with `echo`
![image](https://user-images.githubusercontent.com/29312172/138917897-a3b915b8-d1be-467e-b1d1-d618f756760f.png)
I'm not sure why the character `"` has a problem and the `\` not.

## Test with CMD
If I enter the suspected command with all escape characters from `config.yml`
```
C:\WINDOWS\system32\cmd.exe /c Powershell -NoProfile -WindowStyle Hidden -command \"& { gps > C:\S\temp\test.txt }\"
```
the response is the same like in the screenshot:
```
& { gps > C:\S\temp\test.txt }
```

**Desktop (please complete the following information):**
- OS: Windows
- Lazygit Version 029
- Powershell 7
- Windows terminal

Did I miss something?

Thanks up front.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.