diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-23 14:36:33 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-23 14:36:33 +0200 |
commit | 4308aef7cc403272be21e71676fa4c1e3deb8d88 (patch) | |
tree | bc653a15c947076fe1bfd54e84121e94c8b26916 | |
parent | feat(home/yt/mpv): Map further keys (diff) | |
download | nixos-config-4308aef7cc403272be21e71676fa4c1e3deb8d88.tar.gz nixos-config-4308aef7cc403272be21e71676fa4c1e3deb8d88.zip |
feat(pkgs/stamp): Init
-rw-r--r-- | modules/home/pkgs/default.nix | 1 | ||||
-rw-r--r-- | pkgs/by-name/st/stamp/package.nix | 19 | ||||
-rwxr-xr-x | pkgs/by-name/st/stamp/stamp.sh | 84 |
3 files changed, 104 insertions, 0 deletions
diff --git a/modules/home/pkgs/default.nix b/modules/home/pkgs/default.nix index 4121337c..ad77c5fb 100644 --- a/modules/home/pkgs/default.nix +++ b/modules/home/pkgs/default.nix @@ -196,6 +196,7 @@ with pkgs; let Programming = { GeneralTools = [ + stamp # Add a license header to a file git # the fast distributed version control system git-absorb # git commit --fixup, but automatic git-edit-index # Allows you to edit the indexed version of a file diff --git a/pkgs/by-name/st/stamp/package.nix b/pkgs/by-name/st/stamp/package.nix new file mode 100644 index 00000000..06bd5358 --- /dev/null +++ b/pkgs/by-name/st/stamp/package.nix @@ -0,0 +1,19 @@ +{ + sysLib, + findutils, + fd, + reuse, + git, +}: +sysLib.writeShellScript { + name = "stamp"; + src = ./stamp.sh; + generateCompletions = true; + keepPath = false; + dependencies = [ + findutils + fd + reuse + git + ]; +} diff --git a/pkgs/by-name/st/stamp/stamp.sh b/pkgs/by-name/st/stamp/stamp.sh new file mode 100755 index 00000000..10ede809 --- /dev/null +++ b/pkgs/by-name/st/stamp/stamp.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +help() { + cat <<EOF +A simply file copyright menagment system + +USAGE: + stamp [OPTIONS] FILE_OR_DIRECTORY + +OPTIONS: + --help | -h + Display this help and exit. + + --version | -v + Display version and copyright information and exit. + + --license | -l L + Specify a license. +ARGUMENTS: + FILE_OR_DIRECTORY := [[fd . --max-depth 3]] + Possible files to stamp. + + L := GPL-3.0-or-later|CC-BY-SA-4.0|AGPL-3.0-or-later + A possible license identifier. These above are only suggestions. +EOF +} + +reuse_run() { + root="$(git rev-parse --show-toplevel)" + + if [ -e "$root/.reuse/templates/default" ]; then + reuse annotate \ + --copyright "$(git config --get user.name) <$(git config --get user.email)>" \ + --copyright-style string-c \ + --template default \ + --license "$license" "$1" + else + reuse annotate \ + --copyright "$(git config --get user.name) <$(git config --get user.email)>" \ + --copyright-style string-c \ + --license "$license" "$1" + fi +} + +for arg in "$@"; do + case "$arg" in + "--help" | "-h") + help + exit 0 + ;; + "--version" | "-v") + version + exit 0 + ;; + esac +done + +while [ "$#" -gt 0 ]; do + case "$1" in + "--license" | "-l") + shift 1 + license="$1" + [ "$license" ] || die "No license specified. See --help for more." + shift 1 + ;; + *) + file="$1" + shift 1 + ;; + esac +done + +if [ -d "$file" ]; then + fd . "$file" --type file | while read -r path_file; do + reuse_run "$path_file" + done +else + reuse_run "$file" +fi + +# vim: ft=sh |