diff --git a/.README.md b/.README.md index c98efa9..72061ed 100644 --- a/.README.md +++ b/.README.md @@ -401,6 +401,9 @@ Please note that colors depend on Terminal Emulator and may vary based on its se |yellow|`\033[0;33m`| |yellow (bold)|`\033[1;33m`| +## Convert. +`convert `|Convert between different formats. + ## Copy/paste. Command|Description @@ -458,13 +461,6 @@ Command|Description `dcpu [SERVICE]`|Update and recreate a compose service. `dcul [SERVICE]`|Start a compose service and show its logs. -## Pack. - -Command|Description ----|--- -`pack `|Create desired file format from other files. -`unpack [FILES]`|Attempt to extract file content. - ## Environment variables. Variable|Description @@ -569,6 +565,13 @@ Command|Description ---|--- `own [USER] [FILE]`|Change ownership & permissions to specified user. Ownership changes only when root. +## Pack. + +Command|Description +---|--- +`pack `|Create desired file format from other files. +`unpack [FILES]`|Attempt to extract file content. + ## Permissions. Command|Description @@ -583,11 +586,18 @@ Command|Description `ps `|Show process info for matching [PROGRAM] name. ## Recursive. + Command|Description ---|--- `recursive `|Cd into every directory recursively and run specified command in each dir. `recursive1 `|Cd into every directory in current directory and run specified command in each dir. +## Rust. + +Command|Description +---|--- +`rust_book`|Open Rust book in a browser. + ## Shopt. Shopt|Description diff --git a/.config/bash/module/archive.sh b/.config/bash/module/archive.sh index ef5664f..e71e235 100644 --- a/.config/bash/module/archive.sh +++ b/.config/bash/module/archive.sh @@ -117,12 +117,10 @@ archive_check() done # report result. - if [[ ${count} -gt 1 ]] || [[ "${*}" = "" ]]; then - if [[ ${failed} -gt 0 ]]; then - echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}" - else - echo -e "${color_green}All successful.${color_default}" - fi + if [[ ${failed} -gt 0 ]]; then + echo -e "${color_bred}Items failed to validate: ${failed}.${color_default}" + else + echo -e "${color_green}All successful.${color_default}" fi } diff --git a/.config/bash/module/convert.sh b/.config/bash/module/convert.sh new file mode 100644 index 0000000..13cc51f --- /dev/null +++ b/.config/bash/module/convert.sh @@ -0,0 +1,51 @@ +# Convert between different formats. +# Usage: convert +convert() { + local input="${1}" + local output="${2}" + local from="${input##*.}" + local to="${output##*.}" + + # Report no output. + if [[ "${to}" = "" ]]; then + echo -e "${color_bred}no output file/format.${color_default}" + return 1 + fi + + # Report no input. + if [[ "${from}" = "" ]]; then + echo -e "${color_bred}no input file/format.${color_default}" + return 2 + fi + + # Process. + case "${from}-${to}" in + "gz-xz"|"tgz-txz") + _convert_gz-xz "${input}" "${output}" + ;; + "xz-gz"|"txz-tgz") + _convert_xz-gz "${input}" "${output}" + ;; + *) + echo -e "${color_yellow}Conversion ${from}-${to} not supported.${color_default}" + return 3 + ;; + esac + + if [[ $? = 0 ]]; then + echo -e "${color_green}Done.${color_default}" + else + echo -e "${color_bred}There were errors.${color_default}" + fi +} + +_convert_gz-xz() { + pv "${1}" | gzip -d | xz -9e > "${2}" +} + +_convert_xz-gz() { + pv "${1}" | xz -d | gzip -1 > "${2}" +} + +# Export. +export -f convert _convert_gz-xz _convert_xz-gz