config/git: extract fzf aliases
This commit is contained in:
parent
cf2f85fcb1
commit
201c082aa1
|
@ -20,13 +20,17 @@
|
||||||
[submodule]
|
[submodule]
|
||||||
fetchJobs = 0
|
fetchJobs = 0
|
||||||
|
|
||||||
|
# Create & Sync
|
||||||
[pull]
|
[pull]
|
||||||
ff = only
|
ff = only
|
||||||
[checkout]
|
[checkout]
|
||||||
defaultRemote = origin
|
defaultRemote = origin
|
||||||
[init]
|
[init]
|
||||||
defaultBranch = main
|
defaultBranch = main
|
||||||
|
[push]
|
||||||
|
default = current # Automatically push to branch with matching name
|
||||||
|
|
||||||
|
# Editor
|
||||||
[diff]
|
[diff]
|
||||||
tool = nvim
|
tool = nvim
|
||||||
submodule = log
|
submodule = log
|
||||||
|
@ -39,18 +43,16 @@
|
||||||
[difftool "nvim"]
|
[difftool "nvim"]
|
||||||
cmd = "nvim -d \"$LOCAL\" \"$REMOTE\""
|
cmd = "nvim -d \"$LOCAL\" \"$REMOTE\""
|
||||||
|
|
||||||
# Automatically push to branch with matching name
|
|
||||||
[push]
|
|
||||||
default = current
|
|
||||||
[status]
|
[status]
|
||||||
showStash = true
|
showStash = true
|
||||||
# Disable pagination for branch commmand by default
|
|
||||||
[pager]
|
[pager]
|
||||||
branch = false
|
branch = false # Disable pagination for branch list
|
||||||
[grep]
|
[grep]
|
||||||
lineNumber = true
|
lineNumber = true
|
||||||
[log]
|
[log]
|
||||||
date=local
|
date=local
|
||||||
|
[commit]
|
||||||
|
verbose
|
||||||
|
|
||||||
[color "status"]
|
[color "status"]
|
||||||
added = green
|
added = green
|
||||||
|
@ -132,15 +134,10 @@
|
||||||
sd = switch -d
|
sd = switch -d
|
||||||
sm = !git switch $(git main)
|
sm = !git switch $(git main)
|
||||||
|
|
||||||
fzf = !fzf --tiebreak=end,index --multi --preview-window=wrap --preview='git diff HEAD --color=always -- {}'
|
|
||||||
fzs = !cut -z -c2- | git fzf --read0 -d' ' --nth=2.. --bind='alt-enter:execute(nvim {2..})' --preview='test {1} != \\? && git diff --color HEAD -U5 -- {2..} | $(git config interactive.diffFilter) || find {2..} -type f | xargs -I% diff --recursive --color=always -u /dev/null %' | cut -c3-
|
|
||||||
|
|
||||||
# Local Changes
|
# Local Changes
|
||||||
a = add -u
|
a = add -u
|
||||||
aa = add -u .
|
aa = add -u .
|
||||||
ap = add -p
|
ap = add -p
|
||||||
af = !git status --porcelain --no-renames --untracked-files=all -z | grep -v '^\\w ' -z | git fzs | git -c advice.addEmptyPathspec=false add --verbose --pathspec-from-file=-
|
|
||||||
sf = "!git status --porcelain --no-renames -z | sed -z 's/^\\(\\w\\) / \\1/' | git fzs >/tmp/git-sf && git -c advice.addEmptyPathspec=false add --intent-to-add --pathspec-from-file=/tmp/git-sf; git commit --only -v --pathspec-from-file=/tmp/git-sf"
|
|
||||||
|
|
||||||
c = commit -v
|
c = commit -v
|
||||||
cad = !git diff-tree --no-commit-id --name-only -r HEAD | git commit -v --amend --pathspec-from-file=- # Amend commit with all already changed files
|
cad = !git diff-tree --no-commit-id --name-only -r HEAD | git commit -v --amend --pathspec-from-file=- # Amend commit with all already changed files
|
||||||
|
|
|
@ -7,7 +7,7 @@ y() {
|
||||||
test "$#" -eq 0 && yadm s || yadm "$@"
|
test "$#" -eq 0 && yadm s || yadm "$@"
|
||||||
}
|
}
|
||||||
yc() {
|
yc() {
|
||||||
local folder="${1:-${PWD/$XDG_CONFIG_HOME\/}}"
|
local folder="$(test -e "${1:-$PWD}" && realpath --relative-to="$XDG_CONFIG_HOME" "${1:-$PWD}" || echo "$1")"
|
||||||
echo "config/$folder:" >/tmp/yc-msg
|
echo "config/$folder:" >/tmp/yc-msg
|
||||||
yadm commit -v --template /tmp/yc-msg ${@:2} -- "$XDG_CONFIG_HOME/$folder*"
|
yadm commit -v --template /tmp/yc-msg ${@:2} -- "$XDG_CONFIG_HOME/$folder*"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
# Create a commit or stage files via fzf selection
|
||||||
|
|
||||||
|
fzfpipe() {
|
||||||
|
# Take nul-separated input from git-status short/porcelain
|
||||||
|
# and return a newline-separated list of selected files
|
||||||
|
cut -z -c2- |
|
||||||
|
git fzf-diff --read0 -d' ' --nth=2.. --bind='alt-enter:execute(nvim {2..})' \
|
||||||
|
--preview="test {1} != \? && git diff --color HEAD -U5 -- {2..} | $(git config interactive.diffFilter) || find {2..} -type f | xargs -I% diff --recursive --color=always -u /dev/null %" |
|
||||||
|
cut -c3-
|
||||||
|
}
|
||||||
|
|
||||||
|
cd "$(git rev-parse --show-toplevel)"
|
||||||
|
case "$1" in
|
||||||
|
(add) shift
|
||||||
|
git status -z --porcelain --no-renames --untracked-files=all |
|
||||||
|
grep -zv '^\\w ' | fzfpipe |
|
||||||
|
git -c advice.addEmptyPathspec=false add --verbose --pathspec-from-file=- "$@";;
|
||||||
|
(*) git status -z --porcelain --no-renames |
|
||||||
|
sed -z 's/^\\(\\w\\) / \\1/' | fzfpipe >/tmp/git-fuzz
|
||||||
|
git -c advice.addEmptyPathspec=false add --intent-to-add --pathspec-from-file=/tmp/git-fuzz
|
||||||
|
git commit -v --only --pathspec-from-file=/tmp/git-fuzz "$@";;
|
||||||
|
esac
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# fzf tweaked for previewing diffs for git tracked files
|
||||||
|
fzf --tiebreak=end,index --multi --preview-window=wrap --preview='git diff HEAD --color=always -- {}' "$@"
|
Loading…
Reference in New Issue