Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select file at startup for staging/etc #3788

Open
teleshoes opened this issue Aug 1, 2024 · 6 comments
Open

select file at startup for staging/etc #3788

teleshoes opened this issue Aug 1, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@teleshoes
Copy link

teleshoes commented Aug 1, 2024

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 teleshoes added the enhancement New feature or request label Aug 1, 2024
@mark2185
Copy link
Collaborator

mark2185 commented Aug 1, 2024

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
Copy link
Author

teleshoes commented Aug 1, 2024

  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
Copy link
Collaborator

mark2185 commented Aug 1, 2024

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
Copy link
Author

teleshoes commented Aug 1, 2024

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
Copy link
Author

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
Copy link
Collaborator

mark2185 commented Aug 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants