bash : reformat braces.

This commit is contained in:
Dmitry Voronin 2023-12-05 23:56:04 +03:00
parent 29585b4842
commit 604ce79c31
29 changed files with 175 additions and 306 deletions

View file

@ -1,13 +1,11 @@
_ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z" _ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z"
_ARCHIVE_DATE() _ARCHIVE_DATE() {
{
date +%Y%m%d%H%M date +%Y%m%d%H%M
} }
# archive file with maximum compression and checksum. # archive file with maximum compression and checksum.
# usage: archive [FILES] # usage: archive [FILES]
archive() archive() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}") # target file(s).
local count=0 # processed count. local count=0 # processed count.
@ -54,8 +52,7 @@ archive()
# archive file with minimal compression and checksum. # archive file with minimal compression and checksum.
# usage: archive_fast [FILES] # usage: archive_fast [FILES]
archive_fast() archive_fast() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}") # target file(s).
local count=0 # processed count. local count=0 # processed count.
@ -102,8 +99,7 @@ archive_fast()
# check archive hashes. # check archive hashes.
# usage: archive_check [FILES] # usage: archive_check [FILES]
archive_check() archive_check() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}") # target file(s).
local total=${#} # total to process. local total=${#} # total to process.
@ -147,8 +143,7 @@ archive_check()
# Delete old versions of an archives. # Delete old versions of an archives.
# Usage: archive_prune [NAME] # Usage: archive_prune [NAME]
archive_prune() archive_prune() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -199,8 +194,7 @@ archive_prune()
# extract previously created archive with checksum validation. # extract previously created archive with checksum validation.
# usage: unarchive [FILES] # usage: unarchive [FILES]
unarchive() unarchive() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}") # target file(s).
local count=0 # processed count. local count=0 # processed count.
@ -266,8 +260,7 @@ unarchive()
# rename archive. if no name specified, it simplifies archive's name. # rename archive. if no name specified, it simplifies archive's name.
# usage: archive_name [ARCHIVE] [NAME] # usage: archive_name [ARCHIVE] [NAME]
archive_name() archive_name() {
{
local IFS=$'\n' local IFS=$'\n'
local targets="${1}" # target archive(s). local targets="${1}" # target archive(s).
local name="${2}" # new name. local name="${2}" # new name.
@ -330,8 +323,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. # convert an old archive to a new format. TODO: remove me after some time when there won't be any old archives.
archive_convert() archive_convert() {
{
local IFS=$'\n' local IFS=$'\n'
local old_format="_[[:alnum:]]{40}.tar.[xg]z" local old_format="_[[:alnum:]]{40}.tar.[xg]z"
local targets=($(ls | grep -E ${old_format})) local targets=($(ls | grep -E ${old_format}))
@ -373,8 +365,7 @@ archive_convert()
done done
} }
_archive_parse() _archive_parse() {
{
local input="${1}" local input="${1}"
local name="${input%_*}" local name="${input%_*}"
local format="${input##*.}" local format="${input##*.}"
@ -393,8 +384,7 @@ export -f archive archive_fast archive_check unarchive archive_name _ARCHIVE_DAT
export _ARCHIVE_PATTERN export _ARCHIVE_PATTERN
# autocomplete. # autocomplete.
_archive_name() _archive_name() {
{
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=() COMPREPLY=()
@ -412,8 +402,7 @@ _archive_name()
fi fi
} }
_archive_grep() _archive_grep() {
{
_autocomplete_grep ${_ARCHIVE_PATTERN} _autocomplete_grep ${_ARCHIVE_PATTERN}
} }

View file

@ -1,8 +1,7 @@
# bash autocomplete. # bash autocomplete.
# usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo # usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo
# there are also options like -o nospace. see man for more info. # there are also options like -o nospace. see man for more info.
_autocomplete() _autocomplete() {
{
local IFS=$'\n' local IFS=$'\n'
local commands="${*}" local commands="${*}"
@ -17,8 +16,7 @@ _autocomplete()
} }
# autocomplete only first argument. # autocomplete only first argument.
_autocomplete_first() _autocomplete_first() {
{
local IFS=$'\n' local IFS=$'\n'
local commands="${*}" local commands="${*}"
@ -35,8 +33,7 @@ _autocomplete_first()
} }
# Autocomplete by grepping file names. # Autocomplete by grepping file names.
_autocomplete_grep() _autocomplete_grep() {
{
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=() COMPREPLY=()
@ -50,8 +47,7 @@ _autocomplete_grep()
} }
# autocomplete nested program. # autocomplete nested program.
_autocomplete_nested() _autocomplete_nested() {
{
# local IFS=$'\n' # local IFS=$'\n'
local cur prev words cword split i local cur prev words cword split i
_init_completion -s || return _init_completion -s || return

View file

@ -1,13 +1,11 @@
# install Cargo/Rust. # install Cargo/Rust.
bootstrap_rust() bootstrap_rust() {
{
curl https://sh.rustup.rs -sSf | sh curl https://sh.rustup.rs -sSf | sh
rustup component add rust-analyzer rustup component add rust-analyzer
} }
# install TeXLive. # install TeXLive.
bootstrap_texlive() bootstrap_texlive() {
{
cd /tmp cd /tmp
wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
tar -xf install-tl-unx.tar.gz tar -xf install-tl-unx.tar.gz
@ -17,15 +15,13 @@ bootstrap_texlive()
} }
# install grub theme. # install grub theme.
bootstrap_grub() bootstrap_grub() {
{
wget -O- https://github.com/shvchk/fallout-grub-theme/raw/master/install.sh | bash wget -O- https://github.com/shvchk/fallout-grub-theme/raw/master/install.sh | bash
echo 'GRUB_HIDDEN_TIMEOUT=' >> /etc/default/grub echo 'GRUB_HIDDEN_TIMEOUT=' >> /etc/default/grub
grub2-mkconfig -o /etc/grub2.cfg grub2-mkconfig -o /etc/grub2.cfg
} }
# install ffmpeg. # install ffmpeg.
bootstrap_ffmpeg() bootstrap_ffmpeg() {
{
flatpak install org.kde.kdenlive flatpak install org.kde.kdenlive
} }

View file

@ -1,7 +1,6 @@
# CD (back) to directory. # CD (back) to directory.
# Usage: cdd <DIR> # Usage: cdd <DIR>
cdd() cdd() {
{
local target="${1}" local target="${1}"
local array local array
local result local result

View file

@ -1,7 +1,6 @@
# Save file checksums. # Save file checksums.
# Usage: checksum_create [FILES] # Usage: checksum_create [FILES]
checksum_create() checksum_create() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -47,8 +46,7 @@ checksum_create()
} }
# Check stored values against actual files. # Check stored values against actual files.
checksum_check() checksum_check() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -97,20 +95,17 @@ checksum_check()
fi fi
} }
checksum() checksum() {
{
find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1
} }
_checksum_create() _checksum_create() {
{
local path="${1%/*}" local path="${1%/*}"
local name="${1##*/}" local name="${1##*/}"
sha1sum "${path}/${name}" > "${path}/.${name}.sha1" sha1sum "${path}/${name}" > "${path}/.${name}.sha1"
} }
_checksum_check() _checksum_check() {
{
local file="${1##*\ \ }" local file="${1##*\ \ }"
local stored="${1%%\ \ *}" local stored="${1%%\ \ *}"

View file

@ -19,21 +19,6 @@ export color_yellow="\033[0;33m"
export color_byellow="\033[1;33m" export color_byellow="\033[1;33m"
# print all available colors with their names colored in corresponding color. # print all available colors with their names colored in corresponding color.
color_test() color_test() {
{ echo -e "${color_default}color_default\n${color_blue}color_blue\n${color_bblue}color_bblue\n${color_cyan}color_cyan\n${color_bcyan}color_bcyan\n${color_green}color_green\n${color_bgreen}color_bgreen\n${color_purple}color_purple\n${color_bpurple}color_bpurple\n${color_red}color_red\n${color_bred}color_bred\n${color_white}color_white\n${color_bwhite}color_bwhite\n${color_yellow}color_yellow\n${color_byellow}color_byellow"
echo -e " ${color_default}color_default\n\
${color_blue}color_blue\n\
${color_bblue}color_bblue\n\
${color_cyan}color_cyan\n\
${color_bcyan}color_bcyan\n\
${color_green}color_green\n\
${color_bgreen}color_bgreen\n\
${color_purple}color_purple\n\
${color_bpurple}color_bpurple\n\
${color_red}color_red\n\
${color_bred}color_bred\n\
${color_white}color_white\n\
${color_bwhite}color_bwhite\n\
${color_yellow}color_yellow\n\
${color_byellow}color_byellow"
} }

View file

@ -1,2 +1,2 @@
alias copy="wl-copy" # copy stdin to system clipboard. alias copy="wl-copy" # copy stdin to system clipboard.
alias paste="wl-paste" # paste system clipboard to stdout. alias paste="wl-paste" # paste system clipboard to stdout.

View file

@ -19,48 +19,41 @@ alias dcs="docker compose stop"
# down & up specified services. # down & up specified services.
# usage: dcdu [SERVICES] # usage: dcdu [SERVICES]
dcdu() dcdu() {
{
dcd "${@}" dcd "${@}"
dcu "${@}" dcu "${@}"
} }
# pull & up specified services. # pull & up specified services.
# usage: dcpu [SERVICES] # usage: dcpu [SERVICES]
dcpu() dcpu() {
{
dcp "${@}" dcp "${@}"
dcu "${@}" dcu "${@}"
} }
# up & attach to logs for specified services. # up & attach to logs for specified services.
# usage: dcul [SERVICES] # usage: dcul [SERVICES]
dcul() dcul() {
{
dcu "${@}" && dcl "${@}" dcu "${@}" && dcl "${@}"
} }
# find out container's IP address. # find out container's IP address.
# usage: docker_up <CONTAINER NAME> # usage: docker_up <CONTAINER NAME>
docker_ip() docker_ip() {
{
docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' $1 | sed "s/^.//" | sed "s/.$//" docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' $1 | sed "s/^.//" | sed "s/.$//"
} }
# update all docker images. # update all docker images.
docker_update() docker_update() {
{
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
} }
# autocomplete. # autocomplete.
_dc_services() _dc_services() {
{
_autocomplete "$(docker compose config --services 2> /dev/null)" _autocomplete "$(docker compose config --services 2> /dev/null)"
} }
_dc_containers() _dc_containers() {
{
_autocomplete "$(docker ps --format "\""{{.Names}}"\"")" _autocomplete "$(docker ps --format "\""{{.Names}}"\"")"
} }

View file

@ -1,7 +1,6 @@
# mux audio into containers. file names in sound and current dirrectories must match. tmp usage for anime downloads. # mux audio into containers. file names in sound and current dirrectories must match. tmp usage for anime downloads.
# usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR> # usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>
ffmpeg_mux_audio() ffmpeg_mux_audio() {
{
if [[ "$1" = "" ]]; then if [[ "$1" = "" ]]; then
echo "usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>" echo "usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>"
return 2 return 2
@ -12,8 +11,7 @@ ffmpeg_mux_audio()
# Mux cover into music file. # Mux cover into music file.
# Usage: ffmpeg_mux_cover <FORMAT> <COVER> # Usage: ffmpeg_mux_cover <FORMAT> <COVER>
ffmpeg_mux_cover() ffmpeg_mux_cover() {
{
if [[ "${1}" = "" ]]; then if [[ "${1}" = "" ]]; then
echo "Usage: ffmpeg_mux_cover <FORMAT> <COVER>" echo "Usage: ffmpeg_mux_cover <FORMAT> <COVER>"
return 2 return 2
@ -43,8 +41,7 @@ ffmpeg_mux_cover()
# Change music metadata. # Change music metadata.
# Usage: ffmpeg_music_meta <FORMAT> # Usage: ffmpeg_music_meta <FORMAT>
ffmpeg_music_meta() ffmpeg_music_meta() {
{
if [[ "${1}" = "" ]]; then if [[ "${1}" = "" ]]; then
echo "Usage: ffmpeg_music_meta <FORMAT>" echo "Usage: ffmpeg_music_meta <FORMAT>"
return 2 return 2
@ -74,21 +71,18 @@ ffmpeg_music_meta()
rm -d out/ rm -d out/
} }
_ffprobe_fps() _ffprobe_fps() {
{
local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "${1}") local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "${1}")
fps="${fps%%/*}" fps="${fps%%/*}"
echo "${fps}" echo "${fps}"
} }
_ffprobe_keyint() _ffprobe_keyint() {
{
local fps=$(_ffprobe_fps "${1}") local fps=$(_ffprobe_fps "${1}")
echo $((fps*5)) echo $((fps*5))
} }
_ffprobe_ba() _ffprobe_ba() {
{
local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "${1}") local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "${1}")
[[ "${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 [[ "${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128
} }

View file

@ -1,6 +1,5 @@
# Find all file extensions. # Find all file extensions.
find_ext() find_ext() {
{
local types=($(find -type f | sed -e "s/.*\///" -e "s/^\.//" -e "/\./!d" -e "s/.*\.//")) local types=($(find -type f | sed -e "s/.*\///" -e "s/^\.//" -e "/\./!d" -e "s/.*\.//"))
echo "${types[@]}" | tr ' ' '\n' | sort -u echo "${types[@]}" | tr ' ' '\n' | sort -u
} }

View file

@ -1,8 +1,7 @@
# fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. # fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb.
# usage: fix_ethernet_speed <DEVICE> <SPEED> # usage: fix_ethernet_speed <DEVICE> <SPEED>
# SPEED is one of 10/100/1000 etc. # SPEED is one of 10/100/1000 etc.
fix_ethernet_speed() fix_ethernet_speed() {
{
local device="${1}" local device="${1}"
local speed="${2}" local speed="${2}"

View file

@ -20,8 +20,7 @@ alias gp="git apply"
# alias to preview diff while adding. adds current dir by default. # alias to preview diff while adding. adds current dir by default.
# usage: ga [FILES] # usage: ga [FILES]
ga() ga() {
{
local target=${@} local target=${@}
if [[ "${target}" = "" ]]; then if [[ "${target}" = "" ]]; then
@ -34,8 +33,7 @@ ga()
# rebase by X commits or from root. when COUNT is 0 - rebase from root. default is 2. # rebase by X commits or from root. when COUNT is 0 - rebase from root. default is 2.
# usage: gr [COMMIT COUNT] # usage: gr [COMMIT COUNT]
gr() gr() {
{
local base="${1}" local base="${1}"
# rebase last 2 commits by default. # rebase last 2 commits by default.
@ -53,8 +51,7 @@ gr()
# specify git user as Dmitry Voronin with provided email. # specify git user as Dmitry Voronin with provided email.
# usage: gu [EMAIL] # usage: gu [EMAIL]
gu() gu() {
{
local name="Dmitry Voronin" local name="Dmitry Voronin"
local email="${1}" local email="${1}"
@ -69,39 +66,33 @@ gu()
# Get my git repo. # Get my git repo.
# Usage: gg <REPO> # Usage: gg <REPO>
gg() gg() {
{
git clone https://git.voronind.com/voronind/"${1}" git clone https://git.voronind.com/voronind/"${1}"
} }
# See diff for a specific commit. # See diff for a specific commit.
# Usage: gdc <COMMITHASH> # Usage: gdc <COMMITHASH>
gdc() gdc() {
{
git diff "${1}^!" git diff "${1}^!"
} }
# Show current branch. # Show current branch.
_git_current_branch() _git_current_branch() {
{
git branch --show-current 2> /dev/null git branch --show-current 2> /dev/null
} }
# Show origin's url. # Show origin's url.
_git_origin_url() _git_origin_url() {
{
git remote get-url origin git remote get-url origin
} }
# Get this dotfiles url. # Get this dotfiles url.
_git_dotfiles_url() _git_dotfiles_url() {
{
echo 'https://git.voronind.com/voronind/linux.git' echo 'https://git.voronind.com/voronind/linux.git'
} }
# Check if current git repo is this dotfiles. # Check if current git repo is this dotfiles.
_git_is_dotfiles() _git_is_dotfiles() {
{
# [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]] # [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]]
local dir="${PWD}" local dir="${PWD}"
@ -119,27 +110,26 @@ _git_is_dotfiles()
} }
# autocomplete. # autocomplete.
_completion_loader git &> /dev/null _completion_loader git &> /dev/null
__git_complete gps _git_push &> /dev/null __git_complete gps _git_push &> /dev/null
__git_complete gpsf _git_push &> /dev/null __git_complete gpsf _git_push &> /dev/null
__git_complete gpl _git_pull &> /dev/null __git_complete gpl _git_pull &> /dev/null
__git_complete gl _git_log &> /dev/null __git_complete gl _git_log &> /dev/null
__git_complete gs _git_status &> /dev/null __git_complete gs _git_status &> /dev/null
__git_complete gst _git_stash &> /dev/null __git_complete gst _git_stash &> /dev/null
__git_complete gd _git_diff &> /dev/null __git_complete gd _git_diff &> /dev/null
__git_complete gdc _git_diff &> /dev/null __git_complete gdc _git_diff &> /dev/null
__git_complete gc _git_commit &> /dev/null __git_complete gc _git_commit &> /dev/null
__git_complete gch _git_checkout &> /dev/null __git_complete gch _git_checkout &> /dev/null
__git_complete gchb _git_checkout &> /dev/null __git_complete gchb _git_checkout &> /dev/null
__git_complete gb _git_branch &> /dev/null __git_complete gb _git_branch &> /dev/null
__git_complete gbd _git_branch &> /dev/null __git_complete gbd _git_branch &> /dev/null
__git_complete gf _git_fetch &> /dev/null __git_complete gf _git_fetch &> /dev/null
__git_complete gt _git_tag &> /dev/null __git_complete gt _git_tag &> /dev/null
__git_complete gp _git_apply &> /dev/null __git_complete gp _git_apply &> /dev/null
__git_complete ga _git_add &> /dev/null __git_complete ga _git_add &> /dev/null
_gu() _gu() {
{
_autocomplete_first account@voronind.com dd.voronin@fsight.ru _autocomplete_first account@voronind.com dd.voronin@fsight.ru
} }

View file

@ -3,21 +3,18 @@ unalias l ll lll llll la lla &> /dev/null
unset l ll lll llll la lla &> /dev/null unset l ll lll llll la lla &> /dev/null
# list files in dir. # list files in dir.
l() l() {
{
ls -lhv --si --group-directories-first "$@" ls -lhv --si --group-directories-first "$@"
} }
# list last modified files first. # list last modified files first.
ll() ll() {
{
ls -lhvtr --si "$@" ls -lhvtr --si "$@"
} }
# list files in tree structure. # list files in tree structure.
# usage: lll [DEPTH] [DIRS] # usage: lll [DEPTH] [DIRS]
lll() lll() {
{
local IFS=$'\n' local IFS=$'\n'
local depth="${1}" local depth="${1}"
local target=("${@:2}") local target=("${@:2}")
@ -30,20 +27,17 @@ lll()
} }
# list files recursively. # list files recursively.
llll() llll() {
{
ls -RlAhv --si --group-directories-first "$@" ls -RlAhv --si --group-directories-first "$@"
} }
# list all files in dir, incl. hidden files. # list all files in dir, incl. hidden files.
la() la() {
{
ls -lAh --si --group-directories-first "$@" ls -lAh --si --group-directories-first "$@"
} }
# list all files in dir, incl. hidden files, sorted by mtime. # list all files in dir, incl. hidden files, sorted by mtime.
lla() lla() {
{
ls -lAhtr --si "$@" ls -lAhtr --si "$@"
} }

View file

@ -1,11 +1,10 @@
# rename files to strip all special characters. # rename files to strip all special characters.
# usage: name [FILES] # usage: name [FILES]
name() name() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}")
local count=0 # processed count. local count=0
local total=${#} # total to process. local total=${#}
local failed=0 local failed=0
# all targets except hidden by default. # all targets except hidden by default.
@ -65,12 +64,11 @@ name()
# rename all files to their hashes while keeping extensions. # rename all files to their hashes while keeping extensions.
# usage: name_hash [FILES] # usage: name_hash [FILES]
name_hash() name_hash() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}")
local count=0 # processed counter. local count=0
local total=${#} # total to process. local total=${#}
local failed=0 local failed=0
# all files except hidden by default. # all files except hidden by default.
@ -126,8 +124,7 @@ name_hash()
# check hashes for renamed files. # check hashes for renamed files.
# usage: name_hash_check [FILES] # usage: name_hash_check [FILES]
name_hash_check() name_hash_check() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") # target file(s). local targets=("${@}") # target file(s).
local total=${#} # total to process. local total=${#} # total to process.
@ -169,14 +166,13 @@ name_hash_check()
# rename files for Jellyfin series, i.e. Episode S01E01.mkv # rename files for Jellyfin series, i.e. Episode S01E01.mkv
# usage: name_series <SEASON> [FILES] # usage: name_series <SEASON> [FILES]
name_series() name_series() {
{
local IFS=$'\n' local IFS=$'\n'
local season="${1}" # Season number. local season="${1}"
local targets=("${@:2}") # Target files. local targets=("${@:2}")
local count=0 # Processed counter. local count=0
local episode=0 # Current episode count. local episode=0
local total=${#} # Total to process. local total=${#}
local failed=0 local failed=0
# error when no season number specified. # error when no season number specified.
@ -224,15 +220,14 @@ name_series()
# rename files for Kavita manga format. # rename files for Kavita manga format.
# usage: name_manga <SEASON> [FILES] # usage: name_manga <SEASON> [FILES]
name_manga() name_manga() {
{
local IFS=$'\n' local IFS=$'\n'
local season="${1}" # Season number. local season="${1}"
local targets=("${@:2}") # Target files. local targets=("${@:2}")
local count=0 # Processed counter. local count=0
local episode=0 # Current episode count. local episode=0
local total=${#} # Total to process. local total=${#}
local manga="${PWD##*/}" # Manga name. local manga="${PWD##*/}"
local failed=0 local failed=0
# error when no season number specified. # error when no season number specified.
@ -280,13 +275,12 @@ name_manga()
# rename files for new extension. # rename files for new extension.
# usage: name_ext <EXTENSION> [FILES] # usage: name_ext <EXTENSION> [FILES]
name_ext() name_ext() {
{
local IFS=$'\n' local IFS=$'\n'
local extension="${1}" # new extension. local extension="${1}"
local targets=("${@:2}") # target file(s). local targets=("${@:2}")
local count=0 # processed counter. local count=0
local total=$((${#}-1)) # total to process. local total=$((${#}-1))
local failed=0 local failed=0
# error when no new extension specified. # error when no new extension specified.
@ -333,14 +327,13 @@ name_ext()
# Change file prefixes. # Change file prefixes.
# Usage: name_prefix <OLD> <NEW> [FILES] # Usage: name_prefix <OLD> <NEW> [FILES]
name_prefix() name_prefix() {
{
local IFS=$'\n' local IFS=$'\n'
local old="${1}" # Old prefix. local old="${1}"
local new="${2}" # New prefix. local new="${2}"
local targets=("${@:3}") # Target files. local targets=("${@:3}")
local count=0 # Total files processed. local count=0
local total=$((${#}-2)) # Total files to process. local total=$((${#}-2))
local failed=0 local failed=0
# All targets by default. # All targets by default.
@ -381,14 +374,13 @@ name_prefix()
# Change file postfix. # Change file postfix.
# Usage: name_postfix <OLD> <NEW> [FILES] # Usage: name_postfix <OLD> <NEW> [FILES]
name_postfix() name_postfix() {
{
local IFS=$'\n' local IFS=$'\n'
local old="${1}" # Old postfix. local old="${1}"
local new="${2}" # New postfix. local new="${2}"
local targets=("${@:3}") # Target files. local targets=("${@:3}")
local count=0 # Total files processed. local count=0
local total=$((${#}-2)) # Total files to process. local total=$((${#}-2))
local failed=0 local failed=0
# All targets by default. # All targets by default.
@ -428,14 +420,13 @@ name_postfix()
} }
# Replace part of the name. # Replace part of the name.
name_replace() name_replace() {
{
local IFS=$'\n' local IFS=$'\n'
local old="${1}" # Old postfix. local old="${1}"
local new="${2}" # New postfix. local new="${2}"
local targets=("${@:3}") # Target files. local targets=("${@:3}")
local count=0 # Total files processed. local count=0
local total=$((${#}-2)) # Total files to process. local total=$((${#}-2))
local failed=0 local failed=0
# All targets by default. # All targets by default.

View file

@ -1,11 +1,9 @@
# send Telegram notification. # send Telegram notification.
notify() notify() {
{
curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null
} }
# send silent Telegram notification. # send silent Telegram notification.
notify_silent() notify_silent() {
{
curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null
} }

View file

@ -1,7 +1,6 @@
# change file ownership to specified user id and restrict access to him. # change file ownership to specified user id and restrict access to him.
# usage: own [USER] [FILES] # usage: own [USER] [FILES]
own() own() {
{
local file="${2}" local file="${2}"
local user="${1}" local user="${1}"

View file

@ -2,8 +2,7 @@ _UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$"
# Pack files into desired format. # Pack files into desired format.
# Usage: pack <TARGET.ext> [FILES] # Usage: pack <TARGET.ext> [FILES]
pack() pack() {
{
local IFS=$'\n' local IFS=$'\n'
local output="${1}" local output="${1}"
local targets=("${@:2}") local targets=("${@:2}")
@ -62,8 +61,7 @@ pack()
# attempt to unpack everything. # attempt to unpack everything.
# usage: unpack [FILES] # usage: unpack [FILES]
unpack() unpack() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -142,78 +140,63 @@ unpack()
fi fi
} }
_pack_zip() _pack_zip() {
{
zip -9 -r "${@}" zip -9 -r "${@}"
} }
_pack_tgz() _pack_tgz() {
{
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "${1}" tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "${1}"
} }
_pack_txz() _pack_txz() {
{
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "${1}" tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "${1}"
} }
_pack_tar() _pack_tar() {
{
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') > "${1}" tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') > "${1}"
} }
_pack_gz() _pack_gz() {
{
pv "${2}" | gzip -1 > "${1}" pv "${2}" | gzip -1 > "${1}"
} }
_pack_xz() _pack_xz() {
{
pv "${2}" | xz -9e > "${1}" pv "${2}" | xz -9e > "${1}"
} }
_unpack_zip() _unpack_zip() {
{
unzip "${1}" unzip "${1}"
} }
_unpack_7z() _unpack_7z() {
{
7za x "${1}" 7za x "${1}"
} }
_unpack_tgz() _unpack_tgz() {
{
pv "${1}" | gzip -d | tar -xf - pv "${1}" | gzip -d | tar -xf -
} }
_unpack_txz() _unpack_txz() {
{
pv "${1}" | xz -d | tar -xf - pv "${1}" | xz -d | tar -xf -
} }
_unpack_tar() _unpack_tar() {
{
pv "${1}" | tar -xf - pv "${1}" | tar -xf -
} }
_unpack_iso() _unpack_iso() {
{
7za x "${1}" 7za x "${1}"
} }
_unpack_rar() _unpack_rar() {
{
unrar x "${1}" unrar x "${1}"
} }
_unpack_gz() _unpack_gz() {
{
pv "${1}" | gzip -d > "${1%.gz}" pv "${1}" | gzip -d > "${1%.gz}"
} }
_unpack_xz() _unpack_xz() {
{
pv "${1}" | xz -d > "${1%.xz}" pv "${1}" | xz -d > "${1%.xz}"
} }

View file

@ -1,7 +1,6 @@
# parse data and output simplified format. # parse data and output simplified format.
# usage: parse_simplify <STRING> # usage: parse_simplify <STRING>
parse_simplify() parse_simplify() {
{
echo "${*}" | \ echo "${*}" | \
sed -e "s/ /_/g" \ sed -e "s/ /_/g" \
-e "s/[^[:alnum:]_-]//g" \ -e "s/[^[:alnum:]_-]//g" \
@ -13,8 +12,7 @@ parse_simplify()
# Parse to CamelCase. # Parse to CamelCase.
# Usage: parse_camel <STRING> # Usage: parse_camel <STRING>
parse_camel() parse_camel() {
{
local IFS=${IFS}_- local IFS=${IFS}_-
local parts=($(parse_simplify ${1})) local parts=($(parse_simplify ${1}))
local result local result
@ -29,8 +27,7 @@ parse_camel()
# parse data keeping only alphanumeric characters. # parse data keeping only alphanumeric characters.
# usage: parse_alnum <STRING> # usage: parse_alnum <STRING>
parse_alnum() parse_alnum() {
{
echo "${*}" | \ echo "${*}" | \
sed -e "s/[^[:alnum:]]//g" sed -e "s/[^[:alnum:]]//g"
} }

View file

@ -1,8 +1,7 @@
PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}") PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}")
# custom terminal prompt format. # custom terminal prompt format.
__prompt_command() __prompt_command() {
{
local last_status="${?}" local last_status="${?}"
local is_error=false local is_error=false
local is_root=false local is_root=false
@ -81,8 +80,7 @@ __prompt_command()
fi fi
} }
_ps1error() _ps1error() {
{
local type local type
case ${1} in case ${1} in
1) type="GENERAL" ;; 1) type="GENERAL" ;;
@ -120,7 +118,7 @@ _ps1error()
157) type="SIGIO" ;; 157) type="SIGIO" ;;
158) type="SIGPWR" ;; 158) type="SIGPWR" ;;
159) type="SIGSYS" ;; 159) type="SIGSYS" ;;
*) type="" ;; *) type="" ;;
esac esac
echo -n "${type}" echo -n "${type}"

View file

@ -1,7 +1,6 @@
# Run something recursively over all directories. # Run something recursively over all directories.
# Usage: recursive <COMMAND> # Usage: recursive <COMMAND>
recursive() recursive() {
{
local IFS=$'\n' local IFS=$'\n'
local current="${PWD}" local current="${PWD}"
local dirs=$(find -type d) local dirs=$(find -type d)
@ -32,8 +31,8 @@ recursive()
# Run something recursively over all directories. # Run something recursively over all directories.
# Usage: recursive1 <COMMAND> # Usage: recursive1 <COMMAND>
recursive1() # TODO: create generic function. # TODO: create generic function.
{ recursive1() {
local IFS=$'\n' local IFS=$'\n'
local current="${PWD}" local current="${PWD}"
local dirs=$(find -mindepth 1 -maxdepth 1 -type d) local dirs=$(find -mindepth 1 -maxdepth 1 -type d)

View file

@ -1,5 +1,4 @@
tsize() tsize() {
{
local width=$(tput cols) local width=$(tput cols)
local height=$(tput lines) local height=$(tput lines)
echo "${width}x${height}" echo "${width}x${height}"

View file

@ -1,6 +1,5 @@
# CD into host's primary tmp dir. # CD into host's primary tmp dir.
tmp() tmp() {
{
local host="${HOSTNAME}" local host="${HOSTNAME}"
local tmp_path local tmp_path

View file

@ -1,6 +1,5 @@
# create/attach to named session. # create/attach to named session.
ta() ta() {
{
local name="$1" local name="$1"
# set default name. # set default name.
@ -20,8 +19,7 @@ alias tl="tmux list-sessions"
# Rename current session. Uses current dir name by default. # Rename current session. Uses current dir name by default.
# Usage: trn [NAME] # Usage: trn [NAME]
trn() trn() {
{
local name="${1}" local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}" [[ "${name}" = "" ]] && name="${PWD##*/}"
@ -31,8 +29,7 @@ trn()
# Assign name (to window). Uses current dir name by default. # Assign name (to window). Uses current dir name by default.
# Usage: tn [NAME] # Usage: tn [NAME]
tn() tn() {
{
local name="${1}" local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}" [[ "${name}" = "" ]] && name="${PWD##*/}"
@ -41,8 +38,7 @@ tn()
} }
# kill specified session or default one. # kill specified session or default one.
tk() tk() {
{
# set default name. # set default name.
if [[ "${1}" = "" ]]; then if [[ "${1}" = "" ]]; then
1="main" 1="main"
@ -55,8 +51,7 @@ tk()
} }
# kill all sessions. # kill all sessions.
tka() tka() {
{
local sessions=$(tmux list-sessions | sed -e 's/:.*//') local sessions=$(tmux list-sessions | sed -e 's/:.*//')
for session in $sessions; do for session in $sessions; do
@ -65,18 +60,15 @@ tka()
} }
# autocompletes. # autocompletes.
_complete_tmux_session() _complete_tmux_session() {
{
_autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" _autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
} }
_complete_tmux_sessions() _complete_tmux_sessions() {
{
_autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" _autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')"
} }
_complete_tmux_name() _complete_tmux_name() {
{
_autocomplete_first "${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//') _autocomplete_first "${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//')
} }

View file

@ -1,7 +1,6 @@
# attach/create toolbx container with default or specified name. # attach/create toolbx container with default or specified name.
# usage: tb [NAME] # usage: tb [NAME]
tba() tba() {
{
local name="${1}" local name="${1}"
# set default name. # set default name.
@ -39,8 +38,7 @@ tba()
# remove toolbx container with default or specified name. # remove toolbx container with default or specified name.
# usage: tbk [NAME] # usage: tbk [NAME]
tbk() tbk() {
{
local name="${1}" local name="${1}"
# set default name. # set default name.
@ -54,8 +52,7 @@ tbk()
# install rpm-fusion repository. # install rpm-fusion repository.
# usage: tb_rpmfusion [NAME] # usage: tb_rpmfusion [NAME]
tb_rpmfusion() tb_rpmfusion() {
{
local name="${1}" local name="${1}"
# set default name. # set default name.
@ -71,8 +68,7 @@ tb_rpmfusion()
alias tbl="toolbox list -c" alias tbl="toolbox list -c"
# autocomplete. # autocomplete.
_tb_containers() _tb_containers() {
{
_autocomplete_first "$(toolbox list -c | sed -e '1d' | awk '{ print $2 }')" _autocomplete_first "$(toolbox list -c | sed -e '1d' | awk '{ print $2 }')"
} }

View file

@ -1,7 +1,6 @@
# Convert between different formats. # Convert between different formats.
# Usage: transcode <FORMAT> [FILES] # Usage: transcode <FORMAT> [FILES]
transcode() transcode() {
{
local IFS=$'\n' local IFS=$'\n'
local targets=("${@:2}") local targets=("${@:2}")
local format="${1}" local format="${1}"
@ -91,38 +90,32 @@ transcode()
fi fi
} }
_transcode_gz-xz() _transcode_gz-xz() {
{
[[ -f "${2}" ]] && return 1 [[ -f "${2}" ]] && return 1
pv "${1}" | gzip -d | xz -9e > "${2}" pv "${1}" | gzip -d | xz -9e > "${2}"
} }
_transcode_xz-gz() _transcode_xz-gz() {
{
[[ -f "${2}" ]] && return 1 [[ -f "${2}" ]] && return 1
pv "${1}" | xz -d | gzip -1 > "${2}" pv "${1}" | xz -d | gzip -1 > "${2}"
} }
_transcode_mp3() _transcode_mp3() {
{
ffmpeg -n -i "${1}" -c:a libmp3lame -b:a 320k -f mp3 "${2}" ffmpeg -n -i "${1}" -c:a libmp3lame -b:a 320k -f mp3 "${2}"
} }
_transcode_flac() _transcode_flac() {
{
ffmpeg -n -i "${1}" -c:a flac -f flac "${2}" ffmpeg -n -i "${1}" -c:a flac -f flac "${2}"
} }
_transcode_mka() _transcode_mka() {
{
local braudio=$(_ffprobe_ba "${1}") local braudio=$(_ffprobe_ba "${1}")
[[ ${braudio} -gt 128 ]] && braudio=128 [[ ${braudio} -gt 128 ]] && braudio=128
ffmpeg -n -i "${1}" -ac 2 -c:a libopus -b:a ${braudio}k -vn "${2}" ffmpeg -n -i "${1}" -ac 2 -c:a libopus -b:a ${braudio}k -vn "${2}"
} }
_transcode_mkv() _transcode_mkv() {
{
local keyint=$(_ffprobe_keyint "${1}") local keyint=$(_ffprobe_keyint "${1}")
local braudio=$(_ffprobe_ba "${1}") local braudio=$(_ffprobe_ba "${1}")
[[ ${braudio} -gt 128 ]] && braudio=128 [[ ${braudio} -gt 128 ]] && braudio=128

View file

@ -1,6 +1,5 @@
# retry command every 2 sec until it completes. # retry command every 2 sec until it completes.
try() try() {
{
local result=-1 local result=-1
while [ "$result" != 0 ]; do while [ "$result" != 0 ]; do

View file

@ -1,5 +1,4 @@
# Get the number of avaialble cores (threads). # Get the number of avaialble cores (threads).
_core_count() _core_count() {
{
cat /proc/cpuinfo | grep ^processor | wc -l cat /proc/cpuinfo | grep ^processor | wc -l
} }

View file

@ -1,7 +1,6 @@
# Download video from URL in background. When no [LINK] specified, it tries to update previously downloaded link. # Download video from URL in background. When no [LINK] specified, it tries to update previously downloaded link.
# Usage: vdl [LINK] # Usage: vdl [LINK]
vdl() vdl() {
{
# Check that ffmpeg and ffprobe are available. # Check that ffmpeg and ffprobe are available.
if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then
echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}" echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}"

View file

@ -1,6 +1,5 @@
# set specified file as a wallpaper. # set specified file as a wallpaper.
wallpaper() wallpaper() {
{
path_wallpaper=~/.local/share/backgrounds/background.jpg path_wallpaper=~/.local/share/backgrounds/background.jpg
cp "$1" $path_wallpaper cp "$1" $path_wallpaper
chmod 644 $path_wallpaper chmod 644 $path_wallpaper