Commit graph

103 commits

Author SHA1 Message Date
Wenxuan Zhang de5406cdda fix: use array length instead of string length in reset_head
`${#files}` checks the string length of the first element, not the
array length. Use `${#files[@]}` to correctly detect an empty array.
2026-03-10 09:21:22 +08:00
Wenxuan Zhang 3b9ebce8bc refactor: extract _forgit_print_dim helper and improve worktree ops
- Extract dim formatting into _forgit_print_dim() to replace hardcoded
  ANSI sequences in _forgit_branch_list()
- Add empty state check and alt-l lock toggle reload for worktree delete
- Fix worktree path completion to handle paths with spaces using -z flag
- Add worktree command completion for bash and zsh
2026-03-10 09:20:16 +08:00
Wenxuan Zhang fc081846c0 feat: add interactive git worktree operations
Add worktree browser (gwt) and worktree delete selector (gwd) with:
- Interactive worktree list with lock status, branch info, and age
- Preview showing working tree status and recent commits
- Ctrl-Y to copy worktree path, Alt-L to toggle lock/unlock
- Shell integration for zsh (with cd) and fish (with cd)
- Tab completions for zsh, bash, and fish
- Documentation in README with keybindings and options

Co-Authored-By: Sufien Tout <sufientout@gmail.com>
2026-03-10 09:20:16 +08:00
Wenxuan Zhang ea58599e66 refactor: extract branch helpers and ANSI strip utility
- Add _forgit_strip_ansi for removing ANSI escape codes
- Add _forgit_branch_list to list branches with current branch first
- Add _forgit_extract_branch_name to parse branch names from git output
- Update checkout_branch, switch_branch, branch_delete, cherry_pick_from_branch,
  and branch_preview to use the new helpers
- Fix _forgit_inside_work_tree to suppress stderr
2026-03-10 09:20:16 +08:00
sandr01d 151d61daff
fix: forgit add shows dir view for submodules (#484) 2025-12-21 20:45:56 +01:00
Jose M. Valera Reales 76506fc3da
Feature: add empty state messages for checkout commands (#478)
Show informative messages when there is nothing to checkout:
  - checkout_file: "Nothing to checkout." when no modified files
  - checkout_tag: "Nothing to checkout: there are no tags."
2025-12-10 20:23:14 +01:00
Iván Sotillo del Horno 3cd63a1bbe
Feature: add interactive git switch selector (#472) 2025-12-10 20:19:26 +01:00
sandr01d 779b59690f
Feature: allow configuring arguments of git ls-files in forgit clean (#481) 2025-12-08 20:24:11 +01:00
sandr01d b9ed7bc40e
Fix: preview for clean when file names contain backslashes (#465)
This is a breaking change: flag arguments provided to forgit clean are
now passed to git ls-files instead of git clean -n. This change is
necessary because git clean does not have a -z option that would prevent
it from escaping file names containing backslashes. However, git ls-files
is way more flexible than git clean, so all use cases covered by git
clean (and more) should still be possible.
2025-12-05 22:58:46 +01:00
carlfriedrich 2a4e2e53b7 Refactor: extract function to remove status from diff line (#464) 2025-09-08 06:47:52 +02:00
carlfriedrich ab6a63ee0f Chore: Do not execute any code when forgit is sourced (#464)
In order to run unit tests for individual functions we have to be able
to source the script without triggering the main execution flow.
2025-09-08 06:47:52 +02:00
carlfriedrich 9b3b185e24 Refactor: Move global code into a main function (#464)
This is a prequisite for being able to source the script in order to
implement unit tests for individual functions.
2025-09-08 06:47:52 +02:00
sandr01d f7796d5ce2
Fix: use github/gitignore for ignore files (#461)
The repo we originally used has gone away
2025-07-30 19:19:33 +02:00
sandroid 9a4ff16829 Fix: files in untracked directories are not shown in git add
Pass the value of git config status.showUntrackedFiles to the git status
command we run in _forgit_add, defaulting to 'all' when unset.
Additionally correctly handle directories in _forgit_add_preview for the
case when status.showUntracked is explicitly set to 'normal'.
2025-07-23 09:39:37 +02:00
sandr01d 8285d2e1b0
Fix: early out with non-file arguments in checkout file (#456) 2025-07-16 20:37:06 +02:00
sandr01d fd373ba6c2
Fix: remove explicit -u flag in git status command in _forgit_add (#455)
git status includes untracked files by default, so passing the flag
explicitly is not necessary. This allows overriding forgits behavior
by setting showUntrackedFiles = no in the .gitconfig.
2025-07-15 21:00:04 +02:00
carlfriedrich c0df9a56d0 Refactor: Remove unnecessary xargs in git show commands 2025-07-15 06:36:45 +02:00
carlfriedrich cfc954ebc0 Feat: Use forgit show in stash_show enter (#450)
Instead of using `git stash show` in the `enter` binding of the
`stash_show` command, use `forgit show`. This allows forgit to show the
stash in the same interactive way it shows other commits (e.g. on
`forgit log`), with the same context and formatting options.
2025-07-15 06:36:45 +02:00
sandr01d b71e54c4aa
Feate: allow passing arguments to git checkout file (#451) 2025-07-13 15:41:48 +02:00
sandr01d fe350db899
Feat: allow passing arguments to git add (#452) 2025-07-13 15:41:14 +02:00
sandr01d 7a5e68b11b
Fix: allow filtering by files in fixup, squash and reword (#448)
This reverts commit 3f694f6e99 and adds the same filtering option to reword.
2025-06-21 00:36:27 +02:00
sandroid d477ffaee4 Refactor: do not disable shellcheck 2230
It is optional with ubuntu 24.04 and disabled by default.
2025-06-03 09:37:29 +08:00
sandr01d 455e42ba64
Feature: add interactive reword selector (#443) 2025-05-29 20:51:12 +02:00
sandr01d 3f694f6e99
Refactor: Do not pass files to fixup and squash (#442)
Similar to 09f17c9, this removes the option to pass files to the fixup
and squash functions. There is no need to do so.
2025-05-28 19:37:36 +02:00
sandr01d c2b012855f
Feature: add interactive squash selector (#440) 2025-05-25 18:21:56 +02:00
sandr01d 47fd184c7c
Fix: use FORGIT_SHOW_FZF_OPTS in _forgit_show (#437) 2025-05-05 18:16:52 +02:00
sandr01d 79c4e5a4c4
Fix: create branch when checking non origin remote (#430) 2025-04-22 18:08:37 +02:00
carlfriedrich 09f17c9032
Allow passing arguments to git rebase (#422)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
If non-option arguments are passed to `git forgit rebase`, pass them
through directly to `git rebase`, without launching the interactive
selector, just like we do for other forgit commands.

Along with this, remove possibility to pass files to rebase, as there is
no need for that. I assume this was a copy-paste error when the
rebase function was introduced in the first place.
2025-02-15 14:57:57 +01:00
sandroid 0d65efc769 Feature: Add interactive git attributes generator
Some checks failed
ci / build (macos-latest) (push) Waiting to run
ci / build (ubuntu-20.04) (push) Waiting to run
ci / build (ubuntu-22.04) (push) Failing after 1s
2025-02-14 20:29:33 +01:00
sandroid 408fe6033a Refactor: Make functions interacting with repositories reusable 2025-02-14 20:29:33 +01:00
sandr01d e07b353b94
Refactor: Remove _forgit_ignore_clean (#421)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
2025-02-10 19:36:13 +01:00
carlfriedrich bb83b3cba0
Feature: add forgit show command (#417)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
Introducing `show` as a new subcommand of `forgit`, an interactive
version of `git show`. The configured default alias is `gso`.

Alt-T can be used to toggle between showing the diff and the commit
message in the fzf preview window.

The new command in used instead of `forgit diff` when pressing enter
in `forgit log`. This fixes the display of diffs for merge commits.

**Note**: we have a requirement for the `fzf` version now. The minimum
required `fzf` version is 0.49.0. If the installed version is lower,
forgit will exit with an error message.

Fixes #416.
2025-01-29 07:04:07 +01:00
Wenxuan df5191157f
fix: fix edit file key binding (alt-e) in diff and add (#415)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
The key binding for editing a file in diff and add was not working
properly on recent versions of fzf. As its documentation suggests, we
should replace `execute-silent` with `execute` since we need to switch
to a new screen and handle both input and output.

> fzf switches to the alternate screen when executing a command.
> However, if the command is expected to complete quickly, and you are
> not interested in its output, you might want to use execute-silent
> instead, which silently executes the command without the switching.
2024-12-22 09:18:39 +08:00
Sufien Tout 7a40a11e79
Meta: add an .editorconfig and apply it to the codebase (#404)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 0s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
2024-11-06 10:10:27 +01:00
sandr01d be82c47ceb
Feature: Add interactive git reflog (#398)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
2024-09-04 22:02:27 +02:00
Wenxuan 8b60a899f4
refactor: remove -u option from git status in forgit add (#397)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
2024-08-15 10:06:11 +08:00
sandr01d 17394d1056
Fix special characters in file names (#388)
Git escapes special characters in it's output when core.quotePath is
true or unset. Git always expects unquoted file paths as input. This
leads to issues when we consume output from git and use it to build
input for other git commands. This commit ensures we always feed unqoted
paths to git commands.
The _forgit_list_files function is introduced to handle usage of git
ls-files with the -z flag, which ensures unquoted paths.
It replaces the direct calls to git ls-files in _forgit_reset_head,
_forgit_stash_push and _forgit_checkout_file.
In _git_reset_head the -z option is added to the git diff command to
ensure unqoted paths.
Since git clean does not support the -z flag, we disable core.quotePath
by passing a configuration parameter in _forgit_clean. The same is done for
_forgit_add.
2024-05-12 02:00:08 +02:00
sandr01d b35b309ce5
Fix: Opening files from diff line when not in project root (#393)
When trying to open a file from gd in $EDITOR (alt + e) the wrong file
was being opened when the command wasn't executed from the repository's
root directory.
2024-04-27 16:42:37 +08:00
sandr01d 6f212fd2b2
Fix: gsp does not work outside the root directory (#386) 2024-04-26 23:03:42 +02:00
sandr01d 2ae84d3326
Allow disabling --graph with FORGIT_LOG_GRAPH_ENABLE=false in grc (#387) 2024-04-26 23:02:50 +02:00
sandr01d c76b00bcef
Fix: --date option in gbl can not be overridden anymore (#385)
The order of the arguments passed to git blame in _forgit_blame_preview
has been changed in bfffda6, putting --date=short as the last argument
instead of the first. This caused it taking precedence of anything
defined in $FORGIT_BLAME_GIT_OPTS.
This commit restores the order of the arguments to what they were before
bfffda6.
2024-04-25 22:57:02 +02:00
sandr01d 2903fef2af
Fix: Early out from _forgit_stash_push when no files can be stashed (#376)
Previously when using _forgit_stash_push without any local changes an empty file picker would open. Exit early and show a message instead.
2024-04-23 23:08:35 +02:00
sandr01d bc408f155c
Add a preview to _forgit_clean (#383) 2024-04-19 21:12:16 +02:00
sandr01d a6efc540ba
Move fzf options into $opts variables (#384)
_forgit_stash_push, _forgit_revert_commit and _forgit_blame passed some
fzf options as arguments directly instead of defining them in the $opts
variable, as we do everywhere else. This change makes these functions
consistent with the rest of the code base and additionally allows
overriding said options with the respective $FORGIT_*_FZF_OPTS
environment variables.
2024-04-19 21:11:05 +02:00
sandr01d d240263f42
Do not disable shellcheck 2206 and 2068 in _forgit_ignore (#382)
Shellcheck 2206 and 2068 have been disabled in _forgit_ignore for a very long time. The code that triggers the shellchecks was added in ce240ac before the shellcheck action had been added. The shellcheck for the lines in question got disabled in c14ce93. Disabling shellcheck does not seem necessary, instead this commit implements the fixes shellcheck suggest.
2024-04-13 20:57:00 +02:00
sandr01d 1c34d0d54d
Fix ga, gsp & gcf with older git versions (#335)
Removes the usage of --pathspec-file-nul (which is not available in older git versions) in favor of storing the file names passed to the git command in an array instead of a string.
2024-04-09 22:43:24 +02:00
sandr01d 131f2c1f66
Fix: Pager variables are not evaluated (#381)
Reintroduces the usage of eval for evaluating pagers. We removed all usage of eval with #326, which broke code defined by users in the $FORGIT_*_PAGER environment variables and git pagers. In this particular case, eval does exactly what we want, since we do want to execute code that is defined by the user outside of forgit.
2024-04-09 22:37:29 +02:00
sandr01d cac700ebe1
Refactor: Do not ignore shellcheck 2207 (#378)
We sometimes capture multiline output in an array. We used to do so
directly, while setting IFS to "\n" to control splitting. This has the
downside that bashs glob expansion will be invoked.
Use read -r in such cases to add each line into the array without glob
expansion.
2024-04-05 20:12:32 +02:00
sandr01d 7690364a98
Fix preview for deleted files in _forgit_stash_push (#336) 2024-03-31 00:48:18 +01:00
sandr01d 032b52f6d5
Fix branch preview for branches that have the same name as a file (#374)
The preview for branches (when using gbd or gcb) did not work for branches that have the same name as a file in the repository. This commit fixes this behavior by separating files and revisions with '--' as git suggests, while leaving the files blank to keep matching all files.
2024-03-31 00:31:48 +01:00