Skip to content

Instantly share code, notes, and snippets.

@dabrowski-adam
Last active February 18, 2018 19:41
Show Gist options
  • Save dabrowski-adam/2bc79d96769fa6cf4ff971c8f451a029 to your computer and use it in GitHub Desktop.
Save dabrowski-adam/2bc79d96769fa6cf4ff971c8f451a029 to your computer and use it in GitHub Desktop.
Vomit — Shell Utility [expand directory (flatten top folder only)]
#!/bin/sh
# Vomit 0.1
# Copyright © 2018 Adam Dąbrowski
# https://opensource.org/licenses/MIT
#
# Usage: vomit [DIR]
# Move content of DIR outside and remove DIR.
# print help
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
printf "Vomit 0.1 — Copyright ©️ 2018 Adam Dąbrowski\n"
printf "https://opensource.org/licenses/MIT\n\n"
printf "Usage: %s [DIR]\n" $(basename $0)
printf "Move content of DIR outside and remove DIR. \n"
exit 0
fi
# abort on error
set -e
# move files out of dir
(shopt -s nullglob && mv $1/* $1/.[!.]* . && shopt -u nullglob) 2> /dev/null \
|| (>&2 echo "vomit: couldn't move content" && exit 1)
# remove empty dir
([ $(find $1 -maxdepth 0 -type d -empty) ] && rm -r $1) 2> /dev/null \
|| (>&2 echo "vomit: couldn't clean up leftover dir" && exit 2)
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment