bash : migrate to functions.

This commit is contained in:
Dmitry Voronin 2023-12-07 00:42:06 +03:00
parent 21018f0468
commit 607ed8b9de
23 changed files with 163 additions and 60 deletions

View file

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

View file

@ -1,2 +1,4 @@
# check battery level. # check battery level.
alias battery_level="cat /sys/class/power_supply/BAT0/capacity" battery_level() {
cat /sys/class/power_supply/BAT*/capacity
}

View file

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

View file

@ -1,14 +1,24 @@
# replace default cp with rsync. # replace default cp with rsync.
alias cp="rsync -ahP --chmod=u+w" cp() {
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).
alias cp_merge="rsync -ahP --chmod=u+w --delete" cp_merge() {
rsync -ahP --chmod=u+w --delete -- "${@}"
}
# copy by creating hardlinks. # copy by creating hardlinks.
alias cp_link="/usr/bin/cp -lr" cp_link() {
/usr/bin/cp -lr -- "${@}"
}
# default cp, a.k.a builtin cp. # default cp, a.k.a builtin cp.
alias bcp="/usr/bin/cp" bcp() {
/usr/bin/cp "${@}"
}
# cp_merge without writing anything. # cp_merge without writing anything.
alias cp_test="rsync -ahP --chmod=u+w --delete -n" cp_test() {
rsync -ahP --chmod=u+w --delete -n -- "${@}"
}

View file

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

View file

@ -1,4 +1,9 @@
_GDCONF_PATH="${HOME}/.config/linux/gnome.dconf" _GDCONF_PATH="${HOME}/.config/linux/gnome.dconf"
alias dconf_load="sed -i -e s/voronind/$(whoami)/g ${_GDCONF_PATH} ; dconf load / < ${_GDCONF_PATH}" # load gnome settings. dconf_load() {
alias dconf_save="dconf dump / > gnome.dconf" # dump gnome settings to a file. sed -i -e s/voronind/$(whoami)/g ${_GDCONF_PATH} ; dconf load / < ${_GDCONF_PATH}
}
dconf_save() {
dconf dump / > gnome.dconf
}

View file

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

View file

@ -1,49 +1,81 @@
# show container's volumes. # show container's volumes.
alias docker_volumes="docker inspect -f '{{ .Mounts }}'" docker_volumes() {
docker inspect -f '{{ .Mounts }}' "${@}"
}
# check if container exited. # Check if any container exited.
alias docker_health="docker ps -a | grep Exited" docker_health() {
docker ps -a | grep Exited
}
# prune everything. # prune everything.
alias docker_prune="docker system prune --volumes --all" docker_prune() {
docker system prune --volumes --all
}
# short aliases. # Docker compose shortcut.
# usage: dc [SERVICE] # Usage: dc [SERVICE]
alias dc="docker compose" dc() {
alias dcu="docker compose up -d" docker compose "${@}"
alias dcd="docker compose down" }
alias dcp="docker compose pull"
alias dcl="docker compose logs -f"
alias dcr="docker compose restart"
alias dcs="docker compose stop"
# down & up specified services. # Docker compose up.
# usage: dcdu [SERVICES] dcu() {
docker compose up -d "${@}"
}
# Docker compose down.
dcd() {
docker compose down "${@}"
}
# Docker compose pull.
dcp() {
docker compose pull "${@}"
}
# Docker compose logs.
dcl() {
docker compose logs -f "${@}"
}
# Docker compose restart.
dcr() {
docker compose restart "${@}"
}
# Docker compose stop.
dcs() {
docker compose stop "${@}"
}
# Docker compose down & up specified services.
# Usage: dcdu [SERVICES]
dcdu() { dcdu() {
dcd "${@}" dcd "${@}"
dcu "${@}" dcu "${@}"
} }
# pull & up specified services. # Docker compose pull & up specified services.
# usage: dcpu [SERVICES] # Usage: dcpu [SERVICES]
dcpu() { dcpu() {
dcp "${@}" dcp "${@}"
dcu "${@}" dcu "${@}"
} }
# up & attach to logs for specified services. # Docker compose 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
} }

View file

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

View file

@ -15,4 +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"
alias fix_files_sftp="secret-tool clear protocol sftp" fix_files_sftp() {
secret-tool clear protocol sftp
}

View file

@ -95,8 +95,8 @@ ggc() {
git gc --aggressive --no-cruft --prune=now git gc --aggressive --no-cruft --prune=now
} }
# alias to 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() { ga() {
local target=${@} local target=${@}

View file

@ -0,0 +1 @@
# TODO: Help function that parses help header from modules.

View file

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

View file

@ -1,5 +1,9 @@
# recursively change permissions to allow read sharing with group and others. # recursively change permissions to allow read sharing with group and others.
alias perm_share="find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \;" perm_share() {
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.
alias perm="find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \;" perm() {
find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \;
}

View file

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

View file

@ -1,2 +1,4 @@
# Open Rust book. # Open Rust book.
alias rust_book="rustup docs --book" rust_book() {
rustup docs --book
}

View file

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

View file

@ -12,10 +12,14 @@ ta() {
} }
# detach. # detach.
alias td="tmux detach-client" td() {
tmux detach-client
}
# list. # list.
alias tl="tmux list-sessions" 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]

View file

@ -1 +1,4 @@
alias todo="vi ~/.todo.md" # Open ~/.todo.md file.
todo() {
vi ~/.todo.md
}

View file

@ -65,7 +65,9 @@ tb_rpmfusion() {
} }
# list all containers. # list all containers.
alias tbl="toolbox list -c" tbl() {
toolbox list -c
}
# autocomplete. # autocomplete.
_tb_containers() { _tb_containers() {

View file

@ -26,7 +26,9 @@ 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
} }
alias vdl_vk="vdl --format mp4" vdl_vk() {
vdl --format mp4 "${@}"
}
# Temporary fix for crashes. # Temporary fix for crashes.
_vdl_retry() { _vdl_retry() {
@ -38,4 +40,6 @@ _vdl_retry() {
} }
# download all videos from file. # download all videos from file.
alias vdl_file="vdl -a" vdl_file() {
vdl -a "${@}"
}

View file

@ -1,5 +1,9 @@
# default vim. # default vim.
alias 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() {
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.
alias v="nvim" v() {
nvim -- "${@}"
}

View file

@ -1,6 +1,14 @@
# short aliases. # Watch command output with 2 second interval.
alias w='watch' # Usage: w <COMMAND>
alias ww='watch -n 0' w() {
watch -n 2 "${@}"
}
# Watch command output with minimal interval.
# Usage: ww <COMMAND>
ww() {
watch -n 0 "${@}"
}
# autocomplete. # autocomplete.
complete -F _autocomplete_nested w ww complete -F _autocomplete_nested w ww