commit bc191a9e48d8df825e607bbb112928585c47dd7d
parent 8906028663f2b1f3e87aadfbcd2a3e7efd8d486f
Author: Robert Russell <robert@rr3.xyz>
Date: Sun, 26 Jul 2026 20:40:46 -0700
Allow single-argument link and copy
Diffstat:
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/README b/README
@@ -49,14 +49,14 @@ EXAMPLE
# msg_fatal "This is an error (fatal)"
# Link files/directories:
- link foobar/foo.txt foo.txt
+ link foo.txt
link a-link a
for f in b/*; do
link b-links/"$(basename "$f")" "$f"
done
# Copy files/directories:
- copy foobar/bar.txt bar.txt
+ copy bar.txt
copy a-copy a
for f in b/*; do
copy b-copies/"$(basename "$f")" "$f"
@@ -67,12 +67,12 @@ EXAMPLE
[example-pkg] INFO: This is information
[example-pkg] WARNING: This is a warning
[example-pkg] ERROR: This is an error (not fatal)
- [example-pkg] LINK CREATE: /<omitted>/example-root/foobar/foo.txt --> foo.txt
+ [example-pkg] LINK CREATE: /<omitted>/example-root/foo.txt --> foo.txt
[example-pkg] LINK CREATE: /<omitted>/example-root/a-link --> a
[example-pkg] LINK CREATE: /<omitted>/example-root/b-links/0.txt --> b/0.txt
[example-pkg] LINK CREATE: /<omitted>/example-root/b-links/1.txt --> b/1.txt
[example-pkg] LINK CREATE: /<omitted>/example-root/b-links/2.txt --> b/2.txt
- [example-pkg] COPY CREATE: /<omitted>/example-root/foobar/bar.txt <-- bar.txt
+ [example-pkg] COPY CREATE: /<omitted>/example-root/bar.txt <-- bar.txt
[example-pkg] COPY CREATE: /<omitted>/example-root/a-copy <-- a
[example-pkg] COPY CREATE: /<omitted>/example-root/b-copies/0.txt <-- b/0.txt
[example-pkg] COPY CREATE: /<omitted>/example-root/b-copies/1.txt <-- b/1.txt
@@ -93,21 +93,20 @@ EXAMPLE
│ ├── 0.txt -> /<omitted>/example-pkg/b/0.txt
│ ├── 1.txt -> /<omitted>/example-pkg/b/1.txt
│ └── 2.txt -> /<omitted>/example-pkg/b/2.txt
- └── foobar
- ├── bar.txt
- └── foo.txt -> /<omitted>/example-pkg/foo.txt
+ ├── bar.txt
+ └── foo.txt -> /<omitted>/example-pkg/foo.txt
$ graft example-root example-pkg # Idempotent
[example-pkg] NOTE: This is an important note (e.g., make sure you manually do this thing)
[example-pkg] INFO: This is information
[example-pkg] WARNING: This is a warning
[example-pkg] ERROR: This is an error (not fatal)
- [example-pkg] LINK OK: /<omitted>/example-root/foobar/foo.txt --> foo.txt
+ [example-pkg] LINK OK: /<omitted>/example-root/foo.txt --> foo.txt
[example-pkg] LINK OK: /<omitted>/example-root/a-link --> a
[example-pkg] LINK OK: /<omitted>/example-root/b-links/0.txt --> b/0.txt
[example-pkg] LINK OK: /<omitted>/example-root/b-links/1.txt --> b/1.txt
[example-pkg] LINK OK: /<omitted>/example-root/b-links/2.txt --> b/2.txt
- [example-pkg] COPY OK: /<omitted>/example-root/foobar/bar.txt <-- bar.txt
+ [example-pkg] COPY OK: /<omitted>/example-root/bar.txt <-- bar.txt
[example-pkg] COPY OK: /<omitted>/example-root/a-copy <-- a
[example-pkg] COPY OK: /<omitted>/example-root/b-copies/0.txt <-- b/0.txt
[example-pkg] COPY OK: /<omitted>/example-root/b-copies/1.txt <-- b/1.txt
diff --git a/example-pkg/.graft.sh b/example-pkg/.graft.sh
@@ -6,14 +6,14 @@ msg_error "This is an error (not fatal)"
# msg_fatal "This is an error (fatal)"
# Link files/directories:
-link foobar/foo.txt foo.txt
+link foo.txt
link a-link a
for f in b/*; do
link b-links/"$(basename "$f")" "$f"
done
# Copy files/directories:
-copy foobar/bar.txt bar.txt
+copy bar.txt
copy a-copy a
for f in b/*; do
copy b-copies/"$(basename "$f")" "$f"
diff --git a/graft b/graft
@@ -92,9 +92,9 @@ msg_bad_package() {
}
link() {
- [ $# -eq 2 ] || msg_bad_package "invalid link" "Usage: link DST SRC"
+ [ $# -eq 2 ] || [ $# -eq 1 ] || msg_bad_package "invalid link" "Usage: link DST_PATH SRC_PATH | link PATH"
local rel_dst; rel_dst="$1"
- local rel_src; rel_src="$2"
+ local rel_src; rel_src="${2:-$1}"
local abs_dst; abs_dst="$ROOT/$rel_dst"
local abs_src; abs_src="$PKG/$rel_src"
@@ -142,9 +142,9 @@ link() {
}
copy() {
- [ $# -eq 2 ] || msg_bad_package "invalid copy" "Usage: copy DST SRC"
+ [ $# -eq 2 ] || [ $# -eq 1 ] || msg_bad_package "invalid copy" "Usage: copy DST_PATH SRC_PATH | copy PATH"
local rel_dst; rel_dst="$1"
- local rel_src; rel_src="$2"
+ local rel_src; rel_src="${2:-$1}"
local abs_dst; abs_dst="$ROOT/$rel_dst"
local abs_src; abs_src="$PKG/$rel_src"