bash : EXPERIMENTAL : add support for filenames with spaces.

This commit is contained in:
Dmitry Voronin 2023-11-22 13:20:01 +03:00
parent 3bc8f5b3b3
commit 4f68139a17
5 changed files with 33 additions and 10 deletions

View file

@ -8,6 +8,7 @@ _ARCHIVE_DATE()
# usage: archive [FILES]
archive()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local count=0 # processed count.
local total=${#} # total to process.
@ -15,7 +16,7 @@ archive()
# Set dafult value to target all directories.
if [[ "${targets}" = "" ]]; then
targets=($(ls --classify | grep /$))
targets=($(ls --classify | grep /\$))
total=${#targets[@]}
fi
@ -43,6 +44,7 @@ archive()
# usage: archive_fast [FILES]
archive_fast()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local count=0 # processed count.
local total=${#} # total to process.
@ -78,6 +80,7 @@ archive_fast()
# usage: archive_check [FILES]
archive_check()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local total=${#} # total to process.
local count=0 # processed count.
@ -128,6 +131,7 @@ archive_check()
# Usage: archive_prune [NAME]
archive_prune()
{
local IFS=$'\n'
local targets=("${@}")
local count=0
local total=${#}
@ -155,6 +159,7 @@ archive_prune()
# usage: unarchive [FILES]
unarchive()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local count=0 # processed count.
local total=${#} # total to process.
@ -212,6 +217,7 @@ unarchive()
# usage: archive_name [ARCHIVE] [NAME]
archive_name()
{
local IFS=$'\n'
local targets="${1}" # target archive(s).
local name="${2}" # new name.
local total=1 # total targets to process.
@ -264,6 +270,7 @@ archive_name()
# convert an old archive to a new format. TODO: remove me after some time when there won't be any old archives.
archive_convert()
{
local IFS=$'\n'
local old_format="_[[:alnum:]]{40}.tar.[xg]z"
local targets=($(ls | grep -E ${old_format}))
@ -311,6 +318,7 @@ export _ARCHIVE_PATTERN
# autocomplete.
_archive_name()
{
local IFS=$'\n'
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
@ -332,5 +340,5 @@ _archive_grep()
_autocomplete_grep ${_ARCHIVE_PATTERN}
}
complete -F _archive_grep archive_check unarchive
complete -F _archive_name archive_name
complete -o filenames -F _archive_grep archive_check unarchive
complete -o filenames -F _archive_name archive_name

View file

@ -3,6 +3,7 @@
# there are also options like -o nospace. see man for more info.
_autocomplete()
{
local IFS=$'\n'
local commands="${@}"
COMPREPLY=()
@ -18,6 +19,7 @@ _autocomplete()
# autocomplete only first argument.
_autocomplete_first()
{
local IFS=$'\n'
local commands="${@}"
COMPREPLY=()
@ -32,8 +34,10 @@ _autocomplete_first()
fi
}
# Autocomplete by grepping file names.
_autocomplete_grep()
{
local IFS=$'\n'
COMPREPLY=()
local pattern="${1}"
@ -48,6 +52,7 @@ _autocomplete_grep()
# autocomplete nested program.
_autocomplete_nested()
{
# local IFS=$'\n'
local cur prev words cword split i
_init_completion -s || return

View file

@ -2,6 +2,7 @@
# Usage: convert <FORMAT> [FILES]
convert()
{
local IFS=$'\n'
local targets=("${@:2}")
local format="${1}"
local total=${#targets[@]}
@ -83,7 +84,7 @@ _convert_gz-xz()
_convert_xz-gz()
{
pv "${1}" | xz -d | gzip -1 > "${1.xz}.gz"
pv "${1}" | xz -d | gzip -1 > "${1%.xz}.gz"
}
_convert_mp3()

View file

@ -2,6 +2,7 @@
# usage: name [FILES]
name()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local count=0 # processed count.
local total=${#} # total to process.
@ -60,6 +61,7 @@ name()
# usage: name_hash [FILES]
name_hash()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local count=0 # processed counter.
local total=${#} # total to process.
@ -117,6 +119,7 @@ name_hash()
# usage: name_hash_check [FILES]
name_hash_check()
{
local IFS=$'\n'
local targets=("${@}") # target file(s).
local total=${#} # total to process.
local count=0 # processed counter.
@ -172,6 +175,7 @@ name_hash_check()
# usage: name_series <SEASON> [FILES]
name_series()
{
local IFS=$'\n'
local season="${1}" # Season number.
local targets=("${@:2}") # Target files.
local count=0 # Processed counter.
@ -229,6 +233,7 @@ name_series()
# usage: name_manga <SEASON> [FILES]
name_manga()
{
local IFS=$'\n'
local season="${1}" # Season number.
local targets=("${@:2}") # Target files.
local count=0 # Processed counter.
@ -287,6 +292,7 @@ name_manga()
# usage: name_ext <EXTENSION> [FILES]
name_ext()
{
local IFS=$'\n'
local extension="${1}" # new extension.
local targets=("${@:2}") # target file(s).
local count=0 # processed counter.
@ -342,6 +348,7 @@ name_ext()
# Usage: name_prefix [OLD] [NEW] [FILES]
name_prefix()
{
local IFS=$'\n'
local old="${1}" # Old prefix.
local new="${2}" # New prefix.
local targets=("${@:3}") # Target files.

View file

@ -4,6 +4,7 @@ _UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$"
# Usage: pack <TARGET.ext> [FILES]
pack()
{
local IFS=$'\n'
local output="${1}"
local targets=("${@:2}")
local format="${output##*.}"
@ -30,22 +31,22 @@ pack()
# process.
case "${format}" in
"tgz")
_pack_tgz "${@}"
_pack_tgz "${output}" "${targets[@]}"
;;
"txz")
_pack_txz "${@}"
_pack_txz "${output}" "${targets[@]}"
;;
"tar")
_pack_tar "${@}"
_pack_tar "${output}" "${targets[@]}"
;;
"zip")
_pack_zip "${@}"
_pack_zip "${output}" "${targets[@]}"
;;
"gz")
_pack_gz "${@}"
_pack_gz "${output}" "${targets[@]}"
;;
"xz")
_pack_xz "${@}"
_pack_xz "${output}" "${targets[@]}"
esac
# actions on error.
@ -60,6 +61,7 @@ pack()
# usage: unpack [FILES]
unpack()
{
local IFS=$'\n'
local targets=("${@}")
local count=0
local failed=0