lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Custom Command Keybindings - PlaceHolderValues: SelectedFile exists -> add SelectedDir

Open alexn-s opened this issue 3 years ago • 7 comments

Is your feature request related to a problem? Please describe.

I am using a pnpm monorepo and have some automatic pipelines with conventional commit (eg. using the name from the project in the git repo in the commit). In order for that to work I must automatically navigate/ cd into the project and run the pipeline from there. Currently it only works with SelectedFile.name to get the path and proceed with it.

Describe the solution you'd like

Add SelectedDir to the PlaceHolderValues so it is not required to select a file

Examples

example CURRENT command config.yml

customCommands
  - key: "y"
    command: "powershell.exe -noProfile C:/Users/.../AppData/Roaming/lazygit/scripts/git-cz.ps1 {{.SelectedFile.Name}}"
    context: "files"
    loadingText: "..."
    subprocess: true

example PREFERRED command config.yml

customCommands
  - key: "y"
    command: "powershell.exe -noProfile C:/Users/.../AppData/Roaming/lazygit/scripts/git-cz.ps1 {{.SelectedDir.Name}}"
    context: "files"
    loadingText: "..."
    subprocess: true

alexn-s avatar Jun 17 '22 00:06 alexn-s

would a SelectedPath option suffice? Or do you want something specifically for the selected directory of the current file?

jesseduffield avatar Jun 18 '22 02:06 jesseduffield

selected path would be awesome.

currently i convert the SelectedFile.Name path to a directory path again anyway, because cd obviously only works for a dir path

love your work on lazygit. really appreciate it 💖

alexn-s avatar Jun 18 '22 14:06 alexn-s

would a SelectedPath option suffice? Or do you want something specifically for the selected directory of the current file?

How would SelectedPath differ from the SelectedFile, would it be absolute instead of relative, or?

The SelectedDir might come in handy for accepting all hunks from a certain source for the selected directory, as mentioned here.

mark2185 avatar Jul 24 '22 14:07 mark2185

SelectedFile contains an actual File struct so you can access public fields on it, but if you've selected a directory then SelectedFile will be nil. I'd make the SelectedPath use the same form of path as whatever SelectedFile currently uses (I assume relative). If we need an absolute form we can introduce SelectedAbsPath.

Does introducing SelectedDir actually give us anything beyond the path itself?

jesseduffield avatar Jul 24 '22 22:07 jesseduffield

Yeah, no, SelectedPath would offer more than enough, I didn't have a clear enough picture of what would SelectedPath encompass, but now it's cleared up!

mark2185 avatar Jul 25 '22 07:07 mark2185

Uhhh... we already have SelectedPath, it's just not documented? Lookie here

	SelectedSubCommit      *models.Commit
	SelectedFile           *models.File
--->    SelectedPath           string
	SelectedLocalBranch    *models.Branch
	SelectedRemoteBranch   *models.RemoteBranch

I'll add it to the README.

mark2185 avatar Jul 30 '22 06:07 mark2185

Oh my god that's embarrassing!

jesseduffield avatar Jul 30 '22 09:07 jesseduffield