first integration of anygit functionality, mutli file support
This commit is contained in:
parent
306c72e58a
commit
a76ca97377
1 changed files with 151 additions and 47 deletions
198
dotgit.sh
198
dotgit.sh
|
|
@ -1,60 +1,164 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
[[ ! "${DOT_FILES}" ]] && echo "NOT setting dotGit aliases, since DOT_FILES not set." && return
|
[[ ! "$DOT_FILES" ]] && echo "NOT setting dotgit aliases, since DOT_FILES not set." && return
|
||||||
[[ ! "${DOT_HOME}" ]] && echo "NOT setting dotGit aliases, since DOT_HOME not set." && return
|
[[ ! "$DOT_HOME" ]] && echo "NOT setting dotgit aliases, since DOT_HOME not set." && return
|
||||||
|
|
||||||
|
[[ -n "$DEBUG" ]] && echo loading dotGit aliases
|
||||||
|
|
||||||
|
[[ -z "$DOTGIT_MULTI_LIMIT" ]] && DOTGIT_MULTI_LIMIT=2
|
||||||
|
[[ -z "$DOTGIT_MULTI_ACCEPT" ]] && DOTGIT_MULTI_ACCEPT='{1}'
|
||||||
|
[[ -z "$DOTGIT_PREVIEW" ]] && DOTGIT_PREVIEW='bat -p --color=always'
|
||||||
|
|
||||||
# the master alias
|
# the master alias
|
||||||
alias .git='git --git-dir=${DOT_FILES} --work-tree=${DOT_HOME}'
|
alias .git='git --git-dir=${DOT_FILES} --work-tree=${DOT_HOME}'
|
||||||
|
|
||||||
# and all the shortcuts
|
# and all the shortcuts
|
||||||
alias .g='.git'
|
alias .ga='.git add'
|
||||||
alias .ga='.g add'
|
alias .gc='.git commit'
|
||||||
alias .gc='.g commit'
|
alias .gco='.git checkout'
|
||||||
alias .gco='.g checkout'
|
alias .gd='.git diff'
|
||||||
alias .gd='.g diff'
|
alias .gss='.git status --short'
|
||||||
alias .gss='.g status --short'
|
alias .glo='.git log --oneline --decorate'
|
||||||
alias .gp='.g push'
|
alias .glg='.git log --stat'
|
||||||
alias .gl='.g pull'
|
alias .glgp='.git log --stat --patch'
|
||||||
alias .glo='.g log --oneline --decorate'
|
alias .gbl='git blame -w'
|
||||||
alias .glg='.g log --stat'
|
alias .gb='git branch'
|
||||||
alias .glgp='.g log --stat --patch'
|
alias .gba='git branch --all'
|
||||||
|
alias .gbd='git branch --delete'
|
||||||
# if fzf is installed we can have nice things
|
alias .gbD='git branch --delete --force'
|
||||||
# https://github.com/junegunn/fzf
|
alias .gm='git merge'
|
||||||
if [[ $(command -v fzf) ]]; then
|
alias .gma='git merge --abort'
|
||||||
fzf_opts=(--preview "bat -n --color=always {}"
|
alias .gmc='git merge --continue'
|
||||||
--multi --ansi -0
|
alias .gc!='git commit --verbose --amend'
|
||||||
--preview-window "right,60%,<60(down,75%),+{2}/2"
|
alias .gcm='git commit --message'
|
||||||
--bind 'ctrl-z:ignore'
|
alias .gcp='git cherry-pick'
|
||||||
)
|
alias .gcpa='git cherry-pick --abort'
|
||||||
_dotgit_ge() {
|
alias .gcpc='git cherry-pick --continue'
|
||||||
files=$(cd "$DOT_HOME" && .g ls-files --full-name |
|
alias .gclean='git clean --interactive -d'
|
||||||
fzf "${fzf_opts[@]}" \
|
alias .ginit='git init --bare "${DOT_FILES}"; .git config --local status.showUntrackedFiles no'
|
||||||
--preview "bat --color=always {1}" \
|
# only set up push and pull if DOT_ORIGIN is set
|
||||||
--bind "enter:accept-non-empty" \
|
if [[ -n "$DOT_ORIGIN" ]]; then
|
||||||
-q "${@:-}" | paste -sd' ')
|
alias .gp='.git push'
|
||||||
[[ -n "$files" ]] && sh -c "cd $DOT_HOME && $EDITOR $files"
|
alias .gl='.git pull'
|
||||||
}
|
alias .gclone='git clone --bare "${DOT_ORIGIN}" "${DOT_FILES}"; .git config --local status.showUntrackedFiles no'
|
||||||
alias .ge='_dotgit_ge'
|
|
||||||
|
|
||||||
_dotgit_gg() {
|
|
||||||
files=$(cd "$DOT_HOME" && .g grep --full-name --color=always -n "$@" |
|
|
||||||
fzf "${fzf_opts[@]}" -d ":" \
|
|
||||||
--preview "bat --color=always -H{2} {1}" \
|
|
||||||
--accept-nth "-c 'e {1}|{2}'" | paste -sd' ')
|
|
||||||
[[ -n "$files" ]] && sh -c "cd $DOT_HOME && $EDITOR $files"
|
|
||||||
}
|
|
||||||
# shellcheck disable=SC2154
|
|
||||||
alias .gg='_dotgit_gg' # | read -r f; echo $f'
|
|
||||||
else
|
else
|
||||||
# simplified grep but no "interactive file select"
|
alias .gp='echo "error: must first configure DOT_HOME"'
|
||||||
alias .gg='.g grep'
|
alias .gl='echo "error: must first configure DOT_HOME"'
|
||||||
|
alias .gclone='echo "error: must first configure DOT_HOME"'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
alias .ginit='git init --bare "${DOT_FILES}"; .g config --local status.showUntrackedFiles no'
|
|
||||||
[[ -n "$DOT_ORIGIN" ]] && alias .gclone='git clone --bare "${DOT_ORIGIN}" "${DOT_FILES}"; .g config --local status.showUntrackedFiles no'
|
|
||||||
|
|
||||||
# if lazygit or gitui are avaiable, we set up a .lazygit and .gitui
|
# if lazygit or gitui are avaiable, we set up a .lazygit and .gitui
|
||||||
[[ $(command -v lazygit) ]] &&
|
[[ $(command -v lazygit) ]] &&
|
||||||
alias .lazygit='lazygit -g ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}'
|
alias .lazygit='lazygit -g ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}'
|
||||||
[[ $(command -v gitui) ]] &&
|
[[ $(command -v gitui) ]] &&
|
||||||
alias .gitui='gitui -d ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}'
|
alias .gitui='gitui -d ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}'
|
||||||
|
|
||||||
|
# if fzf is installed we can have nice things
|
||||||
|
# https://github.com/junegunn/fzf
|
||||||
|
if [[ $(command -v fzf) ]]; then
|
||||||
|
fzf_opts=(--multi="$DOTGIT_MULTI_LIMIT" --ansi -0
|
||||||
|
--preview-window "right,60%,<60(down,75%),+{2}/2"
|
||||||
|
--bind 'ctrl-z:ignore'
|
||||||
|
)
|
||||||
|
_dotgit_ge() {
|
||||||
|
local gitdir
|
||||||
|
local files
|
||||||
|
gitdir=$(.git rev-parse --show-toplevel)
|
||||||
|
files=$(cd "$gitdir" && .git ls-files --full-name |
|
||||||
|
fzf "${fzf_opts[@]}" \
|
||||||
|
--preview "$DOTGIT_PREVIEW {1}" \
|
||||||
|
--bind "enter:accept-non-empty" \
|
||||||
|
-q "${@:-}" | paste -sd' ')
|
||||||
|
[[ -n "$files" ]] && sh -c "cd \"$gitdir\" && \"$EDITOR\" $files"
|
||||||
|
}
|
||||||
|
alias .ge='_dotgit_ge'
|
||||||
|
|
||||||
|
_dotgit_gg() {
|
||||||
|
local gitdir
|
||||||
|
local files
|
||||||
|
gitdir=$(.git rev-parse --show-toplevel)
|
||||||
|
files=$(cd "$gitdir" && .git grep --full-name --color=always -n "$@" |
|
||||||
|
fzf "${fzf_opts[@]}" -d ":" \
|
||||||
|
--preview "$DOTGIT_PREVIEW -H{2} {1}" \
|
||||||
|
--accept-nth "$DOTGIT_MULTI_ACCEPT" | paste -sd' ')
|
||||||
|
[[ -n "$files" ]] && sh -c "cd \"$gitdir\" && \"$EDITOR\" $files"
|
||||||
|
}
|
||||||
|
alias .gg='_dotgit_gg'
|
||||||
|
else
|
||||||
|
# simplified grep but no "interactive file select"
|
||||||
|
alias .gg='.git grep'
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -n "$DEBUG" ]] && echo dotGit aliases loaded
|
||||||
|
|
||||||
|
if [[ "$DOTGIT_ANYGIT" == 'yes' ]]; then
|
||||||
|
[[ -n "$DEBUG" ]] && echo loading anyGit aliases
|
||||||
|
|
||||||
|
alias ga='git add'
|
||||||
|
alias gba='git branch --all'
|
||||||
|
alias gbd='git branch --delete'
|
||||||
|
alias gbD='git branch --delete --force'
|
||||||
|
alias gb='git branch'
|
||||||
|
alias gbl='git blame -w'
|
||||||
|
alias gc='git commit'
|
||||||
|
alias gclean='git clean --interactive -d'
|
||||||
|
alias gclone='git clone'
|
||||||
|
alias gcm='git commit --message'
|
||||||
|
alias gco='git checkout'
|
||||||
|
alias gcpa='git cherry-pick --abort'
|
||||||
|
alias gcpc='git cherry-pick --continue'
|
||||||
|
alias gcp='git cherry-pick'
|
||||||
|
alias gd='git diff'
|
||||||
|
alias ge=_dotgit_ge
|
||||||
|
alias gg=_dotgit_gg
|
||||||
|
alias ginit='git init'
|
||||||
|
alias glg='git log --stat'
|
||||||
|
alias gl='git pull'
|
||||||
|
alias glgp='git log --stat --patch'
|
||||||
|
alias glo='git log --oneline --decorate'
|
||||||
|
alias gma='git merge --abort'
|
||||||
|
alias gmc='git merge --continue'
|
||||||
|
alias gm='git merge'
|
||||||
|
alias gp='git push'
|
||||||
|
alias grt='git rev-parse --show-toplevel'
|
||||||
|
alias gss='git status --short'
|
||||||
|
|
||||||
|
# if fzf is installed we can have nice things
|
||||||
|
# https://github.com/junegunn/fzf
|
||||||
|
if [[ $(command -v fzf) ]]; then
|
||||||
|
fzf_opts=(--multi="$DOTGIT_MULTI_LIMIT" --ansi -0
|
||||||
|
--preview-window "right,60%,<60(down,75%),+{2}/2"
|
||||||
|
--header '<tab> to mark more than one file | <enter> to open file(s) in editor'
|
||||||
|
--bind 'ctrl-z:ignore'
|
||||||
|
--bind 'ctrl-w:toggle-wrap'
|
||||||
|
)
|
||||||
|
_anygit_ge() {
|
||||||
|
local gitdir
|
||||||
|
gitdir=$(git rev-parse --show-toplevel)
|
||||||
|
local files
|
||||||
|
files=$(cd "$gitdir" && git ls-files --full-name |
|
||||||
|
fzf "${fzf_opts[@]}" \
|
||||||
|
--preview "$DOTGIT_PREVIEW {1}" \
|
||||||
|
--bind "enter:accept-non-empty" \
|
||||||
|
-q "${@:-}" | paste -sd' ')
|
||||||
|
[[ -n "$files" ]] && sh -c "cd \"$gitdir\" && \"$EDITOR\" $files"
|
||||||
|
}
|
||||||
|
alias ge='_anygit_ge'
|
||||||
|
|
||||||
|
_anygit_gg() {
|
||||||
|
local gitdir
|
||||||
|
gitdir=$(git rev-parse --show-toplevel)
|
||||||
|
local files
|
||||||
|
files=$(cd "$gitdir" && git grep --full-name --color=always -n "$@" |
|
||||||
|
fzf "${fzf_opts[@]}" -d ":" \
|
||||||
|
--preview "$DOTGIT_PREVIEW -H{2} {1}" \
|
||||||
|
--accept-nth "$DOTGIT_MULTI_ACCEPT" | paste -sd' ')
|
||||||
|
|
||||||
|
[[ -n "$files" ]] && sh -c "cd \"$gitdir\" && \"$EDITOR\" $files"
|
||||||
|
}
|
||||||
|
alias gg='_anygit_gg' # | read -r f; echo $f'
|
||||||
|
else
|
||||||
|
# simplified grep but no "interactive file select"
|
||||||
|
alias gg='git grep'
|
||||||
|
fi
|
||||||
|
[[ -n "$DEBUG" ]] && echo anyGit aliases loaded
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue