vcs: Rename from git to support multiple vcs

This commit is contained in:
Marty Oehme 2024-09-18 17:25:12 +02:00
parent 1cce1a9a38
commit 4aec6b9ba3
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
7 changed files with 4 additions and 4 deletions

77
vcs/.config/git/config Normal file
View file

@ -0,0 +1,77 @@
[user]
email = marty.oehme@gmail.com
name = Marty Oehme
signingkey = 73BA40D5AFAF49C9
[init]
defaultBranch = main
[core]
pager = git delta
[pager]
difftool = true
[interactive]
diffFilter = git delta --color-only
[merge]
conflictstyle = diff3
[delta]
navigate = true
line-numbers = true
syntax-theme = base16
[sendemail]
smtpserver = "/usr/bin/msmtp"
annotate = yes
[alias]
ignore = "!gitignore -f"
last = "diff HEAD~ HEAD"
pushall = "!git remote | xargs -I R git push R" # push to all connected remotes
fetchall = "!git remote | xargs -I R git fetch R" # fetch from all connected remotes
diffword = "!git diff --word-diff=color --word-diff-regex='[0-9A-Za-z_]+'" # word-wise diff, good for prose
diffsyn = "!git difftool --tool difftastic" # add syntax-driven diff using treesitter
diffside = "!DELTA_FEATURES='+side-by-side' git diff" # add side-by-side diffing
delta = "![ $TERM_DARK = false ] && delta --light || delta" # Take care that we always display right color scheme
[commit]
gpgsign = true # sign commits as me
verbose = true # Always show diff when preparing commit message
[fetch]
prune = true # remove references to non-existent remote branches
[pull]
rebase = true # always rebase on pulling, obviates merge commits
[diff]
colorMoved = zebra # also color stuff that has simply been moved, in a classy zebra-color
[difftool]
prompt = false
[difftool "difftastic"]
cmd = difft "$LOCAL" "$REMOTE"
[color "diff"]
meta = "9"
frag = "magenta bold"
commit = "yellow bold"
old = "red bold"
new = "green bold"
whitespace = "red reverse"
[color "diff-highlight"]
oldNormal = "red bold"
oldHighlight = "red bold 52"
newNormal = "green bold"
newHighlight = "green bold 22"
[rebase]
autostash = true
autoSquash = true
# Make use of git urls for git{lab,hub}, but only do so for pushing
# since pulling will create troubles with some applications
[url "git@github.com:"]
pushInsteadOf = "https://github.com/"
pushInsteadOf = "http://github.com/"
pushInsteadOf = "gh:"
[url "git@gitlab.com:"]
pushInsteadOf = "https://gitlab.com"
pushInsteadOf = "http://gitlab.com"
[url "git@git.martyoeh.me:"]
pushInsteadOf = "https://git.martyoeh.me"
pushInsteadOf = "http://git.martyoeh.me"
pushInsteadOf = "git@martyoeh.me"
pullInsteadOf = "git@martyoeh.me"
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true

74
vcs/.config/git/ignore Normal file
View file

@ -0,0 +1,74 @@
# Created by https://www.gitignore.io/api/vim,linux,zsh
# Edit at https://www.gitignore.io/?templates=vim,linux,zsh
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# Coc configuration directory
.vim
### Zsh ###
# Zsh compiled script + zrecompile backup
*.zwc
*.zwc.old
# Zsh completion-optimization dumpfile
*zcompdump*
# Zsh zcalc history
.zcalc_history
# A popular plugin manager's files
._zplugin
.zplugin_lstupd
# zdharma/zshelldoc tool's files
zsdoc/data
# robbyrussell/oh-my-zsh/plugins/per-directory-history plugin's files
# (when set-up to store the history in the local directory)
.directory_history
# MichaelAquilina/zsh-autoswitch-virtualenv plugin's files
# (for Zsh plugins using Python)
.venv
# Zunit tests' output
/tests/_output/*
!/tests/_output/.gitkeep
# End of https://www.gitignore.io/api/vim,linux,zsh

View file

@ -0,0 +1,118 @@
#!/usr/bin/env sh
if ! exist git; then
return 1
fi
# print git version output and get raw version number by stripping prefix
git_version=$(git --version 2>/dev/null)
git_version="${git_version##git version }"
alias g='git'
if exist lazygit; then
alias lg="lazygit"
fi
alias ga='git add'
alias gaa='git add --all'
alias gai='git add -i'
alias gc='git commit -v'
alias gc!='git commit -v --amend'
alias gcn!='git commit -v --no-edit --amend'
if version_at_least 2.23 "$git_version"; then
alias gcm='git switch master 2>/dev/null || git switch main'
alias gcd='git switch develop 2>/dev/null || git switch staging'
gcb() {
git switch "$@" 2>/dev/null || git switch -c "$@"
}
else
alias gcm='git checkout master 2>/dev/null || git checkout main'
alias gcd='git checkout develop'
alias gcb='git checkout -b'
fi
alias gco='git checkout'
alias gi='git ignore'
# normal diff
alias gd='git diff'
alias gds='git diff --staged'
# word-based diff (with custom word regex)
alias gdw='git diffword'
alias gdws='git diffword --staged'
# side-by-side diff
alias gdd='git diffside'
alias gdds='git diffside --staged'
# syntax-based diff
if exist difft; then
alias gdy='git diffsyn'
alias gdys='git diffsyn --staged'
fi
alias gdd='git diffside'
alias gdds='git diffside --staged'
# show last committed content
alias gdl='git last'
# show quick log overview
alias glg='git log --oneline --decorate --graph'
alias glga='git log --oneline --decorate --graph --remotes --all'
# show quick log overview - with dates
alias glgd="git log --graph --pretty=format:'%C(auto)%h%Creset %C(cyan)%ar%Creset%C(auto)%d%Creset %s'"
alias glgad="git log --graph --remotes --all --pretty=format:'%C(auto)%h%Creset %C(cyan)%ar%Creset%C(auto)%d%Creset %s'"
# show detailed log overview
alias glog='git log --stat'
# show detailed log overview with contents
alias gloog='git log --stat -p'
alias gf='git fetch'
alias gfa='git fetchall'
alias gl='git pull'
alias gpn='git push --dry-run'
alias gp='git push'
alias gpf!='git push --force'
alias gpm='git pushmerge'
alias gpa='git pushall'
alias grv='git remote -v'
alias grs='git restore --staged'
alias grs!='git restore'
alias grb='git rebase'
alias grbi='git rebase -i'
alias grbc='git rebase --continue'
alias grbm='git rebase master || git rebase main'
alias gst='git status'
alias gstp='git stash pop'
alias gstl='git stash list'
alias gstL='git stash list --stat'
if version_at_least 2.13 "$git_version"; then
alias gsta='git stash push'
else
alias gsta='git stash save'
fi
if exist git-bug; then
gb() {
if [ "$#" -eq 1 ]; then
git bug show "$1"
else
git bug ls "$@"
fi
}
alias gbt='git bug termui'
alias gba='git bug add'
alias gbm='git bug comment add'
alias gbc='git bug status close'
alias gbp='git bug push'
alias gbl='git bug pull'
fi
unset -v git_version

View file

@ -0,0 +1,15 @@
#compdef _gitignore gitignore
#
# Requires gitignore script in path
#
# Enables completion for zsh of gitignore function.
_gitignore_get_command_list() {
curl -sL https://www.gitignore.io/api/list | tr ',' '\n'
}
_gitignore() {
_arguments \
'1::flags:((-f\:"Save output to .gitignore file in current directory"))' \
":listopts: _values -s, 'modules' $(_gitignore_get_command_list)"
}

79
vcs/.local/bin/gitignore Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env sh
#
# Adds call to gitignore.sh api to automatically
# generate a .gitignore file with the individual arguments
# passed in included as ignored packages.
#
# Pass in -f as first argument to save the file as .gitignore
# in the current directory in addition to printing to stdout.
# Will *overwrite* any previous .gitignore file that exists in
# current directory.
#
# When called without arguments will load all possible arguments
# as fzf searchable list if fzf is in path.
#
# Enables completion for zsh in git/.config/shell/zshrc.d/_gitignore_completions.zsh
__get_items() {
if [ "$1" = "" ]; then
echo "gitignore definition generation needs at least one argument."
exit 1
fi
if [ "$savetofile" = "true" ]; then
__call_url "$@" >>.gitignore
else
__call_url "$@"
fi
}
__call_url() {
IFS=","
curl -L -s https://www.gitignore.io/api/"$*"
}
gitignore() {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit 0
# just print to stdout or save locally?
elif [ "$1" = "-f" ] || [ "$1" = "--file" ]; then
savetofile=true
shift
fi
IFS=","
if [ "$#" -eq 0 ]; then
if type fzf >/dev/null 2>&1; then
for item in $(__get_items list); do
echo "$item"
done | fzf --multi --ansi | paste -s -d "," - |
{ read -r result && __get_items "$result"; }
else
usage
fi
else
__get_items "$@"
fi
}
usage() {
printf "%s\n" \
"" \
" gitignore Quickly generate a gitignore definition." \
"" \
" Usage: gitignore [-h] [vim] [linux] [javascript] [...]" \
"" \
" Arguments:" \
"" \
" -h | --help Print out this help." \
"" \
" -f | --file Append gitignore definition to .gitignore file" \
" instead of stdout." \
"" \
" Arguments will be passed along to gitignore.io for parsing and " \
" gitignore definition generation. By default only prints to stdout." \
"" \
""
}
gitignore "$@"

44
vcs/README.md Normal file
View file

@ -0,0 +1,44 @@
# Git module
[git](https://git-scm.com/) - a distributed version control system
## What's in this module
[[_TOC_]]
## Global git settings
This is probably the first thing that needs to be customized, since it points to a different identity for each git user.
I sign all my commits by default, so take out the corresponding lines if you don't, or exchange it with your gpg key.
Git will rewrite any remotes using http(s) to use the ssh notation for pushes to github and gitlab so that, even if you set up the repository using an https url you can utilize your usual ssh key for pushing.
Finally, the configuration makes use of a custom pager called `dsf` which is also contained in this module.
It tries to use `diff-so-fancy` if that is installed on the path, otherwise uses git's internal diff prettifier.
If nothing exists it falls back to the standard output.
You can move between changed files in diffs with n/N.
Otherwise, the git config is prepared to handle lfs repositories, and it has an assortment of smaller quality of life changes, though nothing major.
## Basic git command aliases
This module contains a heap of aliases to every-day git commands.
Most of them follow a two-to-three letter combination of things to do which corresponds to the mnemonic of the longer git command.
As such, they are mostly similar to those found in the Oh My Zsh [git plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git).
Examples of some common aliases are `alias ga=git add`, `alias gst=git status`, `alias gp=git push`, `alias gl=git pull`.
Two aliases might be of note:
`gi` allows quickly generating a gitignore file for the current directory, using the included `gitignore` script.
And `gll` quickly pulls up the contents of the last commit. (`ll` since `gl` already pulls from the remote)
## Gitignore generation script
Adds a `gitignore` script which pulls relevant .gitignore lines from [gitignore.io](https://www.gitignore.io) and sends them to standard out, or creates a .gitignore file in the current directory.
[![asciicast](https://asciinema.org/a/298616.svg)](https://asciinema.org/a/298616)
To show usage of the script run `gitignore -h`. It is fully equipped with zsh auto completions, which will pull a list of all available ignore modules from the website to complete with.
It can alternatively be run through git itself by invoking `git ignore`, which will always generate a .gitignore file in the current directory.
When fzf is installed invoke the script without any arguments to generate a fzf-searchable list of git definitions to create. Select multiple definitions with <tab>.