From fc529fe9b9abdc88bb540eb8a919b2f43ff1cd1c Mon Sep 17 00:00:00 2001 From: izumin5210 Date: Sun, 17 Mar 2024 10:52:02 +0900 Subject: [PATCH] configure git with home-manager --- config/.config/gh/config.yml | 29 +++ .../{.gitconfig => .config/git/config.base} | 15 +- config/.config/git/ignore | 204 ++++++++++++++++++ config/.git_template/hooks/pre-commit | 20 -- config/.gitignore_global | 86 -------- config/bin/git-pr | 18 -- home.nix | 32 +++ 7 files changed, 267 insertions(+), 137 deletions(-) create mode 100644 config/.config/gh/config.yml rename config/{.gitconfig => .config/git/config.base} (83%) create mode 100644 config/.config/git/ignore delete mode 100755 config/.git_template/hooks/pre-commit delete mode 100644 config/.gitignore_global delete mode 100755 config/bin/git-pr diff --git a/config/.config/gh/config.yml b/config/.config/gh/config.yml new file mode 100644 index 00000000..2eb3718a --- /dev/null +++ b/config/.config/gh/config.yml @@ -0,0 +1,29 @@ +# What protocol to use when performing git operations. Supported values: ssh, https +git_protocol: https +# What editor gh should run when creating issues, pull requests, etc. If blank, will refer to environment. +editor: +# When to interactively prompt. This is a global config that cannot be overridden by hostname. Supported values: enabled, disabled +prompt: enabled +# A pager program to send command output to, e.g. "less". Set the value to "cat" to disable the pager. +pager: +# Aliases allow you to create nicknames for gh commands +aliases: + co: pr checkout + sync: '!gh pr create --web' + default-branch: repo view --json defaultBranchRef --jq .defaultBranchRef.name + home: '!ref=$(gh default-branch); git switch $ref && git fetch --all && git pull origin $ref && gh poi' + pr-report: |- + api graphql -f query="query { + search(first: 100, type: ISSUE, query: \"author:@me org:LayerXcom is:pr merged:$1 sort:updated-asc\") { + nodes { ... on PullRequest { title, url, repository { name }, state, mergedAt } } + } + }" --jq " + .data.search.nodes | + map({ title: .title, url: .url, repo: .repository.name, state: .state, mergedAt: .mergedAt }) | + map(select(.state \!= \"CLOSED\")) | + group_by(.repo)[] | + \"* \\(.[0].repo)\\n\" + (map(\" * \\(if .state == \"MERGED\" then \"✅\" else \"⏩\" end) [\\(.title)](\\(.url))\") | join(\"\\n\"))" +# The path to a unix socket through which send HTTP connections. If blank, HTTP traffic will be handled by net/http.DefaultTransport. +http_unix_socket: +# What web browser gh should use when opening URLs. If blank, will refer to environment. +browser: diff --git a/config/.gitconfig b/config/.config/git/config.base similarity index 83% rename from config/.gitconfig rename to config/.config/git/config.base index 100e8123..19684cea 100644 --- a/config/.gitconfig +++ b/config/.config/git/config.base @@ -1,17 +1,13 @@ -[include] - path = ~/.gitconfig.local [user] name = izumin5210 email = m@izum.in [core] autocrlf = input editor = $EDITOR - excludesfile = ~/.gitignore_global [color] ui = true [github] user = izumin5210 - privatekey = /Users/izumin/.ssh/id_rsa.github [alias] co = checkout cb = checkout -b @@ -24,6 +20,7 @@ fetch-default-branch = "!f() { git ls-remote --symref $(git remote get-url origin) HEAD | grep 'refs/heads' | awk '$0=$2' | sed 's/refs\\/heads\\///'; }; f" refresh-default-branch= "!f() { git set-branch-cache default $(git fetch-default-branch); }; f" default-branch = "!f() { git get-branch-cache default || (git refresh-default-branch; git get-branch-cache default); }; f" + pr = "gh pr create --web" [push] default = current [filter "lfs"] @@ -43,19 +40,11 @@ algorithm = "histogram" indentHeuristic = true tool = difftastic -[pager] - log = diff-highlight | less - show = diff-highlight | less - diff = diff-highlight | less -[interactive] - diffFilter = diff-highlight [difftool] prompt = false [difftool "difftastic"] cmd = difft "$LOCAL" "$REMOTE" -[credential] - helper = $GIT_CREDENTIAL_HELPER [init] defaultBranch = main [url "https://github.com/"] - insteadOf = git@github.com: + insteadOf = git@github.com: diff --git a/config/.config/git/ignore b/config/.config/git/ignore new file mode 100644 index 00000000..9090a5b7 --- /dev/null +++ b/config/.config/git/ignore @@ -0,0 +1,204 @@ +# Created by https://www.toptal.com/developers/gitignore/api/intellij,linux,macos,vim,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,linux,macos,vim,visualstudiocode + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### 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* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.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~ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/intellij,linux,macos,vim,visualstudiocode diff --git a/config/.git_template/hooks/pre-commit b/config/.git_template/hooks/pre-commit deleted file mode 100755 index 09550e7e..00000000 --- a/config/.git_template/hooks/pre-commit +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -# WIP commit detection -# -# ref: http://qiita.com/takose/items/beed51b56aeec396e30e - -isLastCommitWIP() { - return `git log -1 --oneline --pretty=format:'%s' | grep -q -e '^\[WIP\]'` -} - -doesCurrentCommitAmmend() { - last_commit=`git log -1 --date=raw --pretty=format:"%ad"` - current_commit=$GIT_AUTHOR_DATE - return `echo "$current_commit" | grep -q -v "$last_commit"` -} - -if isLastCommitWIP && doesCurrentCommitAmmend; then - echo "last commit is wip commit!!" - exit 1 -fi diff --git a/config/.gitignore_global b/config/.gitignore_global deleted file mode 100644 index da03e051..00000000 --- a/config/.gitignore_global +++ /dev/null @@ -1,86 +0,0 @@ -# Created by https://www.gitignore.io/api/vim,sublimetext,osx,linux - -### Vim ### -[._]*.s[a-w][a-z] -[._]s[a-w][a-z] -*.un~ -Session.vim -.netrwhist -*~ - - -### SublimeText ### -# cache files for sublime text -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache - -# workspace files are user-specific -*.sublime-workspace - -# project files should be checked into the repository, unless a significant -# proportion of contributors will probably not be using SublimeText -# *.sublime-project - -# sftp configuration file -sftp-config.json - - -### OSX ### -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - - -### Linux ### -*~ - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - - -### direnv ### -.envrc - - -### vscode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - - -### ruby ### -vendor/bundle - -### misc ### -.env -.env.local -.env.*.local -telepresence.log diff --git a/config/bin/git-pr b/config/bin/git-pr deleted file mode 100755 index f37168f8..00000000 --- a/config/bin/git-pr +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# -# - -set -euo pipefail - -current=$(git symbolic-ref --short HEAD) -base=$(echo $current | sed -e 's/\+[^\+]*$//') - -if [ "$base" = "$current" ]; then - base="$(git default-branch)" -fi - -gh pr create --web --base $base --head $current --body "## Why - -## What - -" diff --git a/home.nix b/home.nix index fae2f02f..ffa99309 100644 --- a/home.nix +++ b/home.nix @@ -23,6 +23,11 @@ # pkgs.hello # pkgs.go + # git + pkgs.git-secrets + pkgs.gh + pkgs.difftastic + # go pkgs.gopls pkgs.delve @@ -67,6 +72,14 @@ # # symlink to the Nix store copy. # ".screenrc".source = dotfiles/screenrc; + "bin/".source = config/bin; + + # git + ".config/git/config.base".source = config/.config/git/config.base; + ".config/git/ignore".source = config/.config/git/ignore; + # gh + ".config/gh/config.yml".source = config/.config/gh/config.yml; + # # You can also set the file content immediately. # ".gradle/gradle.properties".text = '' # org.gradle.console=verbose @@ -93,6 +106,25 @@ # EDITOR = "emacs"; }; + programs= { + git = { + enable = true; + extraConfig = { + include = { + path = "${config.home.homeDirectory}/.config/git/config.base"; + }; + pager = { + log = "${pkgs.git}/share/git/contrib/diff-highlight/diff-highlight | less"; + show = "${pkgs.git}/share/git/contrib/diff-highlight/diff-highlight | less"; + diff = "${pkgs.git}/share/git/contrib/diff-highlight/diff-highlight | less"; + }; + interactive = { + diffFilter = "${pkgs.git}/share/git/contrib/diff-highlight/diff-highlight"; + }; + }; + }; + }; + # Let Home Manager install and manage itself. programs.home-manager.enable = true; }