diff --git a/.gitmodules b/.gitmodules index b9b9199..14c7fd0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "zsh/modules/zsh-syntax-highlighting"] path = zsh/modules/zsh-syntax-highlighting url = https://github.com/zsh-users/zsh-syntax-highlighting.git -[submodule "zsh/modules/forgit"] - path = zsh/modules/forgit - url = https://github.com/wfxr/forgit.git diff --git a/zsh/.zshrc b/zsh/.zshrc index 0547cc2..ab93689 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -26,10 +26,10 @@ if [ -f $XDG_CONFIG_HOME/fzf/fzf.zsh ]; then _fzf_compgen_dir() { fd -H -L --ignore-file $XDG_CONFIG_HOME/local/fd --type d . "$1" } + source $ZDOTDIR/fzf-git.zsh fi # plugins -source $ZDOTDIR/modules/forgit/forgit.plugin.zsh source $ZDOTDIR/modules/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh # theme diff --git a/zsh/fzf-git.zsh b/zsh/fzf-git.zsh new file mode 100644 index 0000000..719bcd0 --- /dev/null +++ b/zsh/fzf-git.zsh @@ -0,0 +1,26 @@ +# heavily inspired (and sometimes stolen from): https://github.com/wfxr/forgit.git + +_am_i_git_repo() { git rev-parse --is-inside-work-tree >/dev/null; } + +gl() { + _am_i_git_repo || return 1 + files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") + cmd="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | cat" + g=(git log --graph --format='%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset' --color=always "$@") + fzf=(fzf --ansi --reverse --tiebreak=index --no-sort --bind='ctrl-j:preview-up' --bind='ctrl-k:preview-down' --bind="ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '\n' |pbcopy)" --bind="enter:execute($cmd | LESS='-r' less)" --preview 'f() { set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}"); [ $# -eq 0 ] || git show --color=always $1; }; f {}') + $g | $fzf + return 0 +} + +gd() { + _am_i_git_repo || return 1 + extract=" + sed 's/^.*] //' | + sed 's/.* -> //' | + sed -e 's/^\\\"//' -e 's/\\\"\$//'" + files=$(git -c color.status=always -c status.relativePaths=true status -su | grep -F -e "$changed" -e "$unmerged" -e "$untracked" | sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/' | fzf --reverse --tiebreak=index --no-sort --bind='ctrl-j:preview-up' --bind='ctrl-k:preview-down' --preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' | sh -c "$extract") + [[ -n "$files" ]] && echo "$files"| tr '\n' '\0' |xargs -0 -I% git add % && git status -su && return + echo 'Nothing to add.' +} +alias ga=gd +alias gs=gd diff --git a/zsh/modules/forgit b/zsh/modules/forgit deleted file mode 160000 index c63bd2b..0000000 --- a/zsh/modules/forgit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c63bd2b8d1f0fc97c5b54ee24c02e4274e1eca5f