diff options
author | xyz <gky44px1999@gmail.com> | 2021-10-24 01:05:49 -0700 |
---|---|---|
committer | xyz <gky44px1999@gmail.com> | 2021-10-24 01:05:49 -0700 |
commit | 5997d1d96d92e389ca5e4301a7974f4b535a12d5 (patch) | |
tree | 5434bcf2507cec03d771a27d728bccad3cca7419 | |
parent | 1ecd63bf0fafdd5fad56f26326d939c66953f6d8 (diff) |
refactor
-rwxr-xr-x | home/xyz/.local/bin/mvt | 6 | ||||
-rwxr-xr-x | home/xyz/.local/bin/orgext | 10 |
2 files changed, 10 insertions, 6 deletions
diff --git a/home/xyz/.local/bin/mvt b/home/xyz/.local/bin/mvt new file mode 100755 index 00000000..1701ed93 --- /dev/null +++ b/home/xyz/.local/bin/mvt @@ -0,0 +1,6 @@ +#!/bin/sh + +# emulate mv -t, for more POSIX compliant +dist="$1" +shift +mv -- "$@" "$dist" diff --git a/home/xyz/.local/bin/orgext b/home/xyz/.local/bin/orgext index de5dc695..bc0a18c5 100755 --- a/home/xyz/.local/bin/orgext +++ b/home/xyz/.local/bin/orgext @@ -1,18 +1,16 @@ #!/bin/sh -# references: -# https://stackoverflow.com/questions/1842254/how-can-i-find-all-of-the-distinct-file-extensions-in-a-folder-hierarchy - # not sure if find here need -depth, not sure if mv here need -n and -T outdir () { - find . -type f -execdir mv -nt "$PWD" -- '{}' \+ - find . -mindepth 1 -maxdepth 1 -type d -delete + find . -type f -execdir mvt "$PWD" '{}' \+ + find . -mindepth 1 -maxdepth 1 -type d -execdir rmdir -- '{}' \+ } indir () { + # https://stackoverflow.com/questions/1842254/how-can-i-find-all-of-the-distinct-file-extensions-in-a-folder-hierarchy find . -maxdepth 1 -type f | awk -F. '!a[$NF]++{print $NF}' | xargs mkdir -- - find . -mindepth 1 -maxdepth 1 -type d -execdir basename -az -- '{}' \+ | xargs -0 -I _ find . -maxdepth 1 -type f -name '*._' -execdir mv -t '_' -- '{}' \+ + find . -mindepth 1 -maxdepth 1 -type d -execdir basename -az -- '{}' \+ | xargs -0 -I _ find . -maxdepth 1 -type f -name '*._' -execdir mvt '_' '{}' \+ } case "$1" in |