From 9aef83d1336c8acb7fda2baa9c16a9afca5cba92 Mon Sep 17 00:00:00 2001 From: Matthias Johnson Date: Tue, 25 Mar 2025 13:28:15 -0600 Subject: [PATCH] adding ANYGIT alias functinality --- dotgit.sh | 94 +++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 76 deletions(-) diff --git a/dotgit.sh b/dotgit.sh index 7d44725..d8893c9 100644 --- a/dotgit.sh +++ b/dotgit.sh @@ -3,7 +3,7 @@ [[ ! "$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 -[[ -n "$DEBUG" ]] && echo loading dotGit aliases +[[ -n "$DEBUG" ]] && echo loading dotgit aliases [[ -z "$DOTGIT_MULTI_LIMIT" ]] && DOTGIT_MULTI_LIMIT=2 [[ -z "$DOTGIT_MULTI_ACCEPT" ]] && DOTGIT_MULTI_ACCEPT='{1}' @@ -48,16 +48,23 @@ else fi # if lazygit or gitui are avaiable, we set up a .lazygit and .gitui [[ $(command -v lazygit) ]] && - alias .lazygit='lazygit -g ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}' + alias .lazygit='lazygit -g ${DOT_FILES}/ -w ${DOT_HOME}' [[ $(command -v gitui) ]] && - alias .gitui='gitui -d ${DOT_FILES}/.dotfiles/ -w ${DOT_HOME}' + alias .gitui='gitui -d ${DOT_FILES}/ -w ${DOT_HOME}' # if fzf is installed we can have nice things # https://github.com/junegunn/fzf +read -r -d '' FZF_HEADER< to mark more than one file | 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 +# and to make general aliases availalbe, we source this file again, but set +# the aliases by removing the leading `.` and changing all instances of the +# string 'dotgit' to 'anygit' +# shellcheck source=/dev/null +# the line above makes the source below not complain +[[ "$DOTGIT_ANYGIT" == 'yes' ]] && \ + sed '/alias \.g.*DOT_FILES/d; s/\.g/g/g; s/dotgit/anygit/g' < "$0" | source /dev/stdin