lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

select file at startup for staging/etc

Open teleshoes opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. my primary use of lazygit is for line-by-line staging of single files. selecting a file to start staging on the command line would be useful, instead of scrolling through the Files panel.

also, in addition to invoking lazygit in a terminal, i currently sometimes use a shortcut in vim to switch to lazygit, stage some lines, and commit them. it would be nice if the file i am currently editing was selected in lazygit.

Describe the solution you'd like

  1. run: lazygit --select-file src/file.cpp
  2. see lazygit start as normal
  3. among files in the Files tab of panel[2], if that file's path (relative to the root of the repo) matches src/file.cpp, select that modified or unstaged file, as if selecting that row in Files with the kb or mouse (expanding dirs in the filetree as necessary)

Describe alternatives you've considered

  • scripting keys at startup to do something like xdotool key '/', xdotool type $FILENAME, xdotool key Return (this is awful, non-portable, and possibly subject to race conditions)
  • creating a temporary custom cmd with yaml before startup that selects a file with a specific name (still have to press a button at startup)
  • creating a permanent custom cmd that selects a file based on an environment variable $VIM_FILE and setting that (still have to press a button at startup)

Additional context none

EDIT: edited to make it clear that this feature request is not related to vim, though it would play nicely with ANY programmer-friendly text editor.

teleshoes avatar Aug 01 '24 15:08 teleshoes

As much as I love lazygit, for this specific thing maybe you would be better off with vim-fugitive or maybe vim-gitgutter for staging the current hunk. Just my two cents, consider it a possible alternative.

mark2185 avatar Aug 01 '24 18:08 mark2185

  1. this is a generic feature, not vim-specific at all. i personally would use it from the cmdline about as much as i use it from vim. lg path/to/file is a lot easier than navigating an interactive Files panel.
  2. vim-fugitive is nice, but it's staging tool is a pure wrapper around git stage -p, which does not support line-by-line staging.
  3. vim-gitgutter is less universally endorsed so i haven't checked it out before, but it seems to claim that it supports line-by-line staging. i will look into it for sure, thanks!

EDIT: nevermind, gitgutter is the same deal. it allows you to stage a hunk, and then delete the bits you dont want to stage, just like git stage -p. honestly, as far as i know, only git gui and lazygit have the convenience of selecting a single line and committing it.

teleshoes avatar Aug 01 '24 18:08 teleshoes

vim-fugitive is nice, but it's staging tool is a pure wrapper around git stage -p, which does not support line-by-line staging.

vim-fugitive does support partial staging, you just have to use visual line mode when staging.

lg path/to/file is a lot easier than navigating an interactive Files panel.

You can just use / to search.

I'll stop with the digression now.

mark2185 avatar Aug 01 '24 18:08 mark2185

You can just use / to search.

yes, i did mention automating doing /file in my initial report

vim-fugitive does support partial staging, you just have to use visual line mode when staging.

!!! did not know this, will try it out right now and see if it replaces lazygit for me. thanks!

teleshoes avatar Aug 01 '24 18:08 teleshoes

hmm, line-by-line staging with :Gdiff+:dp works, but it seems that a unified diff like in git gui or lazygit is not feasible, since it is just wrapping vimdiff and writing the index from the resulting buffer.

a quick internet search did not turn up anyone getting functionality in vim similar to the staging ui from lazygit or git-gui, but maybe someone does have this? (all i want, really, is a terminal based, keyboard driven app that shows a nice, hunk-ed, unified diff of a single file against the index, AND allows easily staging a single +LINE or -LINE from within that diff.)

but like you say, this is a tangent, and lazygit could use this feature with or without vim

teleshoes avatar Aug 01 '24 19:08 teleshoes

This looks pretty close to lazygit to me: image

image

In any case, this is a discussion better suited for the lazygit discord channel since it is pretty off topic.

mark2185 avatar Aug 01 '24 19:08 mark2185