bash : migrate to functions.
This commit is contained in:
parent
21018f0468
commit
607ed8b9de
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# check battery level.
|
||||
alias battery_level="cat /sys/class/power_supply/BAT0/capacity"
|
||||
battery_level() {
|
||||
cat /sys/class/power_supply/BAT*/capacity
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# add executable flag to file.
|
||||
alias x="chmod +x"
|
||||
x() {
|
||||
chmod +x "${@}"
|
||||
}
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
# 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).
|
||||
alias cp_merge="rsync -ahP --chmod=u+w --delete"
|
||||
cp_merge() {
|
||||
rsync -ahP --chmod=u+w --delete -- "${@}"
|
||||
}
|
||||
|
||||
# copy by creating hardlinks.
|
||||
alias cp_link="/usr/bin/cp -lr"
|
||||
cp_link() {
|
||||
/usr/bin/cp -lr -- "${@}"
|
||||
}
|
||||
|
||||
# default cp, a.k.a builtin cp.
|
||||
alias bcp="/usr/bin/cp"
|
||||
bcp() {
|
||||
/usr/bin/cp "${@}"
|
||||
}
|
||||
|
||||
# cp_merge without writing anything.
|
||||
alias cp_test="rsync -ahP --chmod=u+w --delete -n"
|
||||
cp_test() {
|
||||
rsync -ahP --chmod=u+w --delete -n -- "${@}"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# print today date in yyyyMMdd format.
|
||||
alias today="date +%Y%m%d"
|
||||
today() {
|
||||
date +%Y%m%d
|
||||
}
|
||||
|
||||
# current day of week number.
|
||||
alias dow="date +%u"
|
||||
dow() {
|
||||
date +%u
|
||||
}
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
_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.
|
||||
alias dconf_save="dconf dump / > gnome.dconf" # dump gnome settings to a file.
|
||||
dconf_load() {
|
||||
sed -i -e s/voronind/$(whoami)/g ${_GDCONF_PATH} ; dconf load / < ${_GDCONF_PATH}
|
||||
}
|
||||
|
||||
dconf_save() {
|
||||
dconf dump / > gnome.dconf
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# 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.
|
||||
alias du="du -sh --si"
|
||||
du() {
|
||||
du -sh --si -- "${@}"
|
||||
}
|
||||
|
|
|
@ -1,49 +1,81 @@
|
|||
# show container's volumes.
|
||||
alias docker_volumes="docker inspect -f '{{ .Mounts }}'"
|
||||
docker_volumes() {
|
||||
docker inspect -f '{{ .Mounts }}' "${@}"
|
||||
}
|
||||
|
||||
# check if container exited.
|
||||
alias docker_health="docker ps -a | grep Exited"
|
||||
# Check if any container exited.
|
||||
docker_health() {
|
||||
docker ps -a | grep Exited
|
||||
}
|
||||
|
||||
# prune everything.
|
||||
alias docker_prune="docker system prune --volumes --all"
|
||||
docker_prune() {
|
||||
docker system prune --volumes --all
|
||||
}
|
||||
|
||||
# short aliases.
|
||||
# usage: dc [SERVICE]
|
||||
alias dc="docker compose"
|
||||
alias dcu="docker compose up -d"
|
||||
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"
|
||||
# Docker compose shortcut.
|
||||
# Usage: dc [SERVICE]
|
||||
dc() {
|
||||
docker compose "${@}"
|
||||
}
|
||||
|
||||
# down & up specified services.
|
||||
# usage: dcdu [SERVICES]
|
||||
# Docker compose up.
|
||||
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() {
|
||||
dcd "${@}"
|
||||
dcu "${@}"
|
||||
}
|
||||
|
||||
# pull & up specified services.
|
||||
# usage: dcpu [SERVICES]
|
||||
# Docker compose pull & up specified services.
|
||||
# Usage: dcpu [SERVICES]
|
||||
dcpu() {
|
||||
dcp "${@}"
|
||||
dcu "${@}"
|
||||
}
|
||||
|
||||
# up & attach to logs for specified services.
|
||||
# usage: dcul [SERVICES]
|
||||
# Docker compose up & attach to logs for specified services.
|
||||
# Usage: dcul [SERVICES]
|
||||
dcul() {
|
||||
dcu "${@}" && dcl "${@}"
|
||||
}
|
||||
|
||||
# find out container's IP address.
|
||||
# usage: docker_up <CONTAINER NAME>
|
||||
# Find out container's IP address.
|
||||
# Usage: docker_up <CONTAINER NAME>
|
||||
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 images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# open file/dir in GUI.
|
||||
# usage: o <FILE>
|
||||
alias o="xdg-open"
|
||||
# Open file/dir in GUI.
|
||||
# Usage: o <FILE>
|
||||
o() {
|
||||
xdg-open "${@}"
|
||||
}
|
||||
|
|
|
@ -15,4 +15,6 @@ fix_ethernet_speed() {
|
|||
|
||||
# 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"
|
||||
fix_files_sftp() {
|
||||
secret-tool clear protocol sftp
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@ ggc() {
|
|||
git gc --aggressive --no-cruft --prune=now
|
||||
}
|
||||
|
||||
# alias to preview diff while adding. adds current dir by default.
|
||||
# usage: ga [FILES]
|
||||
# Preview diff while adding. adds current dir by default.
|
||||
# Usage: ga [FILES]
|
||||
ga() {
|
||||
local target=${@}
|
||||
|
||||
|
|
1
.config/bash/module/help.sh
Normal file
1
.config/bash/module/help.sh
Normal file
|
@ -0,0 +1 @@
|
|||
# TODO: Help function that parses help header from modules.
|
|
@ -1,2 +1,4 @@
|
|||
# search only on current filesystem.
|
||||
alias ncdu='ncdu -x'
|
||||
ncdu() {
|
||||
ncdu -x -- "${@}"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# 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.
|
||||
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 {} \;
|
||||
}
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
alias ps="ps aux | grep"
|
||||
ps() {
|
||||
ps aux | grep "${@}"
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# Open Rust book.
|
||||
alias rust_book="rustup docs --book"
|
||||
rust_book() {
|
||||
rustup docs --book
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# I'm lazy af.
|
||||
alias s='su'
|
||||
s() {
|
||||
su
|
||||
}
|
||||
|
|
|
@ -12,10 +12,14 @@ ta() {
|
|||
}
|
||||
|
||||
# detach.
|
||||
alias td="tmux detach-client"
|
||||
td() {
|
||||
tmux detach-client
|
||||
}
|
||||
|
||||
# list.
|
||||
alias tl="tmux list-sessions"
|
||||
tl() {
|
||||
tmux list-sessions
|
||||
}
|
||||
|
||||
# Rename current session. Uses current dir name by default.
|
||||
# Usage: trn [NAME]
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
alias todo="vi ~/.todo.md"
|
||||
# Open ~/.todo.md file.
|
||||
todo() {
|
||||
vi ~/.todo.md
|
||||
}
|
||||
|
|
|
@ -65,7 +65,9 @@ tb_rpmfusion() {
|
|||
}
|
||||
|
||||
# list all containers.
|
||||
alias tbl="toolbox list -c"
|
||||
tbl() {
|
||||
toolbox list -c
|
||||
}
|
||||
|
||||
# autocomplete.
|
||||
_tb_containers() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
alias vdl_vk="vdl --format mp4"
|
||||
vdl_vk() {
|
||||
vdl --format mp4 "${@}"
|
||||
}
|
||||
|
||||
# Temporary fix for crashes.
|
||||
_vdl_retry() {
|
||||
|
@ -38,4 +40,6 @@ _vdl_retry() {
|
|||
}
|
||||
|
||||
# download all videos from file.
|
||||
alias vdl_file="vdl -a"
|
||||
vdl_file() {
|
||||
vdl -a "${@}"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# 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.
|
||||
alias v="nvim"
|
||||
v() {
|
||||
nvim -- "${@}"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# short aliases.
|
||||
alias w='watch'
|
||||
alias ww='watch -n 0'
|
||||
# Watch command output with 2 second interval.
|
||||
# Usage: w <COMMAND>
|
||||
w() {
|
||||
watch -n 2 "${@}"
|
||||
}
|
||||
|
||||
# Watch command output with minimal interval.
|
||||
# Usage: ww <COMMAND>
|
||||
ww() {
|
||||
watch -n 0 "${@}"
|
||||
}
|
||||
|
||||
# autocomplete.
|
||||
complete -F _autocomplete_nested w ww
|
||||
|
|
Reference in a new issue