adding DOTGIT_OPEN_FMT and other re-imaginations
This commit is contained in:
parent
2300bd4549
commit
d7cc406677
2 changed files with 20 additions and 10 deletions
|
|
@ -58,7 +58,7 @@ The real daily winners for me are the "edit" (`.ge`) and "grep" (`.gg`) aliases.
|
|||
| .gd | `.git diff` | |
|
||||
| .gds | `.git diff --stat` | |
|
||||
| .ge | calls the `_dotgit_ge` helper function | the dotGit edit feature [^fzf] |
|
||||
| .gg | calls the `_dotgit_gg` helper function (falls back to `.git grep` without fzf) | grep your dotfiles; line-jumping requires customizing `DOTGIT_MULTI_ACCEPT` [^line] |
|
||||
| .gg | calls the `_dotgit_gg` helper function (falls back to `.git grep` without fzf) | grep your dotfiles and open at the matched line [^line] |
|
||||
| .gss | `.git status --short` | |
|
||||
| .glo | `.git log --oneline --decorate` | |
|
||||
| .glg | `.git log --stat` | |
|
||||
|
|
@ -84,7 +84,7 @@ The real daily winners for me are the "edit" (`.ge`) and "grep" (`.gg`) aliases.
|
|||
| .gclone | `git clone --bare "${DOT_ORIGIN}" "${DOT_REPO}"; .git config --local status.showUntrackedFiles no` | [^untracked] |
|
||||
| .ginit | `git init --bare "${DOT_REPO}"; .git config --local status.showUntrackedFiles no` | |
|
||||
|
||||
[^line]: Set `DOTGIT_MULTI_ACCEPT` to the format your editor expects, e.g. `+{2} {1}` for vim/neovim or `{1}:{2}` for editors that accept `file:line`. Works with vi, emacs, nano, micro, and any editor that accepts a line number argument.
|
||||
[^line]: Opens the editor with `+line file` arguments. Works with vi, emacs, nano, micro, and any editor that accepts a line number via `+N`.
|
||||
[^untracked]: Also set git's `status.showUntrackedFiles` to `no`. This prevents every file in `$DOT_HOME` from showing as "untracked" by git.
|
||||
[^fzf]: requires [FZF](https://github.com/junegunn/fzf)
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ The real daily winners for me are the "edit" (`.ge`) and "grep" (`.gg`) aliases.
|
|||
| `DOT_ORIGIN` | *(unset)* | remote URL; enables `.gp`, `.gl`, and `.gclone` |
|
||||
| `DOTGIT_PREVIEW` | `bat -p --color=always` | fzf preview command |
|
||||
| `DOTGIT_MULTI_LIMIT` | `5` | max files selectable at once in `.ge` and `.gg` |
|
||||
| `DOTGIT_MULTI_ACCEPT` | `{1}` | fzf field spec accepted on selection (e.g. `{1}:{2}` for file:line) |
|
||||
| `DOTGIT_OPEN_FMT` | `split` | how `.gg` passes file+line to the editor; `split` uses `+line file` (works with most editors); set to `+e {file}\|{line}` for vim/nvim multi-file line jumping |
|
||||
| `DOTGIT_ANYGIT` | *(unset)* | set to `yes` to also load unprefixed `g*` aliases for any git repo |
|
||||
| `DEBUG` | *(unset)* | set to any value to print load/unload messages |
|
||||
|
||||
|
|
|
|||
24
dotgit.sh
24
dotgit.sh
|
|
@ -6,8 +6,8 @@
|
|||
[[ -n "$DEBUG" ]] && echo loading dotgit aliases
|
||||
|
||||
[[ -z "$DOTGIT_MULTI_LIMIT" ]] && DOTGIT_MULTI_LIMIT=5
|
||||
[[ -z "$DOTGIT_MULTI_ACCEPT" ]] && DOTGIT_MULTI_ACCEPT='{1}'
|
||||
[[ -z "$DOTGIT_PREVIEW" ]] && DOTGIT_PREVIEW='bat -p --color=always'
|
||||
[[ -z "$DOTGIT_OPEN_FMT" ]] && DOTGIT_OPEN_FMT='split' # or e.g. '+e {file}|{line}' for nvim
|
||||
|
||||
# the master alias
|
||||
alias .git='git --git-dir=${DOT_REPO} --work-tree=${DOT_HOME}'
|
||||
|
|
@ -84,16 +84,26 @@ EOF
|
|||
alias .ge='_dotgit_ge'
|
||||
|
||||
_dotgit_gg() {
|
||||
local gitdir result
|
||||
local -a files
|
||||
local gitdir result clean fname lnum
|
||||
local -a editor_args
|
||||
gitdir=$(.git rev-parse --show-toplevel)
|
||||
result=$(cd "$gitdir" && .git grep --full-name --color=always -n "$@" |
|
||||
fzf "${fzf_opts[@]}" -d ":" \
|
||||
--preview "$DOTGIT_PREVIEW -H{2} {1}" \
|
||||
--accept-nth "$DOTGIT_MULTI_ACCEPT")
|
||||
--preview "$DOTGIT_PREVIEW -H{2} {1}")
|
||||
[[ -z "$result" ]] && return
|
||||
while IFS= read -r line; do files+=("$line"); done <<< "$result"
|
||||
(cd "$gitdir" && "$EDITOR" "${files[@]}")
|
||||
while IFS= read -r line; do
|
||||
clean=$(printf '%s' "$line" | sed 's/\x1b\[[0-9;]*[A-Za-z]//g')
|
||||
[[ -z "$clean" ]] && continue
|
||||
fname="${clean%%:*}"
|
||||
lnum="${clean#*:}"; lnum="${lnum%%:*}"
|
||||
if [[ "$DOTGIT_OPEN_FMT" == 'split' ]]; then
|
||||
editor_args+=("+$lnum" "$fname")
|
||||
else
|
||||
local arg="${DOTGIT_OPEN_FMT//\{file\}/$fname}"
|
||||
editor_args+=("${arg//\{line\}/$lnum}")
|
||||
fi
|
||||
done <<< "$result"
|
||||
[[ ${#editor_args[@]} -gt 0 ]] && (cd "$gitdir" && "$EDITOR" "${editor_args[@]}")
|
||||
}
|
||||
alias .gg='_dotgit_gg'
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue