flip writing when in scripts

This commit is contained in:
2019-10-20 10:29:49 +03:00
parent c1b4ee8a23
commit 232e99fee6
4 changed files with 21 additions and 15 deletions

View File

@@ -72,6 +72,8 @@ _simple_list() {
}
_write() {
# stdin is open
[ -t 0 ] || stream_in=1
# no file mentioned, use the name as file
[[ -z "$FILE" ]] && {
[[ -e "$NAME" ]] && {
@@ -80,24 +82,28 @@ _write() {
NAME=$( basename "$NAME" )
}
}
# stdin is open, use stdin
[ -t 0 ] || stream_in=1
[[ -e "$FILE" ]] && {
# Input file exists, dont use stream
stream_in=0
}
[ -t 0 ] && [[ -z "$FILE" ]] && {
[[ $stream_in -ne 1 ]] && [[ -z "$FILE" ]] && {
_msg File to read needed, or use stdin
exit 1
}
_msg "Writing $NAME"
[[ "$stream_in" -eq 1 ]] && {
_write_stdin "$NAME"
} || {
[[ -d "$FILE" ]] && {
[[ "${NAME,,}" = *".tar" ]] || NAME="${NAME}".tar
_write_folder "$NAME" "$FILE"
} || {
_write_file "$NAME" "$FILE"
}
return $?
}
[[ -d "$FILE" ]] && {
[[ "${NAME,,}" = *".tar" ]] || NAME="${NAME}".tar
_write_folder "$NAME" "$FILE"
return $?
}
_write_file "$NAME" "$FILE"
}
_write_folder() { # name, file