@@ -118,12 +118,22 @@ abbr -a gaa "git add --all"
118
118
abbr -a gad " git add (git ls-files --deleted)"
119
119
abbr -a gai " git add --interactive"
120
120
abbr -a gam " git add (git ls-files --modified)"
121
- abbr -a gap " git add --patch"
121
+ function _abbr_git_add_patch
122
+ #
123
+ # command git status --porcelain
124
+ #
125
+
126
+ echo " git add --patch"
127
+ end
128
+
129
+ abbr -a gap --function _abbr_git_add_patch
130
+
122
131
abbr -a gau " git add (git ls-files --others --exclude-standard)"
123
132
124
133
function _abbr_git_add_modified_and_commit_previous
125
134
# 1. find the previous commit
126
135
set -l expansion " git add (git ls-files --modified)"
136
+ # TODO: can this be read from git reflog instead?
127
137
set -l previous_commit (history search --max 1 --prefix " git commit --message" )
128
138
# 2. if there is a previous commit, add it to the command
129
139
if test -n " $previous_commit "
136
146
# have to add the, now, modified files again and then commit them with the same message.
137
147
abbr -a gamcp --set-cursor -f _abbr_git_add_modified_and_commit_previous
138
148
149
+ # git archive
150
+ function _abbr_git_archive
151
+ set -l expansion git archive
152
+ set -l repo_name (path basename (pwd ))
153
+ set -l output
154
+ switch $argv [1]
155
+ case gar
156
+ set output " $repo_name .tar"
157
+ case garz
158
+ set output " $repo_name .zip"
159
+ case ' *'
160
+ # unreachable
161
+ end
162
+
163
+ set -a expansion --output $output
164
+ set -a expansion HEAD
165
+ echo $expansion
166
+ end
167
+
168
+ abbr -a gar --regex " garz?" --function _abbr_git_archive
169
+
170
+ # git bisect
171
+ function _abbr_git_bisect
172
+
173
+ # TODO: figure out how to detect if a git bisect is underway
174
+ echo " git bisect"
175
+ end
176
+ abbr -a gbs --function _abbr_git_bisect
177
+
139
178
# git blame
140
179
# abbr -a gb
141
180
@@ -306,70 +345,96 @@ function _abbr_git_diff
306
345
and printf " GIT_EXTERNAL_DIFF=difft " # then use as the diff tool
307
346
# TODO: append --staged if all modified files are staged
308
347
309
- echo " git diff"
310
- end
311
- abbr -a gd --set-cursor -f _abbr_git_diff
312
-
313
- # TODO: create a function for this similar to `gstatus`
314
- abbr -a gds git diff --staged
315
-
316
- function _abbr_git_fetch
317
- if not command -q gum
318
- echo " git fetch"
319
- return
348
+ set -l expansion git diff
349
+ if string match --regex --quiet s -- $argv [1]
350
+ set -a expansion --staged
320
351
end
352
+ echo $expansion
353
+ end
354
+ abbr -a gd --regex " gds?" --set-cursor -f _abbr_git_diff
321
355
322
- # TODO: add to `gitui` aswell
323
- # fetch "Retrieves changes from the remote"
324
- # fetch --prune "Retrieves changes from the remote and removes deleted remote branches"
325
- # fetch --tags "Retrieves changes from the remote including all tags"
326
- # fetch --all "Retrieves changes from all remotes" # TODO: enumerate known remotes here
327
- # fetch --all --prune "Retrieves changes from all remotes and removes deleted remote branches"
328
- # fetch --all --tags "Retrieves changes from all remotes including all tags"
356
+ # function _abbr_git_fetch
357
+ # if not command -q gum
358
+ # echo "git fetch"
359
+ # return
360
+ # end
329
361
330
- # TODO: handle case where user presses esc gracefully
331
- gum choose
332
- commandline -f repaint
333
- end
362
+ # # TODO: add to `gitui` aswell
363
+ # set -l options
364
+ # set -a options "fetch # Retrieves changes from the remote"
365
+ # set -a options "fetch --prune # Retrieves changes from the remote and removes deleted remote branches"
366
+ # set -a options "fetch --tags # Retrieves changes from the remote including all tags"
367
+ # set -a options "fetch --all # Retrieves changes from all remotes" # TODO: enumerate known remotes here
368
+ # set -a options "fetch --all --prune # Retrieves changes from all remotes and removes deleted remote branches"
369
+ # set -a options "fetch --all --tags # Retrieves changes from all remotes including all tags"
370
+
371
+ # printf "%s\n" (printf "%s\n" $options | fish_indent --ansi) | gum choose
372
+ # # TODO: handle case where user presses esc gracefully
373
+ # # gum choose
374
+ # commandline -f repaint
375
+ # end
334
376
335
377
# git fetch
336
- abbr -a gf --set-cursor " git fetch %"
337
- abbr -a gfa --set-cursor " git fetch --all% # fetch the latest changes from all remote upstream repositories"
338
- abbr -a gft --set-cursor " git fetch --tags% # also fetch tags from the remote upstream repository"
339
- abbr -a gfp --set-cursor " git fetch --prune% # delete local references to remote branches that have been deleted upstream"
378
+ # abbr -a gf --function _abbr_git_fetch
379
+ abbr -a gf --set-cursor " git fetch --prune --tags --all -v"
380
+ # abbr -a gfa --set-cursor "git fetch --all% # fetch the latest changes from all remote upstream repositories"
381
+ # abbr -a gft --set-cursor "git fetch --tags% # also fetch tags from the remote upstream repository"
382
+ # abbr -a gfp --set-cursor "git fetch --prune% # delete local references to remote branches that have been deleted upstream"
340
383
341
384
# git grep
342
385
function _abbr_git_grep
343
- set -l expansion git grep " '%'"
344
- if string match --regex --groups-only " gg([0-9]+)" -- $argv [1] | read n
386
+ set -l expansion git grep --heading
387
+ if not command git config grep .lineNumber > /dev/null
388
+ set -a expansion --line-number
389
+ end
390
+
391
+ if not command git config grep .column > /dev/null
392
+ set -a expansion --column
393
+ end
394
+
395
+ command git config grep .patternType | read patternType
396
+ if test $pipestatus [1] -ne 0
397
+ set -a expansion --perl-regexp
398
+ else if test $patternType = regular; and not command git config grep .extendedRegexp > /dev/null
399
+ set -a expansion --extended-regexp
400
+ end
401
+
402
+ if string match --regex --quiet v -- $argv [1]
403
+ set -a expansion --invert-match
404
+ end
405
+ if string match --regex --quiet i -- $argv [1]
406
+ set -a expansion --ignore-case
407
+ end
408
+
409
+ if string match --regex --groups-only " ([0-9]+)" -- $argv [1] | read n
345
410
set -a expansion " HEAD~$n "
346
411
end
347
412
413
+ set -a expansion " '%'"
414
+
348
415
echo $expansion
349
416
end
350
- abbr -a gg --regex " gg [0-9]*" --set-cursor --function _abbr_git_grep
417
+ abbr -a gg --regex " ggi?v? [0-9]*" --set-cursor --function _abbr_git_grep
351
418
abbr -a gga --set-cursor " git grep '%' -- (git rev-list --all) # This might take some time to execute!"
352
419
353
420
# git log
354
421
function _abbr_git_log
355
422
set -l expansion git log
356
- if string match --regex --groups-only " gl([0-9]+)" -- $argv [1] | read n
357
- set -a expansion --max-count $n
423
+ if string match --regex --quiet p -- $argv [1]
424
+ set -a expansion --patch
425
+ else if string match --regex --quiet o -- $argv [1]
426
+ set -a expansion --oneline --decorate --graph
427
+ else if string match --regex --quiet s -- $argv [1]
428
+ set -a expansion --stat
358
429
end
359
430
360
- echo $expansion
361
- end
362
- abbr -a gl --regex " gl[0-9]*" --function _abbr_git_log
363
-
364
- function _abbr_git_log_oneline
365
- set -l expansion git log --oneline --graph
366
- if string match --regex --groups-only " gl([0-9]+)" -- $argv [1] | read n
431
+ if string match --regex --groups-only ' ([0-9]+)$' -- $argv [1] | read n
367
432
set -a expansion --max-count $n
368
433
end
369
434
370
435
echo $expansion
371
436
end
372
- abbr -a glo --regex " glo[ 0-9]*" --function _abbr_git_log_oneline
437
+ abbr -a gl --regex " gl[ops]?[ 0-9]*" --function _abbr_git_log
373
438
374
439
# git ls-files
375
440
abbr -a gls git ls -files
@@ -394,9 +459,30 @@ abbr -a gm --set-cursor --function _abbr_git_merge
394
459
abbr -a gma git merge --abort
395
460
abbr -a gmc git merge --continue
396
461
462
+
463
+ function _abbr_git_mv
464
+ if not command git rev-parse --is-inside-work-tree 2> /dev/null >&2
465
+ echo mv
466
+ else
467
+ # https://git-scm.com/docs/git-mv
468
+ echo " git mv -k --verbose"
469
+ end
470
+ end
471
+ abbr -a mv --function _abbr_git_mv
472
+
473
+ function _abbr_git_rm
474
+ if not command git rev-parse --is-inside-work-tree 2> /dev/null >&2
475
+ echo rm
476
+ else
477
+ # https://git-scm.com/docs/git-rm
478
+ echo " git rm"
479
+ end
480
+ end
481
+ abbr -a rm --function _abbr_git_rm
397
482
# git mv
398
483
# TODO: try to detect a relevant file to move
399
- abbr -a gmv git mv
484
+ # abbr -a gmv git mv
485
+ # abbr -a grm git rm
400
486
401
487
# git pull
402
488
set --query git_fish_abbr_git_pull_merge_strategy
@@ -446,11 +532,13 @@ function __git::abbr::git_push
446
532
echo " # no commits to push ¯\\ _(ツ)_/¯"
447
533
end
448
534
449
- set -l git_push_opts
535
+ set -l git_push_opts --verbose
450
536
set -l branch (command git rev-parse --abbrev-ref HEAD)
451
537
set -l remote_branch (command git rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null)
452
538
if test $status -ne 0
539
+ # FIXME: handle case where no remote has been confiugred yet
453
540
# Local branch has no remote branch, so create one
541
+ # TODO: print comment note of where the remote is
454
542
echo " git push $git_push_opts --set-upstream origin $branch % # no remote branch found, creating one"
455
543
else
456
544
set -l unpushed_tags (command git push --tags --dry-run & | string match --regex --groups-only ' \ * \ [new tag\ ]\ s+(\ S+)' )
@@ -581,13 +669,17 @@ function _abbr_git_show
581
669
set -a expansion HEAD
582
670
end
583
671
672
+ if string match --regex --quiet s -- $argv [1]
673
+ set -a expansion --summary
674
+ end
675
+
584
676
if command --query difft; and not set --query --export GIT_EXTERNAL_DIFF
585
677
set -p expansion " GIT_EXTERNAL_DIFF=difft"
586
678
set -a expansion --ext-diff
587
679
end
588
680
echo $expansion
589
681
end
590
- abbr -a gsh --regex " gsh [0-9]*" --function _abbr_git_show
682
+ abbr -a gsh --regex " gshs? [0-9]*" --function _abbr_git_show
591
683
592
684
# git show-branch
593
685
abbr -a gsb git show-branch
@@ -713,14 +805,25 @@ abbr -a gwtrm git worktree remove
713
805
abbr -a gwtrmf git worktree remove --force
714
806
715
807
function _abbr_git_clone
716
- set -l args --recurse-submodules
808
+ # TODO: detect if the user has permission to create a directory in $PWD, and print a warning if not
809
+
810
+ if command git rev-parse --inside-work-tree 2> /dev/null >&2
811
+ echo " # ERROR: You are already in a git directory"
812
+ echo " %"
813
+ # TODO: move this further down, and suggest to add the repo (if it is a repo) as a submodule
814
+ # echo "# HINT: maybe you want to "
815
+ # echo "# git submodule add"
816
+ return
817
+ end
818
+
819
+ set -l args --recurse-submodules --verbose --progress
717
820
set -l postfix_args
718
821
# TODO: handle case where clipboard can not be read
719
- set -l clipboard_contents (fish_clipboard_paste)
822
+ set -l clipboard_contents (fish_clipboard_paste | string trim )
720
823
721
- # You ctrl+l && ctrl+c a git url
824
+ # You ctrl+l && ctrl+c a git url in a browser
722
825
if string match --quiet --regex " ^(https?://|git@).*\.git\$ " -- " $clipboard_contents "
723
- set -a args $clipboard_contents
826
+ set -a args " ' $clipboard_contents ' "
724
827
# Parse the directory name from the url
725
828
set -a postfix_args ' && cd'
726
829
set -a postfix_args (string replace --all --regex ' ^.*/(.*)\ .git$' ' $1' $clipboard_contents )
@@ -732,24 +835,26 @@ function _abbr_git_clone
732
835
set -a postfix_args " && cd $reponame "
733
836
else if string match --groups-only --regex " ^\s*git clone https://git(hub|lab)\.com/([^/]+)/(.+)" $clipboard_contents | read --line _hub owner repository
734
837
# example: git clone https://github.com/bevyengine/bevy
735
- set -a postfix_args $clipboard_contents
838
+ set -a postfix_args " ' $clipboard_contents ' "
736
839
set -a postfix_args " && cd $repository "
737
840
end
738
841
739
- # TODO: use (capture) instead
740
- set -l depth (string replace --all --regex ' [^0-9]' ' ' $argv [1])
741
- if test -n $depth
842
+ if string match --regex --groups-only " ([0-9]+)" -- $argv [1] | read depth
742
843
set -a args --depth =$depth
743
844
end
744
845
745
846
echo git clone $args $postfix_args
746
847
end
747
848
748
- abbr -a git_clone_at_depth --regex " gc[0-9]*" --function _abbr_git_clone
849
+ abbr -a git_clone_at_depth --regex " gc[0-9]*" --set-cursor -- function _abbr_git_clone
749
850
750
851
751
852
# TODO: detect if the last commit had message `squash! WIP` and you were the author, and suggest to use amend instead
752
- abbr -a gwip " git add (git ls-files --modified) && git commit --message 'squash! WIP' --no-verify"
853
+ function _abbr_gwip
854
+
855
+ echo " git add (git ls-files --modified) && git commit --message 'squash! WIP' --no-verify"
856
+ end
857
+ abbr -a gwip --function _abbr_gwip
753
858
754
859
# unstage a file
755
860
0 commit comments