bash : add help function.

This commit is contained in:
Dmitry Voronin 2023-12-07 01:44:42 +03:00
parent 607ed8b9de
commit bf8c65e275
48 changed files with 229 additions and 224 deletions

View file

@ -497,6 +497,7 @@ Command|Description
Command|Description Command|Description
---|--- ---|---
`find_ext`|Find all file extensions recursively. `find_ext`|Find all file extensions recursively.
`find_function`|Find all dotfiles functions.
## Fix. ## Fix.
@ -536,6 +537,13 @@ Command|Description
`gg <REPO>`|Get git repo from my own git. `gg <REPO>`|Get git repo from my own git.
`ggc`|Run git garbage collection. `ggc`|Run git garbage collection.
## Help.
Command|Description
---|---
`help <FUNCTION>`|Get help for a dotfile function.
`h <FUNCTION>`|Same as `help`.
## Ls. ## Ls.
Command|Description Command|Description

27
.bashrc
View file

@ -1,21 +1,18 @@
#!/bin/bash
# If not running interactively, don't do anything. # If not running interactively, don't do anything.
[[ "$-" != *i* ]] && return [[ "$-" != *i* ]] && return
#home="/var/home/voronind" # Src system bashrc.
home="${HOME}" [[ -f /etc/bashrc ]] && source /etc/bashrc
module="${home}/.config/bash/module/*.sh"
# src default # Src custom modules.
if [[ -f /etc/bashrc ]]; then for module in ${HOME}/.config/bash/module/*.sh; do
source /etc/bashrc source "${module}"
fi
# src custom
for file in ${module}; do
source "${file}"
done done
# alias to reload # Alias to reload.
alias bashrc="source ~/.bashrc" function bashrc() {
source ~/.bashrc
}
# Export all functions.
export -f $(find_functions | tr '\n' ' ')

View file

@ -1,3 +1,3 @@
emulator() { function emulator() {
${ANDROID_SDK_ROOT}/emulator/emulator -avd default &> /dev/null & disown ${ANDROID_SDK_ROOT}/emulator/emulator -avd default &> /dev/null & disown
} }

View file

@ -1,11 +1,12 @@
_ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z" export _ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z"
_ARCHIVE_DATE() {
function _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() { function archive() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -52,7 +53,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() { function archive_fast() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -99,7 +100,7 @@ archive_fast() {
# check archive hashes. # check archive hashes.
# usage: archive_check [FILES] # usage: archive_check [FILES]
archive_check() { function archive_check() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local total=${#} local total=${#}
@ -143,7 +144,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() { function archive_prune() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -194,7 +195,7 @@ archive_prune() {
# extract previously created archive with checksum validation. # extract previously created archive with checksum validation.
# usage: unarchive [FILES] # usage: unarchive [FILES]
unarchive() { function unarchive() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -260,7 +261,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() { function archive_name() {
local IFS=$'\n' local IFS=$'\n'
local targets="${1}" local targets="${1}"
local name="${2}" local name="${2}"
@ -323,7 +324,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() { function 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}))
@ -365,7 +366,7 @@ archive_convert() {
done done
} }
_archive_parse() { function _archive_parse() {
local input="${1}" local input="${1}"
local name="${input%_*}" local name="${input%_*}"
local format="${input##*.}" local format="${input##*.}"
@ -379,12 +380,7 @@ _archive_parse() {
echo "${format}" echo "${format}"
} }
# export everything, primarily for use with parallel.. function _archive_name() {
export -f archive archive_fast archive_check unarchive archive_name _ARCHIVE_DATE
export _ARCHIVE_PATTERN
# autocomplete.
_archive_name() {
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=() COMPREPLY=()
@ -402,7 +398,7 @@ _archive_name() {
fi fi
} }
_archive_grep() { function _archive_grep() {
_autocomplete_grep ${_ARCHIVE_PATTERN} _autocomplete_grep ${_ARCHIVE_PATTERN}
} }

View file

@ -1,7 +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() { function _autocomplete() {
local IFS=$'\n' local IFS=$'\n'
local commands="${*}" local commands="${*}"
@ -16,7 +16,7 @@ _autocomplete() {
} }
# autocomplete only first argument. # autocomplete only first argument.
_autocomplete_first() { function _autocomplete_first() {
local IFS=$'\n' local IFS=$'\n'
local commands="${*}" local commands="${*}"
@ -33,7 +33,7 @@ _autocomplete_first() {
} }
# Autocomplete by grepping file names. # Autocomplete by grepping file names.
_autocomplete_grep() { function _autocomplete_grep() {
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=() COMPREPLY=()
@ -47,7 +47,7 @@ _autocomplete_grep() {
} }
# autocomplete nested program. # autocomplete nested program.
_autocomplete_nested() { function _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,4 +1,4 @@
# check battery level. # check battery level.
battery_level() { function battery_level() {
cat /sys/class/power_supply/BAT*/capacity cat /sys/class/power_supply/BAT*/capacity
} }

View file

@ -1,11 +1,11 @@
# install Cargo/Rust. # install Cargo/Rust.
bootstrap_rust() { function 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() { function 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
@ -15,13 +15,13 @@ bootstrap_texlive() {
} }
# install grub theme. # install grub theme.
bootstrap_grub() { function 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() { function bootstrap_ffmpeg() {
flatpak install org.kde.kdenlive flatpak install org.kde.kdenlive
} }

View file

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

View file

@ -1,6 +1,6 @@
# Save file checksums. # Save file checksums.
# Usage: checksum_create [FILES] # Usage: checksum_create [FILES]
checksum_create() { function checksum_create() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -46,7 +46,7 @@ checksum_create() {
} }
# Check stored values against actual files. # Check stored values against actual files.
checksum_check() { function checksum_check() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -95,17 +95,17 @@ checksum_check() {
fi fi
} }
checksum() { function checksum() {
find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1
} }
_checksum_create() { function _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() { function _checksum_check() {
local file="${1##*\ \ }" local file="${1##*\ \ }"
local stored="${1%%\ \ *}" local stored="${1%%\ \ *}"
@ -124,6 +124,3 @@ _checksum_check() {
return 0 return 0
} }
export -f checksum_create checksum_check
export -f _checksum_check _checksum_create

View file

@ -1,4 +1,4 @@
# add executable flag to file. # add executable flag to file.
x() { function x() {
chmod +x "${@}" chmod +x "${@}"
} }

View file

@ -19,6 +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() { function 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,24 +1,24 @@
# replace default cp with rsync. # replace default cp with rsync.
cp() { function cp() {
rsync -ahP --chmod=u+w -- "${@}" rsync -ahP --chmod=u+w -- "${@}"
} }
# copy and also merge all changes (delete dst files that do not exist in src). # copy and also merge all changes (delete dst files that do not exist in src).
cp_merge() { function cp_merge() {
rsync -ahP --chmod=u+w --delete -- "${@}" rsync -ahP --chmod=u+w --delete -- "${@}"
} }
# copy by creating hardlinks. # copy by creating hardlinks.
cp_link() { function cp_link() {
/usr/bin/cp -lr -- "${@}" /usr/bin/cp -lr -- "${@}"
} }
# default cp, a.k.a builtin cp. # default cp, a.k.a builtin cp.
bcp() { function bcp() {
/usr/bin/cp "${@}" /usr/bin/cp "${@}"
} }
# cp_merge without writing anything. # cp_merge without writing anything.
cp_test() { function cp_test() {
rsync -ahP --chmod=u+w --delete -n -- "${@}" rsync -ahP --chmod=u+w --delete -n -- "${@}"
} }

View file

@ -1,9 +1,9 @@
# print today date in yyyyMMdd format. # print today date in yyyyMMdd format.
today() { function today() {
date +%Y%m%d date +%Y%m%d
} }
# current day of week number. # current day of week number.
dow() { function dow() {
date +%u date +%u
} }

View file

@ -1,9 +1,9 @@
_GDCONF_PATH="${HOME}/.config/linux/gnome.dconf" export _GDCONF_PATH="${HOME}/.config/linux/gnome.dconf"
dconf_load() { function dconf_load() {
sed -i -e s/voronind/$(whoami)/g ${_GDCONF_PATH} ; dconf load / < ${_GDCONF_PATH} sed -i -e s/voronind/$(whoami)/g ${_GDCONF_PATH} ; dconf load / < ${_GDCONF_PATH}
} }
dconf_save() { function dconf_save() {
dconf dump / > gnome.dconf dconf dump / > gnome.dconf
} }

View file

@ -1,9 +1,9 @@
# show only physical drive sizes. # show only physical drive sizes.
df() { function df() {
df --si | sed -e '1p' -e "/^\/dev\//!d" df --si | sed -e '1p' -e "/^\/dev\//!d"
} }
# show combined size in SI. # show combined size in SI.
du() { function du() {
du -sh --si -- "${@}" du -sh --si -- "${@}"
} }

View file

@ -1,91 +1,90 @@
# show container's volumes. # show container's volumes.
docker_volumes() { function docker_volumes() {
docker inspect -f '{{ .Mounts }}' "${@}" docker inspect -f '{{ .Mounts }}' "${@}"
} }
# Check if any container exited. # Check if any container exited.
docker_health() { function docker_health() {
docker ps -a | grep Exited docker ps -a | grep Exited
} }
# prune everything. # prune everything.
docker_prune() { function docker_prune() {
docker system prune --volumes --all docker system prune --volumes --all
} }
# Docker compose shortcut. # Docker compose shortcut.
# Usage: dc [SERVICE] # Usage: dc [SERVICE]
dc() { function dc() {
docker compose "${@}" docker compose "${@}"
} }
# Docker compose up. # Docker compose up.
dcu() { function dcu() {
docker compose up -d "${@}" docker compose up -d "${@}"
} }
# Docker compose down. # Docker compose down.
dcd() { function dcd() {
docker compose down "${@}" docker compose down "${@}"
} }
# Docker compose pull. # Docker compose pull.
dcp() { function dcp() {
docker compose pull "${@}" docker compose pull "${@}"
} }
# Docker compose logs. # Docker compose logs.
dcl() { function dcl() {
docker compose logs -f "${@}" docker compose logs -f "${@}"
} }
# Docker compose restart. # Docker compose restart.
dcr() { function dcr() {
docker compose restart "${@}" docker compose restart "${@}"
} }
# Docker compose stop. # Docker compose stop.
dcs() { function dcs() {
docker compose stop "${@}" docker compose stop "${@}"
} }
# Docker compose down & up specified services. # Docker compose down & up specified services.
# Usage: dcdu [SERVICES] # Usage: dcdu [SERVICES]
dcdu() { function dcdu() {
dcd "${@}" dcd "${@}"
dcu "${@}" dcu "${@}"
} }
# Docker compose pull & up specified services. # Docker compose pull & up specified services.
# Usage: dcpu [SERVICES] # Usage: dcpu [SERVICES]
dcpu() { function dcpu() {
dcp "${@}" dcp "${@}"
dcu "${@}" dcu "${@}"
} }
# Docker compose up & attach to logs for specified services. # Docker compose up & attach to logs for specified services.
# Usage: dcul [SERVICES] # Usage: dcul [SERVICES]
dcul() { function 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() { function 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() { function docker_update() {
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
} }
# autocomplete. function _dc_services() {
_dc_services() {
_autocomplete "$(docker compose config --services 2> /dev/null)" _autocomplete "$(docker compose config --services 2> /dev/null)"
} }
_dc_containers() { function _dc_containers() {
_autocomplete "$(docker ps --format "\""{{.Names}}"\"")" _autocomplete "$(docker ps --format "\""{{.Names}}"\"")"
} }

View file

@ -1,5 +1,5 @@
# add all links in ~/app/bin/ # add all links in ~/app/bin/
PATH=$( find -L $HOME/app/bin/ -type d -printf ":%p" 2> /dev/null ):$PATH export PATH=$( find -L $HOME/app/bin/ -type d -printf ":%p" 2> /dev/null ):$PATH
# specify locale. # specify locale.
#export LC_ALL=C #export LC_ALL=C
@ -23,3 +23,6 @@ export ANDROID_SDK_ROOT="$HOME/.android/sdk"
export TEXMFVAR="$HOME/app/tex/data/var" export TEXMFVAR="$HOME/app/tex/data/var"
export TEXMFCONFIG="$HOME/app/tex/data/config" export TEXMFCONFIG="$HOME/app/tex/data/config"
export TEXMFLOCAL="$HOME/app/tex/data/local" export TEXMFLOCAL="$HOME/app/tex/data/local"
# Dotfiles exports.
export DOTFILES_PATH="${HOME}/.config/bash/module"

View file

@ -1,6 +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() { function 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
@ -11,7 +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() { function 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
@ -41,7 +41,7 @@ ffmpeg_mux_cover() {
# Change music metadata. # Change music metadata.
# Usage: ffmpeg_music_meta <FORMAT> # Usage: ffmpeg_music_meta <FORMAT>
ffmpeg_music_meta() { function 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
@ -71,7 +71,7 @@ ffmpeg_music_meta() {
rm -d out/ rm -d out/
} }
_ffprobe_fps() { function _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}"
@ -82,9 +82,7 @@ _ffprobe_keyint() {
echo $((fps*5)) echo $((fps*5))
} }
_ffprobe_ba() { function _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
} }
export -f _ffprobe_keyint _ffprobe_ba _ffprobe_fps

View file

@ -1,5 +1,5 @@
# Open file/dir in GUI. # Open file/dir in GUI.
# Usage: o <FILE> # Usage: o <FILE>
o() { function o() {
xdg-open "${@}" xdg-open "${@}"
} }

View file

@ -1,5 +1,10 @@
# Find all file extensions. # Find all file extensions.
find_ext() { function 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
} }
# Find all module functions.
function find_functions() {
cat "${DOTFILES_PATH}"/* | grep "^function.*()" | sed -e "s/^function //" -e "s/().*//"
}

View file

@ -1,7 +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() { function fix_ethernet_speed() {
local device="${1}" local device="${1}"
local speed="${2}" local speed="${2}"
@ -15,6 +15,6 @@ fix_ethernet_speed() {
# fix files wrong sftp password. # fix files wrong sftp password.
# alias fix_files_sftp="secret-tool clear protocol sftp server 192.168.1.2" # alias fix_files_sftp="secret-tool clear protocol sftp server 192.168.1.2"
fix_files_sftp() { function fix_files_sftp() {
secret-tool clear protocol sftp secret-tool clear protocol sftp
} }

View file

@ -1,103 +1,103 @@
# Git push. # Git push.
gps() { function gps() {
git push "${@}" git push "${@}"
} }
# Git force push. # Git force push.
gpsf() { function gpsf() {
git push --force "${@}" git push --force "${@}"
} }
# Git pull. # Git pull.
gpl() { function gpl() {
git pull "${@}" git pull "${@}"
} }
# Git log. # Git log.
gl() { function gl() {
git log "${@}" git log "${@}"
} }
# Git status. # Git status.
gs() { function gs() {
git status "${@}" git status "${@}"
} }
# Git stash. # Git stash.
gst() { function gst() {
git stash "${@}" git stash "${@}"
} }
# Git diff. # Git diff.
gd() { function gd() {
git diff "${@}" git diff "${@}"
} }
# Git commit. # Git commit.
gc() { function gc() {
git commit -m "${@}" git commit -m "${@}"
} }
# Git checkout. # Git checkout.
gch() { function gch() {
git checkout "${@}" git checkout "${@}"
} }
# Git checkout branch. # Git checkout branch.
gchb() { function gchb() {
git checkout -b "${@}" git checkout -b "${@}"
} }
# Git branch. # Git branch.
gb() { function gb() {
git branch --all "${@}" git branch --all "${@}"
} }
# Git branch delete. # Git branch delete.
gbd() { function gbd() {
git branch -D "${@}" git branch -D "${@}"
} }
# Git branch delete all except current. # Git branch delete all except current.
gbda() { function gbda() {
git branch | grep -v ^* | xargs git branch -D git branch | grep -v ^* | xargs git branch -D
} }
# Git fetch all. # Git fetch all.
gf() { function gf() {
git fetch --all -v -p git fetch --all -v -p
} }
# Git tag. # Git tag.
gt() { function gt() {
git tag "${@}" git tag "${@}"
} }
# Git ignore files. # Git ignore files.
gi() { function gi() {
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
} }
# Git patch create. # Git patch create.
# Usage: gpc <FILE> # Usage: gpc <FILE>
gpc() { function gpc() {
git diff > "${@}" git diff > "${@}"
} }
# Git patch (apply). # Git patch (apply).
# Usage: gp <FILE> # Usage: gp <FILE>
gp() { function gp() {
git apply "${@}" git apply "${@}"
} }
# Run git garbage collection. # Run git garbage collection.
ggc() { function ggc() {
git gc --aggressive --no-cruft --prune=now git gc --aggressive --no-cruft --prune=now
} }
# Preview diff while adding. adds current dir by default. # Preview diff while adding. adds current dir by default.
# Usage: ga [FILES] # Usage: ga [FILES]
ga() { function ga() {
local target=${@} local target=${@}
if [[ "${target}" = "" ]]; then if [[ "${target}" = "" ]]; then
@ -110,7 +110,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() { function gr() {
local base="${1}" local base="${1}"
# rebase last 2 commits by default. # rebase last 2 commits by default.
@ -128,7 +128,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() { function gu() {
local name="Dmitry Voronin" local name="Dmitry Voronin"
local email="${1}" local email="${1}"
@ -143,33 +143,33 @@ gu() {
# Get my git repo. # Get my git repo.
# Usage: gg <REPO> # Usage: gg <REPO>
gg() { function 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() { function gdc() {
git diff "${1}^!" git diff "${1}^!"
} }
# Show current branch. # Show current branch.
_git_current_branch() { function _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() { function _git_origin_url() {
git remote get-url origin git remote get-url origin
} }
# Get this dotfiles url. # Get this dotfiles url.
_git_dotfiles_url() { function _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() { function _git_is_dotfiles() {
# [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]] # [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]]
local dir="${PWD}" local dir="${PWD}"
@ -206,7 +206,7 @@ __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() { function _gu() {
_autocomplete_first account@voronind.com dd.voronin@fsight.ru _autocomplete_first account@voronind.com dd.voronin@fsight.ru
} }

View file

@ -1 +1,16 @@
# TODO: Help function that parses help header from modules. # Get help about bash function.
function help() {
local fun="${1}"
if [[ $(find_functions | grep "${fun}") = "" ]]; then
echo "Function not found."
return 1
fi
sed -e '$s/$/\n/' -s "${DOTFILES_PATH}"/* | sed -n -e "/function ${fun}()/q;p" | tac | sed -n -e "/^$/q;p" | tac | sed -e "s/^# \+//"
}
# Short for help.
function h() {
help "${@}"
}

View file

@ -3,18 +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() { function l() {
ls -lhv --si --group-directories-first "$@" ls -lhv --si --group-directories-first "$@"
} }
# list last modified files first. # list last modified files first.
ll() { function 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() { function lll() {
local IFS=$'\n' local IFS=$'\n'
local depth="${1}" local depth="${1}"
local target=("${@:2}") local target=("${@:2}")
@ -27,19 +27,16 @@ lll() {
} }
# list files recursively. # list files recursively.
llll() { function 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() { function 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() { function lla() {
ls -lAhtr --si "$@" ls -lAhtr --si "$@"
} }
# export.
export -f l ll lll llll la lla

View file

@ -1,6 +1,6 @@
# rename files to strip all special characters. # rename files to strip all special characters.
# usage: name [FILES] # usage: name [FILES]
name() { function name() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -64,7 +64,7 @@ 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() { function name_hash() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -124,7 +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() { function 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.
@ -166,7 +166,7 @@ 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() { function name_series() {
local IFS=$'\n' local IFS=$'\n'
local season="${1}" local season="${1}"
local targets=("${@:2}") local targets=("${@:2}")
@ -220,7 +220,7 @@ 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() { function name_manga() {
local IFS=$'\n' local IFS=$'\n'
local season="${1}" local season="${1}"
local targets=("${@:2}") local targets=("${@:2}")
@ -275,7 +275,7 @@ name_manga() {
# rename files for new extension. # rename files for new extension.
# usage: name_ext <EXTENSION> [FILES] # usage: name_ext <EXTENSION> [FILES]
name_ext() { function name_ext() {
local IFS=$'\n' local IFS=$'\n'
local extension="${1}" local extension="${1}"
local targets=("${@:2}") local targets=("${@:2}")
@ -327,7 +327,7 @@ name_ext() {
# Change file prefixes. # Change file prefixes.
# Usage: name_prefix <OLD> <NEW> [FILES] # Usage: name_prefix <OLD> <NEW> [FILES]
name_prefix() { function name_prefix() {
local IFS=$'\n' local IFS=$'\n'
local old="${1}" local old="${1}"
local new="${2}" local new="${2}"
@ -374,7 +374,7 @@ name_prefix() {
# Change file postfix. # Change file postfix.
# Usage: name_postfix <OLD> <NEW> [FILES] # Usage: name_postfix <OLD> <NEW> [FILES]
name_postfix() { function name_postfix() {
local IFS=$'\n' local IFS=$'\n'
local old="${1}" local old="${1}"
local new="${2}" local new="${2}"
@ -420,7 +420,7 @@ name_postfix() {
} }
# Replace part of the name. # Replace part of the name.
name_replace() { function name_replace() {
local IFS=$'\n' local IFS=$'\n'
local old="${1}" local old="${1}"
local new="${2}" local new="${2}"
@ -463,8 +463,4 @@ name_replace() {
echo -e "${color_bred}Failed: ${failed}.${color_default}" echo -e "${color_bred}Failed: ${failed}.${color_default}"
false false
fi fi
} }
# export for parallel.
export -f name name_hash name_hash_check name_ext

View file

@ -1,4 +1,4 @@
# search only on current filesystem. # search only on current filesystem.
ncdu() { function ncdu() {
ncdu -x -- "${@}" ncdu -x -- "${@}"
} }

View file

@ -1,9 +1,9 @@
# send Telegram notification. # send Telegram notification.
notify() { function 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() { function 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,6 +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() { function own() {
local file="${2}" local file="${2}"
local user="${1}" local user="${1}"

View file

@ -1,8 +1,8 @@
_UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" export _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() { function pack() {
local IFS=$'\n' local IFS=$'\n'
local output="${1}" local output="${1}"
local targets=("${@:2}") local targets=("${@:2}")
@ -61,7 +61,7 @@ pack() {
# attempt to unpack everything. # attempt to unpack everything.
# usage: unpack [FILES] # usage: unpack [FILES]
unpack() { function unpack() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@}") local targets=("${@}")
local count=0 local count=0
@ -140,65 +140,62 @@ unpack() {
fi fi
} }
_pack_zip() { function _pack_zip() {
zip -9 -r "${@}" zip -9 -r "${@}"
} }
_pack_tgz() { function _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() { function _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() { function _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() { function _pack_gz() {
pv "${2}" | gzip -1 > "${1}" pv "${2}" | gzip -1 > "${1}"
} }
_pack_xz() { function _pack_xz() {
pv "${2}" | xz -9e > "${1}" pv "${2}" | xz -9e > "${1}"
} }
_unpack_zip() { function _unpack_zip() {
unzip "${1}" unzip "${1}"
} }
_unpack_7z() { function _unpack_7z() {
7za x "${1}" 7za x "${1}"
} }
_unpack_tgz() { function _unpack_tgz() {
pv "${1}" | gzip -d | tar -xf - pv "${1}" | gzip -d | tar -xf -
} }
_unpack_txz() { function _unpack_txz() {
pv "${1}" | xz -d | tar -xf - pv "${1}" | xz -d | tar -xf -
} }
_unpack_tar() { function _unpack_tar() {
pv "${1}" | tar -xf - pv "${1}" | tar -xf -
} }
_unpack_iso() { function _unpack_iso() {
7za x "${1}" 7za x "${1}"
} }
_unpack_rar() { function _unpack_rar() {
unrar x "${1}" unrar x "${1}"
} }
_unpack_gz() { function _unpack_gz() {
pv "${1}" | gzip -d > "${1%.gz}" pv "${1}" | gzip -d > "${1%.gz}"
} }
_unpack_xz() { function _unpack_xz() {
pv "${1}" | xz -d > "${1%.xz}" pv "${1}" | xz -d > "${1%.xz}"
} }
# export functions.
export -f pack unpack _pack_tgz _pack_txz _pack_tar _pack_zip _unpack_zip _unpack_7z _unpack_tgz _unpack_txz _unpack_tar _unpack_iso _unpack_rar _pack_gz _pack_xz _unpack_gz _unpack_xz

View file

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

View file

@ -1,9 +1,9 @@
# recursively change permissions to allow read sharing with group and others. # recursively change permissions to allow read sharing with group and others.
perm_share() { function perm_share() {
find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \;
} }
# recursively change permissions to restrict access for group and others. # recursively change permissions to restrict access for group and others.
perm() { function perm() {
find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \; find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \;
} }

View file

@ -1,3 +1,3 @@
ps() { function ps() {
ps aux | grep "${@}" ps aux | grep "${@}"
} }

View file

@ -1,7 +1,7 @@
PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}") export PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}")
# custom terminal prompt format. # custom terminal prompt format.
__prompt_command() { function __prompt_command() {
local last_status="${?}" local last_status="${?}"
local is_error=false local is_error=false
local is_root=false local is_root=false
@ -80,7 +80,7 @@ __prompt_command() {
fi fi
} }
_ps1error() { function _ps1error() {
local type local type
case ${1} in case ${1} in
1) type="GENERAL" ;; 1) type="GENERAL" ;;

View file

@ -1,6 +1,6 @@
# Run something recursively over all directories. # Run something recursively over all directories.
# Usage: recursive <COMMAND> # Usage: recursive <COMMAND>
recursive() { function recursive() {
local IFS=$'\n' local IFS=$'\n'
local current="${PWD}" local current="${PWD}"
local dirs=$(find -type d) local dirs=$(find -type d)
@ -32,7 +32,7 @@ recursive() {
# Run something recursively over all directories. # Run something recursively over all directories.
# Usage: recursive1 <COMMAND> # Usage: recursive1 <COMMAND>
# TODO: create generic function. # TODO: create generic function.
recursive1() { 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,4 +1,4 @@
# Open Rust book. # Open Rust book.
rust_book() { function rust_book() {
rustup docs --book rustup docs --book
} }

View file

@ -1,4 +1,4 @@
# I'm lazy af. # I'm lazy af.
s() { function s() {
su su
} }

View file

@ -1,4 +1,4 @@
tsize() { function 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,5 +1,5 @@
# CD into host's primary tmp dir. # CD into host's primary tmp dir.
tmp() { function tmp() {
local host="${HOSTNAME}" local host="${HOSTNAME}"
local tmp_path local tmp_path

View file

@ -1,5 +1,5 @@
# create/attach to named session. # create/attach to named session.
ta() { function ta() {
local name="$1" local name="$1"
# set default name. # set default name.
@ -12,18 +12,18 @@ ta() {
} }
# detach. # detach.
td() { function td() {
tmux detach-client tmux detach-client
} }
# list. # list.
tl() { function tl() {
tmux list-sessions 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() { function trn() {
local name="${1}" local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}" [[ "${name}" = "" ]] && name="${PWD##*/}"
@ -33,7 +33,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() { function tn() {
local name="${1}" local name="${1}"
[[ "${name}" = "" ]] && name="${PWD##*/}" [[ "${name}" = "" ]] && name="${PWD##*/}"
@ -42,7 +42,7 @@ tn() {
} }
# kill specified session or default one. # kill specified session or default one.
tk() { function tk() {
# set default name. # set default name.
if [[ "${1}" = "" ]]; then if [[ "${1}" = "" ]]; then
1="main" 1="main"
@ -55,7 +55,7 @@ tk() {
} }
# kill all sessions. # kill all sessions.
tka() { function 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
@ -64,15 +64,15 @@ tka() {
} }
# autocompletes. # autocompletes.
_complete_tmux_session() { function _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() { function _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() { function _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,4 +1,4 @@
# Open ~/.todo.md file. # Open ~/.todo.md file.
todo() { function todo() {
vi ~/.todo.md vi ~/.todo.md
} }

View file

@ -1,6 +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() { function tba() {
local name="${1}" local name="${1}"
# set default name. # set default name.
@ -38,7 +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() { function tbk() {
local name="${1}" local name="${1}"
# set default name. # set default name.
@ -52,7 +52,7 @@ tbk() {
# install rpm-fusion repository. # install rpm-fusion repository.
# usage: tb_rpmfusion [NAME] # usage: tb_rpmfusion [NAME]
tb_rpmfusion() { function tb_rpmfusion() {
local name="${1}" local name="${1}"
# set default name. # set default name.
@ -65,12 +65,12 @@ tb_rpmfusion() {
} }
# list all containers. # list all containers.
tbl() { function tbl() {
toolbox list -c toolbox list -c
} }
# autocomplete. # autocomplete.
_tb_containers() { function _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,6 +1,6 @@
# Convert between different formats. # Convert between different formats.
# Usage: transcode <FORMAT> [FILES] # Usage: transcode <FORMAT> [FILES]
transcode() { function transcode() {
local IFS=$'\n' local IFS=$'\n'
local targets=("${@:2}") local targets=("${@:2}")
local format="${1}" local format="${1}"
@ -90,32 +90,32 @@ transcode() {
fi fi
} }
_transcode_gz-xz() { function _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() { function _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() { function _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() { function _transcode_flac() {
ffmpeg -n -i "${1}" -c:a flac -f flac "${2}" ffmpeg -n -i "${1}" -c:a flac -f flac "${2}"
} }
_transcode_mka() { function _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() { function _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
@ -123,6 +123,3 @@ _transcode_mkv() {
# ffmpeg -n -i "${1}" -c:a libopus -b:a ${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -preset 8 -pix_fmt yuv420p10le -g ${keyint} -vf "scale=-2:min'(1080,ih)'" "${2}" # ffmpeg -n -i "${1}" -c:a libopus -b:a ${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -preset 8 -pix_fmt yuv420p10le -g ${keyint} -vf "scale=-2:min'(1080,ih)'" "${2}"
ffmpeg -n -i "${1}" -map 0 -map -v -map V -map -t -c:s srt -ac 2 -c:a libopus -b:a ${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -pix_fmt yuv420p10le -g ${keyint} -vf "scale=-2:min'(1080,ih)'" "${2}" ffmpeg -n -i "${1}" -map 0 -map -v -map V -map -t -c:s srt -ac 2 -c:a libopus -b:a ${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -pix_fmt yuv420p10le -g ${keyint} -vf "scale=-2:min'(1080,ih)'" "${2}"
} }
# Export.
export -f transcode _transcode_gz-xz _transcode_xz-gz _transcode_mp3 _transcode_flac _transcode_mka _transcode_mkv

View file

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

View file

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

View file

@ -1,6 +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() { function 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}"
@ -26,12 +26,12 @@ vdl() {
yt-dlp -f 'bestvideo[height<=?1081]+bestaudio/best' --download-archive index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ${target} # || _vdl_retry yt-dlp -f 'bestvideo[height<=?1081]+bestaudio/best' --download-archive index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ${target} # || _vdl_retry
} }
vdl_vk() { function vdl_vk() {
vdl --format mp4 "${@}" vdl --format mp4 "${@}"
} }
# Temporary fix for crashes. # Temporary fix for crashes.
_vdl_retry() { function _vdl_retry() {
for file in *.part; do for file in *.part; do
local number="${file%%_*}" local number="${file%%_*}"
rm ${number}* rm ${number}*
@ -40,6 +40,6 @@ _vdl_retry() {
} }
# download all videos from file. # download all videos from file.
vdl_file() { function vdl_file() {
vdl -a "${@}" vdl -a "${@}"
} }

View file

@ -1,9 +1,9 @@
# default vim. # default vim.
vi() { function vi() {
vi -c "filetype plugin indent on" -c "set autoindent" -c "set tabstop=2" -c "set shiftwidth=2" -c "set expandtab" -c "set number" -- "${@}" vi -c "filetype plugin indent on" -c "set autoindent" -c "set tabstop=2" -c "set shiftwidth=2" -c "set expandtab" -c "set number" -- "${@}"
} }
# neovim. # neovim.
v() { function v() {
nvim -- "${@}" nvim -- "${@}"
} }

View file

@ -1,5 +1,5 @@
# set specified file as a wallpaper. # set specified file as a wallpaper.
wallpaper() { function 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

View file

@ -1,12 +1,12 @@
# Watch command output with 2 second interval. # Watch command output with 2 second interval.
# Usage: w <COMMAND> # Usage: w <COMMAND>
w() { function w() {
watch -n 2 "${@}" watch -n 2 "${@}"
} }
# Watch command output with minimal interval. # Watch command output with minimal interval.
# Usage: ww <COMMAND> # Usage: ww <COMMAND>
ww() { function ww() {
watch -n 0 "${@}" watch -n 0 "${@}"
} }