summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/gi/git-edit-index
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/gi/git-edit-index')
-rwxr-xr-xpkgs/by-name/gi/git-edit-index/git-edit-index.sh57
-rw-r--r--pkgs/by-name/gi/git-edit-index/package.nix19
-rw-r--r--pkgs/by-name/gi/git-edit-index/package.unstable.nix29
3 files changed, 57 insertions, 48 deletions
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
deleted file mode 100644
index 8ac085bf..00000000
--- a/pkgs/by-name/gi/git-edit-index/package.nix
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- sysLib,
- git,
- gnused,
-}:
-sysLib.writeShellScript {
- name = "git-edit-index";
- src = ./git-edit-index.sh;
- generateCompletions = true;
-
- # `git-edit-index` starts neovim, wich might want to shell out from
- keepPath = true;
-
- dependencies = [
- git
- gnused
- # $EDITOR
- ];
-}
diff --git a/pkgs/by-name/gi/git-edit-index/package.unstable.nix b/pkgs/by-name/gi/git-edit-index/package.unstable.nix
new file mode 100644
index 00000000..5e855b49
--- /dev/null
+++ b/pkgs/by-name/gi/git-edit-index/package.unstable.nix
@@ -0,0 +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>.
+{
+ writeShellApplication,
+ # Dependencies
+ coreutils,
+ git,
+ gnused,
+}:
+writeShellApplication {
+ name = "git-edit-index";
+ text = builtins.readFile ./git-edit-index.sh;
+
+ # `git-edit-index` starts neovim, wich might want to shell out from
+ inheritPath = true;
+
+ runtimeInputs = [
+ coreutils
+ git
+ gnused
+ ];
+}