aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/gi
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xpkgs/by-name/gi/git-cgit/git-cgit.sh131
-rw-r--r--pkgs/by-name/gi/git-cgit/package.nix28
-rwxr-xr-xpkgs/by-name/gi/git-cleanup/git-cleanup.sh78
-rw-r--r--pkgs/by-name/gi/git-cleanup/package.nix17
-rwxr-xr-xpkgs/by-name/gi/git-cm/git-cm.sh13
-rw-r--r--pkgs/by-name/gi/git-cm/package.nix23
-rwxr-xr-xpkgs/by-name/gi/git-edit-index/git-edit-index.sh57
-rw-r--r--pkgs/by-name/gi/git-edit-index/package.nix24
8 files changed, 232 insertions, 139 deletions
diff --git a/pkgs/by-name/gi/git-cgit/git-cgit.sh b/pkgs/by-name/gi/git-cgit/git-cgit.sh
new file mode 100755
index 00000000..d24fda15
--- /dev/null
+++ b/pkgs/by-name/gi/git-cgit/git-cgit.sh
@@ -0,0 +1,131 @@
+#!/usr/bin/env sh
+
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+NAME="git-cgit"
+
+not_empty() {
+ arg="$1"
+ name="$2"
+
+ if [ "$arg" = "" ]; then
+ echo 1>&2 "flag '$name' is empty"
+ exit 2
+ fi
+}
+
+help() {
+ cat <<EOF
+Create a cgit repo to push the current repo to.
+
+USAGE:
+ $NAME [OPTIONS] --git URL..
+
+OPTIONS:
+ --help | -h
+ Display this help and exit.
+ --git URL
+ git upstream URL.
+ Should be in the form:
+ 'ssh://git@<url>/path/to/repo'
+ --desc DESC
+ Optional description (will be read from './.git/description' otherwise).
+ --defbranch
+ Optional default branch
+ --cgit-owner
+ Optional cgit owner
+EOF
+}
+
+git_url=""
+ssh_url=""
+url_path=""
+desc="$(cat "$(git rev-parse --show-toplevel)/.git/description")"
+
+cgit_owner="$(id --name -u)"
+defbranch="$(git branch --show-current)"
+
+while [ "$#" -ne 0 ]; do
+ case "$1" in
+ "--help" | "-h")
+ help
+ exit 0
+ ;;
+ "--git")
+ shift 1
+ git_url="$1"
+ ;;
+ "--desc")
+ shift 1
+ desc="$1"
+ ;;
+ "--defbranch")
+ shift 1
+ defbranch="$1"
+ ;;
+ "--cgit-owner")
+ shift 1
+ cgit_owner="$1"
+ ;;
+ esac
+ shift 1
+done
+
+# In the form git@<url>
+ssh_url="${git_url#ssh://}"
+while [ "$(dirname "$ssh_url")" != "." ]; do
+ ssh_url="$(dirname "$ssh_url")"
+done
+url_path="${git_url#ssh://"$ssh_url"}"
+url_path="${url_path#/}"
+
+not_empty "$git_url" "--git"
+not_empty "$ssh_url" "--git <indirectly>"
+not_empty "$url_path" "--git <indirectly>"
+
+not_empty "$desc" "--desc"
+not_empty "$defbranch" "--defbranch"
+not_empty "$cgit_owner" "--cgit-owner"
+
+cat <<EOF
+Initializing repo with following values:
+ --git -> '$git_url'
+ <ssh_url> -> '$ssh_url'
+ <url_path> -> '$url_path'
+
+ --desc -> '$desc'
+ --defbranch -> '$defbranch'
+ --cgit-owner -> '$cgit_owner'
+
+EOF
+
+printf "Continue [y/N]? "
+read -r continue
+if [ "$continue" != "y" ]; then
+ echo 1>&2 "Not continuing.."
+ exit 1
+fi
+
+set -x
+
+git remote remove origin
+git remote add origin "$git_url"
+
+git push --set-upstream origin "$defbranch"
+
+ssh "$ssh_url" -- perms "$url_path" + READERS @all
+ssh "$ssh_url" -- desc "$url_path" "$desc"
+
+ssh "$ssh_url" -- config "$url_path" --add cgit.defbranch "$defbranch"
+ssh "$ssh_url" -- config "$url_path" --add cgit.owner "$cgit_owner"
+
+ssh "$ssh_url" -- info
+# vim: ft=sh
diff --git a/pkgs/by-name/gi/git-cgit/package.nix b/pkgs/by-name/gi/git-cgit/package.nix
new file mode 100644
index 00000000..b64c5e84
--- /dev/null
+++ b/pkgs/by-name/gi/git-cgit/package.nix
@@ -0,0 +1,28 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+{
+ writeShellApplication,
+ # Dependencies
+ coreutils,
+ git,
+ openssh,
+}:
+writeShellApplication {
+ name = "git-cgit";
+ text = builtins.readFile ./git-cgit.sh;
+
+ inheritPath = false;
+
+ runtimeInputs = [
+ coreutils
+ git
+ openssh
+ ];
+}
diff --git a/pkgs/by-name/gi/git-cleanup/git-cleanup.sh b/pkgs/by-name/gi/git-cleanup/git-cleanup.sh
deleted file mode 100755
index f423a9d2..00000000
--- a/pkgs/by-name/gi/git-cleanup/git-cleanup.sh
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env dash
-
-# shellcheck source=/dev/null
-SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
-
-help() {
- cat <<EOF
-Automatically remove merged branches (remote and local)
-
-USAGE:
- git-cleanup [OPTIONS]
-
-OPTIONS:
- --remote | -r
- Act on remote branches
-
- --help | -h
- Display this help and exit.
-
- --version | -v
- Display version and copyright information and exit.
-EOF
-}
-
-# This should always be the correct answer.
-get_default_branch() {
- # source: https://stackoverflow.com/a/50056710
- # We assume, that 'origin' is the remote in use
- git remote show origin | sed -n '/HEAD branch/s|.*: ||p'
-}
-
-cleanup() {
- default_branch="$(get_default_branch)"
-
- merged_branches="$(git branch --merged "$default_branch" --no-contains "$default_branch" --format='%(refname:short)')"
-
- # shellcheck disable=2086
- # We expect the branches to not contain spaces and want git to deal with them
- # separately
- [ "$merged_branches" ] && git branch --delete $merged_branches
-}
-cleanup_remote() {
- default_branch="$(get_default_branch)"
-
- merged_branches="$(git branch --remotes --merged "$default_branch" --no-contains "$default_branch" --format='%(refname:short)' | sed 's|origin/||')"
-
- # shellcheck disable=2086
- # We expect the branches to not contain spaces and want git to deal with them
- # separately
- [ "$merged_branches" ] && git push --delete origin $merged_branches
-}
-
-remote=false
-for arg in "$@"; do
- case "$arg" in
- "--help" | "-h")
- help
- exit 0
- ;;
- "--version" | "-v")
- version
- exit 0
- ;;
- "--remote" | "-r")
- remote=true
- ;;
- esac
-done
-
-if [ "$remote" = "true" ]; then
- cleanup_remote
-elif [ "$remote" = "false" ]; then
- cleanup
-else
- die "BUG: 'remote' is not true or false but: '$remote'"
-fi
-
-# vim: ft=sh
diff --git a/pkgs/by-name/gi/git-cleanup/package.nix b/pkgs/by-name/gi/git-cleanup/package.nix
deleted file mode 100644
index 54b3f2bd..00000000
--- a/pkgs/by-name/gi/git-cleanup/package.nix
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- sysLib,
- git,
- gnused,
- openssh,
-}:
-sysLib.writeShellScript {
- name = "git-cleanup";
- src = ./git-cleanup.sh;
- keepPath = false;
- generateCompletions = true;
- dependencies = [
- git
- gnused
- openssh
- ];
-}
diff --git a/pkgs/by-name/gi/git-cm/git-cm.sh b/pkgs/by-name/gi/git-cm/git-cm.sh
index 2204e4d6..7ab957df 100755
--- a/pkgs/by-name/gi/git-cm/git-cm.sh
+++ b/pkgs/by-name/gi/git-cm/git-cm.sh
@@ -1,7 +1,14 @@
#!/usr/bin/env dash
-# shellcheck source=/dev/null
-SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
ROOT="$(git rev-parse --show-toplevel)"
@@ -13,6 +20,6 @@ else
fi
sed '1d' "$(git config commit.template)" >>"$ROOT/.git/COMMIT_TEMPLATE"
-git commit --template "$ROOT/.git/COMMIT_TEMPLATE" --verbose "$@"
+git commit --template "$ROOT/.git/COMMIT_TEMPLATE" "$@"
# vim: ft=sh
diff --git a/pkgs/by-name/gi/git-cm/package.nix b/pkgs/by-name/gi/git-cm/package.nix
index a9949783..f124ce90 100644
--- a/pkgs/by-name/gi/git-cm/package.nix
+++ b/pkgs/by-name/gi/git-cm/package.nix
@@ -1,13 +1,26 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
- sysLib,
+ writeShellApplication,
+ # Dependencies
git,
gnused,
}:
-sysLib.writeShellScript {
+writeShellApplication {
name = "git-cm";
- src = ./git-cm.sh;
- keepPath = true;
- dependencies = [
+ text = builtins.readFile ./git-cm.sh;
+
+ # We need access to the $EDITOR
+ inheritPath = true;
+
+ runtimeInputs = [
git
gnused
];
diff --git a/pkgs/by-name/gi/git-edit-index/git-edit-index.sh b/pkgs/by-name/gi/git-edit-index/git-edit-index.sh
index e73dc53c..a9434381 100755
--- a/pkgs/by-name/gi/git-edit-index/git-edit-index.sh
+++ b/pkgs/by-name/gi/git-edit-index/git-edit-index.sh
@@ -1,19 +1,20 @@
#!/usr/bin/env dash
-# shellcheck source=/dev/null
-SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
-# needed for help() and version
-# shellcheck disable=2034
-AUTHORS="Soispha"
-# shellcheck disable=2034
-YEARS="2024"
-# shellcheck disable=2034
-VERSION="1.0.0"
+NAME="git-edit-index"
-# NAME is from the wrapper
-# shellcheck disable=SC2269
-NAME="$NAME"
+warn() {
+ echo "WARNING: $1"
+}
help() {
cat <<EOF
@@ -55,37 +56,35 @@ materialize_file() {
}
edit() {
- files_to_add="$(mktmp)"
- realpath --relative-to=. "$@" >"$files_to_add"
+ files_to_add="$(mktemp -t git_edit_index_XXXXX)"
+ cleanup() {
+ rm "$files_to_add"
+ }
+ trap cleanup EXIT
- index_files="$(mktmp)"
- git diff --name-only --cached --diff-filter=AM >"$index_files"
+ realpath --relative-to=. "$@" >"$files_to_add"
- while read -r file; do
- if grep -q "$file" "$files_to_add"; then
- sed -i "s|$file||" "$files_to_add"
- materialize_file "$file"
+ git diff --name-only --cached --diff-filter=AM | while read -r index_file; do
+ if grep -q "$index_file" "$files_to_add"; then
+ sed -i "s|$index_file||" "$files_to_add"
+ materialize_file "$index_file"
fi
- done <"$index_files"
+ done
- files_to_check="$(mktmp)"
- clean "$files_to_add" >"$files_to_check"
- if [ "$(wc -l <"$files_to_check")" -gt 0 ]; then
- warn "Could not edit every file:"
+ unedided_files="$(sed '/^\s*$/d' "$files_to_add" | wc -l)"
+ if [ "$unedided_files" -gt 0 ]; then
+ warn "Failed to edit $unedided_files file(s):"
cat "$files_to_add"
fi
}
+end_of_cli_options=false
for arg in "$@"; do
case "$arg" in
"--help" | "-h")
help
exit 0
;;
- "--version" | "-v")
- version
- exit 0
- ;;
"--")
end_of_cli_options=true
;;
diff --git a/pkgs/by-name/gi/git-edit-index/package.nix b/pkgs/by-name/gi/git-edit-index/package.nix
index 8ac085bf..5e855b49 100644
--- a/pkgs/by-name/gi/git-edit-index/package.nix
+++ b/pkgs/by-name/gi/git-edit-index/package.nix
@@ -1,19 +1,29 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
- sysLib,
+ writeShellApplication,
+ # Dependencies
+ coreutils,
git,
gnused,
}:
-sysLib.writeShellScript {
+writeShellApplication {
name = "git-edit-index";
- src = ./git-edit-index.sh;
- generateCompletions = true;
+ text = builtins.readFile ./git-edit-index.sh;
# `git-edit-index` starts neovim, wich might want to shell out from
- keepPath = true;
+ inheritPath = true;
- dependencies = [
+ runtimeInputs = [
+ coreutils
git
gnused
- # $EDITOR
];
}