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

View file

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

View file

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

View file

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

View file

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

View file

@ -19,21 +19,6 @@ export color_yellow="\033[0;33m"
export color_byellow="\033[1;33m"
# print all available colors with their names colored in corresponding color.
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"
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"
}

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.

View file

@ -19,48 +19,41 @@ alias dcs="docker compose stop"
# down & up specified services.
# usage: dcdu [SERVICES]
dcdu()
{
dcdu() {
dcd "${@}"
dcu "${@}"
}
# pull & up specified services.
# usage: dcpu [SERVICES]
dcpu()
{
dcpu() {
dcp "${@}"
dcu "${@}"
}
# up & attach to logs for specified services.
# usage: dcul [SERVICES]
dcul()
{
dcul() {
dcu "${@}" && dcl "${@}"
}
# find out container's IP address.
# usage: docker_up <CONTAINER NAME>
docker_ip()
{
docker_ip() {
docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' $1 | sed "s/^.//" | sed "s/.$//"
}
# update all docker images.
docker_update()
{
docker_update() {
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
}
# autocomplete.
_dc_services()
{
_dc_services() {
_autocomplete "$(docker compose config --services 2> /dev/null)"
}
_dc_containers()
{
_dc_containers() {
_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.
# usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>
ffmpeg_mux_audio()
{
ffmpeg_mux_audio() {
if [[ "$1" = "" ]]; then
echo "usage: ffmpeg_mux_audio <SOUND> <OUTPUT DIR>"
return 2
@ -12,8 +11,7 @@ ffmpeg_mux_audio()
# Mux cover into music file.
# Usage: ffmpeg_mux_cover <FORMAT> <COVER>
ffmpeg_mux_cover()
{
ffmpeg_mux_cover() {
if [[ "${1}" = "" ]]; then
echo "Usage: ffmpeg_mux_cover <FORMAT> <COVER>"
return 2
@ -43,8 +41,7 @@ ffmpeg_mux_cover()
# Change music metadata.
# Usage: ffmpeg_music_meta <FORMAT>
ffmpeg_music_meta()
{
ffmpeg_music_meta() {
if [[ "${1}" = "" ]]; then
echo "Usage: ffmpeg_music_meta <FORMAT>"
return 2
@ -74,21 +71,18 @@ ffmpeg_music_meta()
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}")
fps="${fps%%/*}"
echo "${fps}"
}
_ffprobe_keyint()
{
_ffprobe_keyint() {
local fps=$(_ffprobe_fps "${1}")
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}")
[[ "${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128
}

View file

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

View file

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

View file

@ -20,8 +20,7 @@ alias gp="git apply"
# alias to preview diff while adding. adds current dir by default.
# usage: ga [FILES]
ga()
{
ga() {
local target=${@}
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.
# usage: gr [COMMIT COUNT]
gr()
{
gr() {
local base="${1}"
# rebase last 2 commits by default.
@ -53,8 +51,7 @@ gr()
# specify git user as Dmitry Voronin with provided email.
# usage: gu [EMAIL]
gu()
{
gu() {
local name="Dmitry Voronin"
local email="${1}"
@ -69,39 +66,33 @@ gu()
# Get my git repo.
# Usage: gg <REPO>
gg()
{
gg() {
git clone https://git.voronind.com/voronind/"${1}"
}
# See diff for a specific commit.
# Usage: gdc <COMMITHASH>
gdc()
{
gdc() {
git diff "${1}^!"
}
# Show current branch.
_git_current_branch()
{
_git_current_branch() {
git branch --show-current 2> /dev/null
}
# Show origin's url.
_git_origin_url()
{
_git_origin_url() {
git remote get-url origin
}
# Get this dotfiles url.
_git_dotfiles_url()
{
_git_dotfiles_url() {
echo 'https://git.voronind.com/voronind/linux.git'
}
# Check if current git repo is this dotfiles.
_git_is_dotfiles()
{
_git_is_dotfiles() {
# [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]]
local dir="${PWD}"
@ -119,27 +110,26 @@ _git_is_dotfiles()
}
# autocomplete.
_completion_loader git &> /dev/null
__git_complete gps _git_push &> /dev/null
__git_complete gpsf _git_push &> /dev/null
__git_complete gpl _git_pull &> /dev/null
__git_complete gl _git_log &> /dev/null
__git_complete gs _git_status &> /dev/null
__git_complete gst _git_stash &> /dev/null
__git_complete gd _git_diff &> /dev/null
__git_complete gdc _git_diff &> /dev/null
__git_complete gc _git_commit &> /dev/null
__git_complete gch _git_checkout &> /dev/null
_completion_loader git &> /dev/null
__git_complete gps _git_push &> /dev/null
__git_complete gpsf _git_push &> /dev/null
__git_complete gpl _git_pull &> /dev/null
__git_complete gl _git_log &> /dev/null
__git_complete gs _git_status &> /dev/null
__git_complete gst _git_stash &> /dev/null
__git_complete gd _git_diff &> /dev/null
__git_complete gdc _git_diff &> /dev/null
__git_complete gc _git_commit &> /dev/null
__git_complete gch _git_checkout &> /dev/null
__git_complete gchb _git_checkout &> /dev/null
__git_complete gb _git_branch &> /dev/null
__git_complete gbd _git_branch &> /dev/null
__git_complete gf _git_fetch &> /dev/null
__git_complete gt _git_tag &> /dev/null
__git_complete gp _git_apply &> /dev/null
__git_complete ga _git_add &> /dev/null
__git_complete gb _git_branch &> /dev/null
__git_complete gbd _git_branch &> /dev/null
__git_complete gf _git_fetch &> /dev/null
__git_complete gt _git_tag &> /dev/null
__git_complete gp _git_apply &> /dev/null
__git_complete ga _git_add &> /dev/null
_gu()
{
_gu() {
_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
# list files in dir.
l()
{
l() {
ls -lhv --si --group-directories-first "$@"
}
# list last modified files first.
ll()
{
ll() {
ls -lhvtr --si "$@"
}
# list files in tree structure.
# usage: lll [DEPTH] [DIRS]
lll()
{
lll() {
local IFS=$'\n'
local depth="${1}"
local target=("${@:2}")
@ -30,20 +27,17 @@ lll()
}
# list files recursively.
llll()
{
llll() {
ls -RlAhv --si --group-directories-first "$@"
}
# list all files in dir, incl. hidden files.
la()
{
la() {
ls -lAh --si --group-directories-first "$@"
}
# list all files in dir, incl. hidden files, sorted by mtime.
lla()
{
lla() {
ls -lAhtr --si "$@"
}

View file

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

View file

@ -1,11 +1,9 @@
# 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
}
# 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
}

View file

@ -1,7 +1,6 @@
# change file ownership to specified user id and restrict access to him.
# usage: own [USER] [FILES]
own()
{
own() {
local file="${2}"
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.
# Usage: pack <TARGET.ext> [FILES]
pack()
{
pack() {
local IFS=$'\n'
local output="${1}"
local targets=("${@:2}")
@ -62,8 +61,7 @@ pack()
# attempt to unpack everything.
# usage: unpack [FILES]
unpack()
{
unpack() {
local IFS=$'\n'
local targets=("${@}")
local count=0
@ -142,78 +140,63 @@ unpack()
fi
}
_pack_zip()
{
_pack_zip() {
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}"
}
_pack_txz()
{
_pack_txz() {
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}"
}
_pack_gz()
{
_pack_gz() {
pv "${2}" | gzip -1 > "${1}"
}
_pack_xz()
{
_pack_xz() {
pv "${2}" | xz -9e > "${1}"
}
_unpack_zip()
{
_unpack_zip() {
unzip "${1}"
}
_unpack_7z()
{
_unpack_7z() {
7za x "${1}"
}
_unpack_tgz()
{
_unpack_tgz() {
pv "${1}" | gzip -d | tar -xf -
}
_unpack_txz()
{
_unpack_txz() {
pv "${1}" | xz -d | tar -xf -
}
_unpack_tar()
{
_unpack_tar() {
pv "${1}" | tar -xf -
}
_unpack_iso()
{
_unpack_iso() {
7za x "${1}"
}
_unpack_rar()
{
_unpack_rar() {
unrar x "${1}"
}
_unpack_gz()
{
_unpack_gz() {
pv "${1}" | gzip -d > "${1%.gz}"
}
_unpack_xz()
{
_unpack_xz() {
pv "${1}" | xz -d > "${1%.xz}"
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,5 @@
# create/attach to named session.
ta()
{
ta() {
local name="$1"
# set default name.
@ -20,8 +19,7 @@ alias tl="tmux list-sessions"
# Rename current session. Uses current dir name by default.
# Usage: trn [NAME]
trn()
{
trn() {
local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}"
@ -31,8 +29,7 @@ trn()
# Assign name (to window). Uses current dir name by default.
# Usage: tn [NAME]
tn()
{
tn() {
local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}"
@ -41,8 +38,7 @@ tn()
}
# kill specified session or default one.
tk()
{
tk() {
# set default name.
if [[ "${1}" = "" ]]; then
1="main"
@ -55,8 +51,7 @@ tk()
}
# kill all sessions.
tka()
{
tka() {
local sessions=$(tmux list-sessions | sed -e 's/:.*//')
for session in $sessions; do
@ -65,18 +60,15 @@ tka()
}
# autocompletes.
_complete_tmux_session()
{
_complete_tmux_session() {
_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/:.*//')"
}
_complete_tmux_name()
{
_complete_tmux_name() {
_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.
# usage: tb [NAME]
tba()
{
tba() {
local name="${1}"
# set default name.
@ -39,8 +38,7 @@ tba()
# remove toolbx container with default or specified name.
# usage: tbk [NAME]
tbk()
{
tbk() {
local name="${1}"
# set default name.
@ -54,8 +52,7 @@ tbk()
# install rpm-fusion repository.
# usage: tb_rpmfusion [NAME]
tb_rpmfusion()
{
tb_rpmfusion() {
local name="${1}"
# set default name.
@ -71,8 +68,7 @@ tb_rpmfusion()
alias tbl="toolbox list -c"
# autocomplete.
_tb_containers()
{
_tb_containers() {
_autocomplete_first "$(toolbox list -c | sed -e '1d' | awk '{ print $2 }')"
}

View file

@ -1,7 +1,6 @@
# Convert between different formats.
# Usage: transcode <FORMAT> [FILES]
transcode()
{
transcode() {
local IFS=$'\n'
local targets=("${@:2}")
local format="${1}"
@ -91,38 +90,32 @@ transcode()
fi
}
_transcode_gz-xz()
{
_transcode_gz-xz() {
[[ -f "${2}" ]] && return 1
pv "${1}" | gzip -d | xz -9e > "${2}"
}
_transcode_xz-gz()
{
_transcode_xz-gz() {
[[ -f "${2}" ]] && return 1
pv "${1}" | xz -d | gzip -1 > "${2}"
}
_transcode_mp3()
{
_transcode_mp3() {
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}"
}
_transcode_mka()
{
_transcode_mka() {
local braudio=$(_ffprobe_ba "${1}")
[[ ${braudio} -gt 128 ]] && braudio=128
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 braudio=$(_ffprobe_ba "${1}")
[[ ${braudio} -gt 128 ]] && braudio=128

View file

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

View file

@ -1,5 +1,4 @@
# Get the number of avaialble cores (threads).
_core_count()
{
_core_count() {
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.
# Usage: vdl [LINK]
vdl()
{
vdl() {
# Check that ffmpeg and ffprobe are available.
if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then
echo -e "${color_red}ffmpeg and ffprobe are required.${color_default}"

View file

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