jesseduffield / lazygit

simple terminal UI for git commands
MIT License
50.55k stars 1.78k forks source link

select file at startup for staging/etc #3788

Open teleshoes opened 1 month ago

teleshoes commented 1 month ago

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

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.

mark2185 commented 1 month ago

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.

teleshoes commented 1 month ago

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.

mark2185 commented 1 month ago

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.

teleshoes commented 1 month ago

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 commented 1 month ago

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

mark2185 commented 1 month ago

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.