commit 0918e0204f1d4a6f8d6ba92cd43a0ad1925ea623 parent 247a8f8e29482a17fc3a59eb361646a8aadce22b Author: Jacob R. Edwards <n/a> Date: Fri, 4 Feb 2022 23:23:53 -0800 Add scripts to help organize directory structures Bump bumps files into a directory and drop drops files to their directory's parent. Diffstat:
| A | local/bin/bin/bump | | | 20 | ++++++++++++++++++++ |
| A | local/bin/bin/drop | | | 15 | +++++++++++++++ |
2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/local/bin/bin/bump b/local/bin/bin/bump @@ -0,0 +1,20 @@ +#!/bin/sh -e +# Copyright 2022 Jacob R. Edwards +# Bump files up to the specified directory. + +dir="${1:?Directory not specified}" +shift + +if test -e "$dir" -a '!' -d "$dir" +then + echo "$dir: File exists" 1>&2 + exit 1 +fi + +if test $# -eq 0 +then + set -- * +fi +tmp="$(mktemp -d drop-XXXXXXXXXX)" +mv "$@" "$tmp" +mv "$tmp" "$dir" diff --git a/local/bin/bin/drop b/local/bin/bin/drop @@ -0,0 +1,15 @@ +#!/bin/sh -e +# Copyright 2022 Jacob R. Edwards +# Drop files to their parent directory. + +list() find "$@" -maxdepth 1 -mindepth 1 +drop() awk -F / -v OFS=/ '{ $(NF - 1) = ""; print }' "$@" + +if list "$1" | drop | stest -e +then + echo 'File also exists in parent directory' 1>&2 + exit 1 +fi + +mv "$1"/* . +rmdir "$1"