refactor(history): commit development branch
All checks were successful
/ job (push) Successful in 1m12s

new development branch from root commit
This commit is contained in:
Marc Beninca 2025-02-10 21:54:51 +01:00
parent 3e562930f6
commit 020aaa0b9a
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
94 changed files with 4804 additions and 0 deletions

95
sh/alias/apt.sh Normal file
View file

@ -0,0 +1,95 @@
# show package information
acl() { a__apt_cache_list "${@}"; }
a__apt_cache_list() {
apt-cache \
show \
"${@}"
}
# package versions policy
acp() { a__apt_cache_policy "${@}"; }
a__apt_cache_policy() {
apt-cache \
policy \
"${@}"
}
# search package
acs() { a__apt_cache_search "${@}"; }
a__apt_cache_search() {
apt-cache \
search \
"${@}"
}
#
agap() { a__apt_get_auto_purge "${@}"; }
a__apt_get_auto_purge() {
apt-get \
autopurge \
"${@}"
}
#
agar() { a__apt_get_auto_remove "${@}"; }
a__apt_get_auto_remove() {
apt-get \
autoremove \
"${@}"
}
# clean packages cache
agc() { a__apt_get_clean "${@}"; }
a__apt_get_clean() {
apt-get \
clean \
"${@}"
}
# upgrade allowing package installation or removal
agfu() { a__apt_get_full_upgrade "${@}"; }
a__apt_get_full_upgrade() {
apt-get \
full-upgrade \
"${@}"
}
# install packages
agi() { a__apt_get_install "${@}"; }
a__apt_get_install() {
apt-get \
install \
"${@}"
}
#
agp() { a__apt_get_purge "${@}"; }
a__apt_get_purge() {
apt-get \
purge \
"${@}"
}
#
agr() { a__apt_get_remove "${@}"; }
a__apt_get_remove() {
apt-get \
remove \
"${@}"
}
# update packages catalog
agud() { a__apt_get_up_date "${@}"; }
a__apt_get_up_date() {
apt-get \
update \
"${@}"
}
# upgrade forbidding package installation or removal
agug() { a__apt_get_up_grade "${@}"; }
a__apt_get_up_grade() {
apt-get \
upgrade \
"${@}"
}

5
sh/alias/batcat.sh Normal file
View file

@ -0,0 +1,5 @@
b() { a__bat "${@}"; }
a__bat() {
batcat \
"${@}"
}

73
sh/alias/btrfs.sh Normal file
View file

@ -0,0 +1,73 @@
bfdf() { a__btrfs_filesystem_d_f "${@}"; }
a__btrfs_filesystem_d_f() {
btrfs \
filesystem \
df \
"${@}"
}
bfdu() { a__btrfs_filesystem_d_u "${@}"; }
a__btrfs_filesystem_d_u() {
btrfs \
filesystem \
du \
--summarize \
"${@}"
}
bfu() { a__btrfs_filesystem_usage "${@}"; }
a__btrfs_filesystem_usage() {
btrfs \
filesystem \
usage \
"${@}"
}
bpg() { a__btrfs_property_get "${@}"; }
a__btrfs_property_get() {
btrfs \
property \
get \
"${@}"
}
bsc() { a__btrfs_subvolume_create "${@}"; }
a__btrfs_subvolume_create() {
btrfs \
subvolume \
create \
"${@}"
}
bsd() { a__btrfs_subvolume_delete "${@}"; }
a__btrfs_subvolume_delete() {
btrfs \
subvolume \
delete \
"${@}"
}
bsl() { a__btrfs_subvolume_list "${@}"; }
a__btrfs_subvolume_list() {
if [ -n "${1}" ]; then
btrfs subvolume list "${1}" |
cut --delimiter " " --fields 9 |
sort
fi
}
bss() { a__btrfs_subvolume_snapshot "${@}"; }
a__btrfs_subvolume_snapshot() {
btrfs \
subvolume \
snapshot \
"${@}"
}
bssr() { a__btrfs_subvolume_snapshot_r "${@}"; }
a__btrfs_subvolume_snapshot_r() {
btrfs \
subvolume \
snapshot -r \
"${@}"
}

27
sh/alias/byobu.sh Normal file
View file

@ -0,0 +1,27 @@
bb() { a__byo_bu "${@}"; }
a__byo_bu() {
byobu \
"${@}"
}
bba() { a__byo_bu_attach "${@}"; }
a__byo_bu_attach() {
byobu \
attach-session \
"${@}"
}
bbl() { a__byo_bu_ls "${@}"; }
a__byo_bu_ls() {
byobu \
ls \
"${@}"
}
bbnd() { a__byo_bu_new_detach "${@}"; }
a__byo_bu_new_detach() {
byobu \
new-session \
-d \
"${@}"
}

15
sh/alias/chmod.sh Normal file
View file

@ -0,0 +1,15 @@
# change mode to directory
cmd() { a__change_mode_directory "${@}"; }
a__change_mode_directory() {
chmod \
"755" \
"${@}"
}
# change mode to file
cmf() { a__change_mode_file "${@}"; }
a__change_mode_file() {
chmod \
"644" \
"${@}"
}

15
sh/alias/chown.sh Normal file
View file

@ -0,0 +1,15 @@
# change owner to root
cor() { a__change_owner_root "${@}"; }
a__change_owner_root() {
chown \
"0:0" \
"${@}"
}
# change owner to user
cou() { a__change_owner_user "${@}"; }
a__change_owner_user() {
chown \
"1000:1000" \
"${@}"
}

6
sh/alias/clear.sh Normal file
View file

@ -0,0 +1,6 @@
# clear terminal
c() { a__clear "${@}"; }
a__clear() {
clear \
"${@}"
}

7
sh/alias/cp.sh Normal file
View file

@ -0,0 +1,7 @@
# copy interactively
cpi() { a__co_py_interactive "${@}"; }
a__co_py_interactive() {
cp \
--interactive \
"${@}"
}

5
sh/alias/emacs.sh Normal file
View file

@ -0,0 +1,5 @@
em() { a__e_macs "${@}"; }
a__e_macs() {
emacs \
"${@}"
}

5
sh/alias/evince.sh Normal file
View file

@ -0,0 +1,5 @@
ev() { a__e_vince "${@}"; }
a__e_vince() {
evince \
"${@}"
}

548
sh/alias/git.sh Normal file
View file

@ -0,0 +1,548 @@
RWX_GIT_LOG_FORMAT="\
%C(auto)%h%d
S %C(red)%GS
A %C(green)%an %ae
%C(green)%ai
C %C(blue)%cn %ce
%C(blue)%ci
%B"
# add to index
ga() { a__git_add "${@}"; }
a__git_add() {
git \
add \
"${@}"
}
# add all to index
gaa() { a__git_add_all "${@}"; }
a__git_add_all() {
git \
add \
--all \
"${@}"
}
# add parts of all to index
gaap() { a__git_add_all_patch "${@}"; }
a__git_add_all_patch() {
git \
add \
--all \
--patch \
"${@}"
}
# add parts to index
gap() { a__git_add_patch "${@}"; }
a__git_add_patch() {
git \
add \
--patch \
"${@}"
}
# create a branch
gb() { a__git_branch "${@}"; }
a__git_branch() {
git \
branch \
"${@}"
}
# delete a branch
gbd() { a__git_branch_delete "${@}"; }
a__git_branch_delete() {
git \
branch \
--delete \
"${@}"
}
# force a branch deletion
gbdf() { a__git_branch_delete_force "${@}"; }
a__git_branch_delete_force() {
git \
branch \
--delete \
--force \
"${@}"
}
# list branches
gbl() { a__git_branch_list "${@}"; }
a__git_branch_list() {
git \
branch \
--all \
--list \
--verbose \
--verbose \
"${@}"
}
# set the link to a remote branch from a local branch
gbsu() { a__git_branch_set_upstream "${@}"; }
a__git_branch_set_upstream() {
git \
branch \
--set-upstream-to \
"${@}"
}
# switch to a branch or checkout file(s) from a commit
gc() { a__git_checkout "${@}"; }
a__git_checkout() {
git \
checkout \
"${@}"
}
# checkout an orphan branch
gco() { a__git_checkout_orphan "${@}"; }
a__git_checkout_orphan() {
git \
checkout \
--orphan \
"${@}"
}
# pick a commit
gcp() { a__git_cherry_pick "${@}"; }
a__git_cherry_pick() {
git \
cherry-pick \
"${@}"
}
# abort the commit pick
gcpa() { a__git_cherry_pick_abort "${@}"; }
a__git_cherry_pick_abort() {
git \
cherry-pick \
--abort \
"${@}"
}
# continue the commit pick
gcpc() { a__git_cherry_pick_continue "${@}"; }
a__git_cherry_pick_continue() {
git \
cherry-pick \
--continue \
"${@}"
}
# clean untracked files
gcf() { a__git_clean_force "${@}"; }
a__git_clean_force() {
git \
clean \
-d \
--force \
"${@}"
}
# redo the last commit with a different message
gcam() { a__git_commit_amend_message "${@}"; }
a__git_commit_amend_message() {
git \
commit \
--amend \
--message \
"${@}"
}
# make a root commit
gcem() { a__git_commit_empty_message "${@}"; }
a__git_commit_empty_message() {
git \
commit \
--allow-empty \
--allow-empty-message \
--message \
"${@}"
}
# commit the index
gcm() { a__git_commit_message "${@}"; }
a__git_commit_message() {
git \
commit \
--message \
"${@}"
}
# configure the user email
gcue() { a__git_config_user_email "${@}"; }
a__git_config_user_email() {
git \
config \
"user.email" \
"${@}"
}
# configure the user name
gcun() { a__git_config_user_name "${@}"; }
a__git_config_user_name() {
git \
config \
"user.name" \
"${@}"
}
# differences from last or between commits
gd() { a__git_diff "${@}"; }
a__git_diff() {
git \
diff \
"${@}"
}
# display what is indexed in cache
gdc() { a__git_diff_cached "${@}"; }
a__git_diff_cached() {
git \
diff \
--cached \
"${@}"
}
# indexed character-level differences
gdcw() { a__git_diff_cached_word "${@}"; }
a__git_diff_cached_word() {
git \
diff \
--cached \
--word-diff-regex "." \
"${@}"
}
# differences via external tool
gdt() { a__git_diff_tool "${@}"; }
a__git_diff_tool() {
git \
difftool \
--dir-diff \
"${@}"
}
# character-level differences
gdw() { a__git_diff_word "${@}"; }
a__git_diff_word() {
git \
diff \
--word-diff-regex "." \
"${@}"
}
# fetch from the remote repository
gf() { a__git_fetch "${@}"; }
a__git_fetch() {
rwx_gpg_agent_update &&
git \
fetch \
--tags \
--verbose \
"${@}"
}
# fetch from remote repository and prune local orphan branches
gfp() { a__git_fetch_prune "${@}"; }
a__git_fetch_prune() {
a__git_fetch \
--prune \
"${@}"
}
# garbage collect all orphan commits
ggc() { a__git_garbage_collect "${@}"; }
a__git_garbage_collect() {
git \
reflog \
expire \
--all \
--expire "all" &&
git \
gc \
--aggressive \
--prune="now"
}
# initialize a new repository
gi() { a__git_init "${@}"; }
a__git_init() {
git \
init \
"${@}"
}
# initialize a new bare repository
gib() { a__git_init_bare "${@}"; }
a__git_init_bare() {
git \
init \
--bare \
"${@}"
}
# log history
gl() { a__git_log "${@}"; }
a__git_log() {
git \
log \
--abbrev=8 \
--abbrev-commit \
--format="${RWX_GIT_LOG_FORMAT}" \
--graph \
"${@}"
}
# log all history
gla() { a__git_log_all "${@}"; }
a__git_log_all() {
a__git_log \
--all \
"${@}"
}
# log all history with patches
glap() { a__git_log_all_patch "${@}"; }
a__git_log_all_patch() {
a__git_log \
--all \
--patch \
"${@}"
}
# log history with patches
glp() { a__git_log_patch "${@}"; }
a__git_log_patch() {
a__git_log \
--patch \
"${@}"
}
# fast-forward merge to remote branch
gm() { a__git_merge "${@}"; }
a__git_merge() {
git \
merge \
--ff-only \
"${@}"
}
# abort the current merge commit
gma() { a__git_merge_abort "${@}"; }
a__git_merge_abort() {
git \
merge \
--abort \
"${@}"
}
# do a merge commit
gmc() { a__git_merge_commit "${@}"; }
a__git_merge_commit() {
git \
merge \
--no-ff \
--message \
"${@}"
}
# squash a branch and index its modifications
gms() { a__git_merge_squash "${@}"; }
a__git_merge_squash() {
git \
merge \
--squash \
"${@}"
}
# merge via external tool
gmt() { a__git_merge_tool "${@}"; }
a__git_merge_tool() {
git \
mergetool \
"${@}"
}
# push to the remote repository
gp() { a__git_push "${@}"; }
a__git_push() {
rwx_gpg_agent_update &&
git \
push \
--tags \
--verbose \
"${@}"
}
# delete from the remote repository
gpd() { a__git_push_delete "${@}"; }
a__git_push_delete() {
git \
push \
--delete \
"${@}"
}
# force the push to the remote repository
gpf() { a__git_push_force "${@}"; }
a__git_push_force() {
a__git_push \
--force \
"${@}"
}
# rebase current branch onto another
grb() { a__git_re_base "${@}"; }
a__git_re_base() {
git \
rebase \
"${@}"
}
# abort current rebase
grba() { a__git_re_base_abort "${@}"; }
a__git_re_base_abort() {
git \
rebase \
--abort \
"${@}"
}
# continue current rebase
grbc() { a__git_re_base_continue "${@}"; }
a__git_re_base_continue() {
git \
rebase \
--continue \
"${@}"
}
# force rebase without fast-forward
grbf() { a__git_re_base_force "${@}"; }
a__git_re_base_force() {
git \
rebase \
--force-rebase \
"${@}"
}
# rebase interactively
grbi() { a__git_re_base_interactive "${@}"; }
a__git_re_base_interactive() {
git \
rebase \
--interactive \
"${@}"
}
# add a new remote repository
grma() { a__git_re_mote_add "${@}"; }
a__git_re_mote_add() {
git \
remote \
add \
"${@}"
}
# list remote repositories
grml() { a__git_re_mote_list "${@}"; }
a__git_re_mote_list() {
git \
remote \
--verbose \
"${@}"
}
# set the location of a remote repository
grmsu() { a__git_re_mote_set_upstream "${@}"; }
a__git_re_mote_set_upstream() {
git \
remote \
set-url \
"${@}"
}
# show connection to a remote repository
grms() { a__git_re_mote_show "${@}"; }
a__git_re_mote_show() {
git \
remote \
show \
"${@}"
}
# remove and add removal to index
grm() { a__git_re_move "${@}"; }
a__git_re_move() {
git \
rm \
"${@}"
}
# remove file(s) from index or move current branch pointer
grs() { a__git_re_set "${@}"; }
a__git_re_set() {
git \
reset \
"${@}"
}
# wipe modifications or reset current branch to another commit
grsh() { a__git_re_set_hard "${@}"; }
a__git_re_set_hard() {
git \
reset \
--hard \
"${@}"
}
# show a commit
gsc() { a__git_show_commit "${@}"; }
a__git_show_commit() {
git \
show \
"${@}"
}
# current state of repository
gs() { a__git_status "${@}"; }
a__git_status() {
git \
status \
--untracked-files="all" \
"${@}"
}
# tag a commit
gt() { a__git_tag "${@}"; }
a__git_tag() {
git \
tag \
"${@}"
}
# delete a tag
gtd() { a__git_tag_delete "${@}"; }
a__git_tag_delete() {
git \
tag \
--delete \
"${@}"
}
# update head ref
gurh() { a__git_update_ref_head "${@}"; }
a__git_update_ref_head() {
if [ -n "${2}" ]; then
git \
update-ref \
"refs/heads/${1}" \
"${2}"
fi
}

12
sh/alias/gpg.sh Normal file
View file

@ -0,0 +1,12 @@
# turn gpg agent off
gak() { a__gpg_agent_kill "${@}"; }
a__gpg_agent_kill() {
gpgconf \
--kill "gpg-agent"
}
# bind gpg agent to current tty
gau() { a__gpg_agent_update "${@}"; }
a__gpg_agent_update() {
rwx_gpg_agent_update
}

9
sh/alias/grep.sh Normal file
View file

@ -0,0 +1,9 @@
# grep from current directory with regex
g() { a__grep "${@}"; }
a__grep() {
grep \
--directories "recurse" \
--line-number \
--regexp \
"${@}"
}

14
sh/alias/kill.sh Normal file
View file

@ -0,0 +1,14 @@
# kill a process by id
k() { a__kill "${@}"; }
a__kill() {
kill \
"${@}"
}
# force kill a process by id
kf() { a__kill_force "${@}"; }
a__kill_force() {
kill \
-9 \
"${@}"
}

14
sh/alias/killall.sh Normal file
View file

@ -0,0 +1,14 @@
# kill all instances of a process by name
ka() { a__kill_all "${@}"; }
a__kill_all() {
killall \
"${@}"
}
# force kill all instances of a process by name
kaf() { a__kill_all_force "${@}"; }
a__kill_all_force() {
killall \
-9 \
"${@}"
}

32
sh/alias/ls.sh Normal file
View file

@ -0,0 +1,32 @@
export LS_COLORS="\
di=0;94\
"
# list current directory’s entries
l() { a__ls "${@}"; }
a__ls() {
ls \
--all \
--color \
-l \
-p \
--time-style "+" \
"${@}"
}
# list timestamps
lt() { a__ls_time "${@}"; }
a__ls_time() {
a__ls \
--time-style "+%Y%m%d-%H%M%S%-:::z" \
"${@}"
}
# list timestamps recent last
ltr() { a__ls_time_reverse "${@}"; }
a__ls_time_reverse() {
a__ls_time \
--reverse \
-t \
"${@}"
}

31
sh/alias/lsblk.sh Normal file
View file

@ -0,0 +1,31 @@
# list block devices
lb() { a__list_block "${@}"; }
a__list_block() {
a__list_block_output \
"SIZE" \
"TYPE" \
"FSTYPE" \
"LABEL" \
"MOUNTPOINTS" \
"${@}"
}
# base arguments
lbne() { a__list_block_no_empty "${@}"; }
a__list_block_no_empty() {
lsblk \
--noempty \
"${@}"
}
# output arguments
lbo() { a__list_block_output "${@}"; }
a__list_block_output() {
local argument
local arguments="NAME"
for argument in "${@}"; do
arguments="${arguments},${argument}"
done
a__list_block_no_empty \
--output "${arguments}"
}

14
sh/alias/mkdir.sh Normal file
View file

@ -0,0 +1,14 @@
# make a directory
md() { a__make_directory "${@}"; }
a__make_directory() {
mkdir \
"${@}"
}
# make a directory after making its parents
mdp() { a__make_directory_parents "${@}"; }
a__make_directory_parents() {
mkdir \
--parents \
"${@}"
}

5
sh/alias/mount.sh Normal file
View file

@ -0,0 +1,5 @@
m() { a__mount "${@}"; }
a__mount() {
mount \
"${@}"
}

7
sh/alias/mv.sh Normal file
View file

@ -0,0 +1,7 @@
# move interactively
mvi() { a__mo_ve_interactive "${@}"; }
a__mo_ve_interactive() {
mv \
--interactive \
"${@}"
}

5
sh/alias/nano.sh Normal file
View file

@ -0,0 +1,5 @@
nn() { a__na_no "${@}"; }
a__na_no() {
nano \
"${@}"
}

5
sh/alias/newsboat.sh Normal file
View file

@ -0,0 +1,5 @@
nb() { a__news_boat "${@}"; }
a__news_boat() {
newsboat \
"${@}"
}

140
sh/alias/overlay.sh Normal file
View file

@ -0,0 +1,140 @@
obm() { a__overlay_bind_mount "${@}"; }
a__overlay_bind_mount() {
local directory
for directory in "dev" "dev/pts" "proc" "sys"; do
if ! mount --bind "/${directory}" "overlay/mount/${directory}"; then
rwx_log_error "Unable to bind mount directory: ${directory}"
return 1
fi
done
}
obu() { a__overlay_bind_unmount "${@}"; }
a__overlay_bind_unmount() {
local directory
for directory in "sys" "proc" "dev/pts" "dev"; do
if ! umount --lazy "overlay/mount/${directory}"; then
rwx_log_error "Unable to bind unmount directory: ${directory}"
return 1
fi
done
}
ocr() { a__overlay_command_root "${@}"; }
a__overlay_command_root() {
chroot \
"overlay/mount" "${@}"
}
ocu() { a__overlay_command_user "${@}"; }
a__overlay_command_user() {
chroot \
--userspec "1000:1000" \
"overlay/mount" "${@}"
}
omm() { a__overlay_mirror_mount "${@}"; }
a__overlay_mirror_mount() {
mount --make-rslave --rbind "/deb" "overlay/mount/deb"
}
omu() { a__overlay_mirror_unmount "${@}"; }
a__overlay_mirror_unmount() {
umount --recursive "overlay/mount/deb"
}
orm() { a__overlay_root_mount "${@}"; }
a__overlay_root_mount() {
local root="${1}"
if [ -z "${root}" ]; then
rwx_log_error "No root target directory"
return 1
fi
root="$(realpath "${root}")"
if ! mkdir "overlay"; then
rwx_log_error "Unable to make overlay directory"
return 2
fi
(
if ! cd "overlay"; then
rwx_log_error "Unable to move into overlay directory"
return 3
fi
local directory
for directory in "lower" "upper" "work" "mount"; do
if ! mkdir --parents "${directory}"; then
rwx_log_error "Unable to make directory: ${directory}"
return 4
fi
done
local file="${root}/filesystem.squashfs"
if ! mount "${file}" "lower"; then
rwx_log_error "Unable to lower mount: ${file}"
return 5
fi
if ! mount \
-o "lowerdir=lower,upperdir=upper,workdir=work" \
-t "overlay" \
"overlay" "mount"; then
rwx_log_error "Unable to overlay mount"
return 6
fi
)
}
ors() { a__overlay_root_squash "${@}"; }
a__overlay_root_squash() {
local directory="${1}"
local file
local level="${2}"
if [ -n "${directory}" ]; then
if mkdir "${directory}"; then
[ -n "${level}" ] || level="18"
for file in "vmlinuz" "initrd.img"; do
cp "overlay/mount/${file}" "${directory}"
done
mksquashfs \
"overlay/mount" "${directory}/filesystem.squashfs" \
-noappend \
-comp "zstd" -Xcompression-level "${level}"
chown --recursive 1000:1000 "${directory}"
fi
fi
}
oru() { a__overlay_root_unmount "${@}"; }
a__overlay_root_unmount() {
(
if ! cd "overlay"; then
rwx_log_error "Unable to move into overlay directory"
return 1
fi
if ! umount "mount"; then
rwx_log_error "Unable to unmount mount directory"
return 2
fi
if ! rmdir "mount"; then
rwx_log_error "Unable to remove mount directory"
return 3
fi
local directory
for directory in "upper" "work"; do
if ! rm --force --recursive "${directory}"; then
rwx_log_error "Unable to remove directory: ${directory}"
return 4
fi
done
if ! umount "lower"; then
rwx_log_error "Unable to unmount lower directory"
return 5
fi
if ! rmdir "lower"; then
rwx_log_error "Unable to remove lower directory"
return 6
fi
)
if ! rmdir "overlay"; then
rwx_log_error "Unable to remove overlay directory"
return 7
fi
}

14
sh/alias/pass.sh Normal file
View file

@ -0,0 +1,14 @@
# display pass entry’s content
p() { a__pass "${@}"; }
a__pass() {
pass \
"${@}"
}
# copy passphrase into clipboard
pc() { a__pass_clip "${@}"; }
a__pass_clip() {
pass \
--clip \
"${@}"
}

7
sh/alias/pgrep.sh Normal file
View file

@ -0,0 +1,7 @@
# look for a string in processes names
pg() { a__proc_grep "${@}"; }
a__proc_grep() {
pgrep \
--list-full \
"${@}"
}

17
sh/alias/pwgen.sh Normal file
View file

@ -0,0 +1,17 @@
# generate passwords
pwg() { a__pass_word_gen "${@}"; }
a__pass_word_gen() {
pwgen \
-1 \
--num-passwords 1048576 \
--secure \
"${@}"
}
# generate passwords with symbols
pwgs() { a__pass_word_gen_symbols "${@}"; }
a__pass_word_gen_symbols() {
a__pass_word_gen \
--symbols \
"${@}"
}

7
sh/alias/rm.sh Normal file
View file

@ -0,0 +1,7 @@
# remove interactively
rmi() { a__re_move_interactive "${@}"; }
a__re_move_interactive() {
rm \
--interactive \
"${@}"
}

27
sh/alias/rsync.sh Normal file
View file

@ -0,0 +1,27 @@
# synchronize
rs() { a__r_sync "${@}"; }
a__r_sync() {
rsync \
--archive \
--no-inc-recursive \
--partial \
--progress \
--verbose \
"${@}"
}
# synchronize and delete after
rsda() { a__r_sync_delete_after "${@}"; }
a__r_sync_delete_after() {
a__r_sync \
--delete-after \
"${@}"
}
# synchronize and delete before
rsdb() { a__r_sync_delete_before "${@}"; }
a__r_sync_delete_before() {
a__r_sync \
--delete-before \
"${@}"
}

29
sh/alias/shell.sh Normal file
View file

@ -0,0 +1,29 @@
# shorten alias
a() {
alias \
"${@}"
}
# swap directory (current ↔ previous)
sd() {
cd \
- ||
return
}
# exit terminal
x() {
exit \
"${@}"
}
[ "${RWX_SHELL}" = "bash" ] || return
# shellcheck disable=SC3033
..() {
cd ..
}
# shellcheck disable=SC3033
...() {
cd ../..
}

31
sh/alias/tar.sh Normal file
View file

@ -0,0 +1,31 @@
tc() { a__tar_create "${@}"; }
a__tar_create() {
a__tar_verbose \
--create \
--auto-compress \
--file \
"${@}"
}
tl() { a__tar_list "${@}"; }
a__tar_list() {
a__tar_verbose \
--list \
--file \
"${@}"
}
tv() { a__tar_verbose "${@}"; }
a__tar_verbose() {
tar \
--verbose \
"${@}"
}
tx() { a__tar_xtract "${@}"; }
a__tar_xtract() {
a__tar_verbose \
--extract \
--file \
"${@}"
}

5
sh/alias/tmux.sh Normal file
View file

@ -0,0 +1,5 @@
tm() { a__t_mux "${@}"; }
a__t_mux() {
tmux \
"${@}"
}

12
sh/alias/tree.sh Normal file
View file

@ -0,0 +1,12 @@
t() { a__tree "${@}"; }
a__tree() {
tree \
"${@}"
}
ta() { a__tree_all "${@}"; }
a__tree_all() {
tree \
-a \
"${@}"
}

6
sh/cryptsetup.sh Normal file
View file

@ -0,0 +1,6 @@
_rwx_cmd_cs() { rwx_crypt_setup "${@}"; }
rwx_crypt_setup() {
local action="${1}"
echo "cs: ${action}"
}

76
sh/debian.sh Normal file
View file

@ -0,0 +1,76 @@
RWX_DEBIAN_CODENAME="$(
grep "VERSION_CODENAME" "/etc/os-release" |
cut --delimiter "=" --fields "2"
)"
rwx_apt_clean() {
apt-get \
clean
}
rwx_apt_conf_write() {
printf "\
Acquire::AllowInsecureRepositories False;
Acquire::AllowWeakRepositories False;
Acquire::AllowDowngradeToInsecureRepositories False;
Acquire::Check-Valid-Until True;
APT::Install-Recommends False;
APT::Install-Suggests False;
APT::Get::Show-Versions True;
Dir::Etc::SourceParts \"\";
Dpkg::Progress True;
" >"/etc/apt/apt.conf.d/apt.conf"
}
rwx_apt_install_backports() {
rwx_apt_install_target "${RWX_DEBIAN_CODENAME}-backports" "${@}"
}
rwx_apt_install_release() {
rwx_apt_install_target "${RWX_DEBIAN_CODENAME}" "${@}"
}
rwx_apt_install_target() {
local target="${1}"
shift
local package
for package in "${@}"; do
rwx_log "" \
"${package}${target}"
apt-get \
install \
--assume-yes \
--target-release "${target}" \
"${package}"
rwx_apt_clean
done
}
rwx_apt_sources_write() {
printf "%s" "\
deb https://deb.debian.org/debian \
${RWX_DEBIAN_CODENAME} main non-free-firmware contrib non-free
deb https://deb.debian.org/debian \
${RWX_DEBIAN_CODENAME}-backports main non-free-firmware contrib non-free
deb https://deb.debian.org/debian \
${RWX_DEBIAN_CODENAME}-updates main non-free-firmware contrib non-free
deb https://deb.debian.org/debian-security \
${RWX_DEBIAN_CODENAME}-security main non-free-firmware contrib non-free
" >"/etc/apt/sources.list"
}
rwx_apt_update() {
apt-get \
update
}
rwx_apt_upgrade() {
apt-get \
upgrade \
--assume-yes
rwx_apt_clean
}
rwx_debian_frontend_disable() {
export DEBIAN_FRONTEND="noninteractive"
}

194
sh/ffmpeg.sh Normal file
View file

@ -0,0 +1,194 @@
# ╭────────┬─────────┬───────╮
# │ ffmpeg │ devices │ reset │
# ╰────────┴─────────┴───────╯
_rwx_cmd_rwx_ffmpeg_devices_reset() { rwx_ffmpeg_devices_reset "${@}"; }
rwx_ffmpeg_devices_reset() {
local module="uvcvideo"
modprobe --remove "${module}" &&
modprobe "${module}"
}
# ╭────────┬────────┬─────────╮
# │ ffmpeg │ device │ formats │
# ╰────────┴────────┴─────────╯
rwx_ffmpeg_device_formats() {
local device="${1}"
[ -n "${device}" ] || device="/dev/video0"
ffmpeg \
-f "v4l2" \
-list_formats "all" \
-i "${device}"
}
# ╭────────┬───────╮
# │ ffmpeg │ input │
# ╰────────┴───────╯
rwx_ffmpeg_input_blue_yeti() {
local device="alsa_input.\
usb-Generic_Blue_Microphones_2051BAB04XY8-00.analog-stereo"
set -- \
-f "pulse" \
-i "${device}" \
-ac "2" \
-ar "48000"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_input_dell_precision() {
local device="alsa_input.\
pci-0000_00_1f.3.analog-stereo"
set -- \
-f "pulse" \
-i "${device}" \
-ac "2" \
-ar "48000"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_input_file() {
local file="${1}"
local from="${2}"
local to="${3}"
[ -n "${file}" ] || return
set -- \
-i "${file}"
if [ -n "${to}" ]; then
set -- "${@}" \
-ss "${from}" \
-to "${to}"
fi
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_input_hdmi() {
local device="${1}"
[ -n "${device}" ] || device="/dev/video0"
set -- \
-f "v4l2" \
-video_size "1920x1080" \
-framerate "60" \
-input_format "yuyv422" \
-i "${device}"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
# ╭────────┬────────╮
# │ ffmpeg │ output │
# ╰────────┴────────╯
rwx_ffmpeg_output_audio_fast() {
set -- \
-codec:a "flac" \
-compression_level "0"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_audio_slow() {
set -- \
-codec:a "libopus" \
-b:a "128k"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_file() {
local file="${1}"
[ -n "${file}" ] || return
set -- \
-y "${file}"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_video_fast() {
set -- \
-codec:v "libx264" \
-preset "ultrafast" \
-crf "0"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
rwx_ffmpeg_output_video_slow() {
local crf="${1}"
local codec="${2}"
[ -n "${codec}" ] || codec="libx264"
if [ -z "${crm}" ]; then
case "${codec}" in
"libx264") crf="23" ;;
"libx265") crf="28" ;;
*) ;;
esac
fi
set -- \
-codec:v "${codec}" \
-preset "veryslow" \
-crf "${crf}" \
-movflags "+faststart" \
-pix_fmt "yuv420p"
local argument
for argument in "${@}"; do echo "${argument}"; done
}
# ╭────────┬────────╮
# │ ffmpeg │ record │
# ╰────────┴────────╯
rwx_ffmpeg_record_hdmi_precision() {
local file="${1}"
[ -n "${file}" ] || return
# LATER alternative
# shellcheck disable=SC2046,SC2312
set -- \
$(rwx_ffmpeg_input_hdmi) \
$(rwx_ffmpeg_input_dell_precision) \
$(rwx_ffmpeg_output_video_fast) \
$(rwx_ffmpeg_output_audio_fast) \
$(rwx_ffmpeg_output_file "${file}")
echo "${@}"
ffmpeg "${@}"
}
rwx_ffmpeg_record_hdmi_yeti() {
local file="${1}"
[ -n "${file}" ] || return
# LATER alternative
# shellcheck disable=SC2046,SC2312
set -- \
$(rwx_ffmpeg_input_hdmi) \
$(rwx_ffmpeg_input_blue_yeti) \
$(rwx_ffmpeg_output_video_fast) \
$(rwx_ffmpeg_output_audio_fast) \
$(rwx_ffmpeg_output_file "${file}")
echo "${@}"
ffmpeg "${@}"
}
# ╭────────┬────────╮
# │ ffmpeg │ reduce │
# ╰────────┴────────╯
rwx_ffmpeg_reduce() {
local input="${1}"
local output="${2}"
local from="${3}"
local to="${4}"
[ -n "${output}" ] || return
# LATER alternative
# shellcheck disable=SC2046,SC2312
set -- \
$(rwx_ffmpeg_input_file "${input}" "${from}" "${to}") \
$(rwx_ffmpeg_output_video_slow) \
$(rwx_ffmpeg_output_audio_slow) \
$(rwx_ffmpeg_output_file "${output}")
echo "${@}"
ffmpeg "${@}"
}

121
sh/fs.sh Normal file
View file

@ -0,0 +1,121 @@
rwx_fs_make_btrfs() {
local device="${1}"
local label="${2}"
local uuid="${3}"
if [ -b "${device}" ]; then
set -- \
--force \
--checksum "sha256"
if [ -n "${label}" ]; then
set -- "${@}" \
--label "${label}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" \
--uuid "${uuid}"
fi
mkfs.btrfs "${@}" "${device}"
fi
}
rwx_fs_make_btrfs_swap() {
local path="${1}"
local size="${2}"
local uuid="${3}"
if [ -n "${path}" ]; then
set -- filesystem mkswapfile
if [ -n "${size}" ]; then
set -- "${@}" \
--size "${size}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" \
--uuid "${uuid}"
fi
btrfs "${@}" "${path}"
fi
}
rwx_fs_make_fat() {
local device="${1}"
local name="${2}"
local volid="${3}"
if [ -b "${device}" ]; then
set -- \
-F 32 \
-S 4096
if [ -n "${name}" ]; then
set -- "${@}" \
-n "${name}"
fi
if [ -n "${volid}" ]; then
set -- "${@}" \
-i "${volid}"
fi
mkfs.fat "${@}" "${device}"
fi
}
rwx_fs_raid_create() {
if [ -n "${4}" ]; then
local name="${1}"
local uuid="${2}"
shift 2
mdadm \
--create "/dev/md/${name}" \
--level 0 \
--metadata 1 \
--name "md:${name}" \
--raid-devices ${#} \
--uuid "${uuid}" \
"${@}"
fi
}
rwx_fs_wipe() {
local device="${1}"
local buffer="${2}"
local count="${3}"
if [ -b "${device}" ]; then
set -- \
status="progress" \
if="/dev/zero" \
of="${device}"
if [ -n "${buffer}" ]; then
set -- "${@}" \
bs="${buffer}"
fi
if [ -n "${count}" ]; then
set -- "${@}" \
count="${count}"
fi
dd "${@}"
fi
}
rwx_fs_luks_format() {
local passphrase="${1}"
local device="${2}"
local label="${3}"
local uuid="${4}"
if [ -b "${device}" ]; then
set -- \
--batch-mode \
--cipher "aes-xts-plain64" \
--hash "sha512" \
--iter-time 4096 \
--key-size 512 \
--pbkdf "argon2id" \
--type "luks2" \
--use-random \
--verbose
if [ -n "${label}" ]; then
set -- "${@}" --label "${label}"
fi
if [ -n "${uuid}" ]; then
set -- "${@}" --uuid "${uuid}"
fi
echo "${passphrase}" |
cryptsetup "${@}" luksFormat "${device}"
fi
}

71
sh/gnome.sh Normal file
View file

@ -0,0 +1,71 @@
# ╭───────┬────────────╮
# │ gnome │ background │
# ╰───────┴────────────╯
rwx_gnome_background_black() {
rwx_gnome_set_background "color-shading-type" "solid"
rwx_gnome_set_background "primary-color" "#000000"
}
rwx_gnome_background_white() {
rwx_gnome_set_background "color-shading-type" "solid"
rwx_gnome_set_background "primary-color" "#ffffff"
}
rwx_gnome_background_win3() {
rwx_gnome_set_background "color-shading-type" "vertical"
rwx_gnome_set_background "primary-color" "#000000"
rwx_gnome_set_background "secondary-color" "#0000ff"
}
# ╭───────┬───────╮
# │ gnome │ proxy │
# ╰───────┴───────╯
rwx_gnome_proxy() {
local value
case "${1}" in
"on") value="manual" ;;
*) value="none" ;;
esac
gsettings set "org.gnome.system.proxy" "mode" "${value}"
}
# ╭───────┬─────╮
# │ gnome │ set │
# ╰───────┴─────╯
rwx_gnome_set() {
local group="${1}"
local key="${2}"
local value="${3}"
[ -n "${value}" ] || return
gsettings set "${group}" "${key}" "${value}"
}
rwx_gnome_set_background() {
local key="${1}"
local value="${2}"
[ -n "${value}" ] || return
rwx_gnome_set "org.gnome.desktop.background" "${key}" "${value}"
}
# ╭───────┬────────────╮
# │ gnome │ workspaces │
# ╰───────┴────────────╯
rwx_gnome_workspaces_primary() {
local bool
local group="org.gnome.mutter"
local name="workspaces-only-on-primary"
local var="${group}/${name}"
# get
bool="$(gsettings get "${group}" "${name}")"
rwx_log_debug "${var}: ${bool}"
# not
bool="$(rwx_not "${bool}")"
rwx_log_debug "bool: ${bool}"
# set
gsettings set "${group}" "${name}" "${bool}"
rwx_log_info "${var}: ${bool}"
}

19
sh/gpg.sh Normal file
View file

@ -0,0 +1,19 @@
# bind gpg agent to current tty
rwx_gpg_agent_update() {
gpg-connect-agent \
updatestartuptty \
/bye
}
rwx_gpg_ssh_auth_sock() {
local user_id
user_id=$(id --user)
if [ "${user_id}" -ne 0 ]; then
if [ -f "${HOME}/.gnupg/gpg-agent.conf" ]; then
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
export SSH_AUTH_SOCK
fi
fi
}
rwx_gpg_ssh_auth_sock

6
sh/lint/gitlint.sh Normal file
View file

@ -0,0 +1,6 @@
rwx_gitlint() {
local path="${1}"
gitlint \
--target "${path}" \
"lint"
}

78
sh/lint/lint.sh Normal file
View file

@ -0,0 +1,78 @@
# lint code
rwx_lint() {
local path="${1}"
[ -n "${path}" ] || return 1
rwx_lint_clean "${path}"
rwx_lint_tasks "${path}"
set \
"python" \
"shell"
local code
for code in "${@}"; do
rwx_log "" "${code}"
"rwx_lint_${code}" "${path}"
done
rwx_lint_clean "${path}"
}
# clean
rwx_lint_clean() {
local path="${1}"
[ -n "${path}" ] || return 1
rwx_log "" "clean" ""
py3clean "${path}"
set \
"mypy" \
"ruff"
local tool
for tool in "${@}"; do
rwx_remove "${path}/.${tool}_cache"
done
}
# lint python code
rwx_lint_python() {
local path="${1}"
local action
set \
"pylint" \
"pydoclint" \
"mypy" \
"ruff"
for action in "${@}"; do
rwx_log "" "${action}"
"rwx_${action}" "${path}"
done
}
# lint shell code
rwx_lint_shell() {
local path="${1}"
local action
set \
"shellcheck" \
"shfmt"
for action in "${@}"; do
rwx_log "" "${action}"
"rwx_${action}" "${path}"
done
}
# lint code tasks
rwx_lint_tasks() {
local path="${1}"
local type
set \
"LATER" \
"TODO" \
"FIXME"
for type in "${@}"; do
rwx_log "" "${type}"
grep \
--after "1" \
--directories "recurse" \
--line-number \
" ${type}" \
"${path}"
done
}

4
sh/lint/mypy.sh Normal file
View file

@ -0,0 +1,4 @@
rwx_mypy() {
local path="${1}"
mypy "${path}"
}

9
sh/lint/pydoclint.sh Normal file
View file

@ -0,0 +1,9 @@
rwx_pydoclint() {
local path="${1}"
pydoclint \
--allow-init-docstring True \
--quiet \
--skip-checking-short-docstrings False \
--style "sphinx" \
"${path}"
}

6
sh/lint/pylint.sh Normal file
View file

@ -0,0 +1,6 @@
rwx_pylint() {
local path="${1}"
pylint \
--enable-all-extensions \
"${path}/**/*.py"
}

28
sh/lint/ruff.sh Normal file
View file

@ -0,0 +1,28 @@
rwx_ruff() {
local path="${1}"
local action
set \
"check" \
"format"
for action in "${@}"; do
"rwx_ruff_${action}" "${path}"
done
}
rwx_ruff_check() {
local path="${1}"
ruff check \
--ignore "D203,D213" \
--isolated \
--select "ALL" \
"${path}"
}
rwx_ruff_format() {
local path="${1}"
ruff format \
--diff \
--isolated \
--line-length "80" \
"${path}"
}

34
sh/lint/shellcheck.sh Normal file
View file

@ -0,0 +1,34 @@
rwx_shellcheck() {
local root="${1}"
local file module modules path
file="$(mktemp)"
modules="$(rwx_find_shell "${root}")"
rwx_ifs_set
for module in ${modules}; do
path="${root}/${module}"
echo ". \"${path}\"" >>"${file}"
done
rwx_ifs_unset
rwx_shellcheck_file "${file}"
rwx_remove "${file}"
}
rwx_shellcheck_file() {
local file="${1}"
shellcheck \
--check-sourced \
--enable "all" \
--exclude "3043" \
--external-sources \
--shell "dash" \
"${file}"
}
rwx_shellcheck_write() {
rwx_file_write ".shellcheckrc" "\
disable=3043
enable=all
external-sources=true
shell=sh
"
}

4
sh/lint/shfmt.sh Normal file
View file

@ -0,0 +1,4 @@
rwx_shfmt() {
local path="${1}"
shfmt --diff "${path}"
}

6
sh/live.sh Normal file
View file

@ -0,0 +1,6 @@
# remount read-only medium in read-write
rwx_live_medium_remount() {
mount \
-o "remount,rw" \
"/usr/lib/live/mount/medium"
}

68
sh/log/log.sh Normal file
View file

@ -0,0 +1,68 @@
RWX_LOG_LEVEL_FATAL=0
RWX_LOG_LEVEL_ERROR=1
RWX_LOG_LEVEL_WARN=2
RWX_LOG_LEVEL_INFO=3
RWX_LOG_LEVEL_DEBUG=4
RWX_LOG_LEVEL_TRACE=5
RWX_LOG_LEVEL=${RWX_LOG_LEVEL_INFO}
rwx_log() { rwx_log_info "${@}"; }
rwx_log_debug() {
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_DEBUG}" ]; then
_rwx_log "[DEBUG]" "${@}"
fi
}
rwx_log_error() {
local code="${1}"
shift
[ -n "${code}" ] || rwx_log_fatal 1 "No error code"
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_ERROR}" ]; then
_rwx_log "[ERROR]" "${@}" >&2
return "${code}"
fi
}
rwx_log_fatal() {
local code="${1}"
shift
[ -n "${code}" ] || rwx_log_fatal 1 "No error code"
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_FATAL}" ]; then
_rwx_log "[FATAL]" "${@}" >&2
exit "${code}"
fi
}
rwx_log_info() {
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_INFO}" ]; then
_rwx_log "" "${@}"
fi
}
rwx_log_trace() {
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_TRACE}" ]; then
_rwx_log "[TRACE]" "${@}"
fi
}
rwx_log_warn() {
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_WARN}" ]; then
_rwx_log "[ WARN]" "${@}"
fi
}
_rwx_log() {
local prefix="${1}"
shift
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
if [ -n "${prefix}" ]; then
__rwx_log "${prefix} ${line}"
else
__rwx_log "${line}"
fi
done
}

25
sh/log/step.sh Normal file
View file

@ -0,0 +1,25 @@
# ╭───────────────╮
# │ __ = internal │
# ╰───────────────╯
# __RWX_BAR_TOP
# __RWX_BAR_MIDDLE
# __RWX_BAR_BOTTOM
# __RWX_STEP_LEVEL
# __RWX_STEP_level_INDEX
# __RWX_STEP_level_LABEL
# ╭─────────────╮
# │ _ = private │
# ╰─────────────╯
_RWX_BOX_DOWN_AND_HORIZONTAL="┬"
_RWX_BOX_DOWN_AND_LEFT="╮"
_RWX_BOX_DOWN_AND_RIGHT="╭"
_RWX_BOX_HORIZONTAL="─"
_RWX_BOX_LEFT="╴"
_RWX_BOX_UP_AND_HORIZONTAL="┴"
_RWX_BOX_UP_AND_LEFT="╯"
_RWX_BOX_UP_AND_RIGHT="╰"
_RWX_BOX_VERTICAL="│"

144
sh/main.sh Executable file
View file

@ -0,0 +1,144 @@
#! /usr/bin/env sh
# ╭──────┬───────────╮
# │ main │ constants │
# ╰──────┴───────────╯
RWX_MAIN_NAME="main.sh"
RWX_SELF_NAME="rwx"
RWX_SELF_COMMAND="_${RWX_SELF_NAME}_cmd_"
# ╭──────┬───────────╮
# │ main │ variables │
# ╰──────┴───────────╯
RWX_COMMAND_ARGUMENT="${0}"
RWX_SHELL="$(cat "/proc/${$}/comm")"
RWX_COMMAND_NAME="$(basename "${RWX_COMMAND_ARGUMENT}" |
sed "s|^-||")"
case "${RWX_COMMAND_NAME}" in
"bash" | "dash" | "sh") unset RWX_COMMAND_NAME ;;
*) ;;
esac
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
# ╭──────┬───────╮
# │ main │ shell │
# ╰──────┴───────╯
# test if active shell is in interactive mode
rwx_shell_interactive() {
case "${-}" in
*i*) ;;
*) return 1 ;;
esac
}
# ╭──────┬─────╮
# │ main │ log │
# ╰──────┴─────╯
__rwx_log() {
if rwx_shell_interactive; then
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
echo "${line}"
done
fi
}
# ╭──────┬──────╮
# │ main │ find │
# ╰──────┴──────╯
# find directory’s files by extension
rwx_find_extension() {
local extension="${1}"
local root="${2}"
local file="${3}"
set -- \
"${root}" \
-name "*.${extension}" \
-type "f"
[ -n "${file}" ] &&
set -- "${@}" \
-not \
-name "${file}"
find "${@}" \
-printf "%P\n" |
sort
}
# find directory’s sh files
rwx_find_shell() {
rwx_find_extension "sh" "${@}"
}
# ╭──────┬─────╮
# │ main │ ifs │
# ╰──────┴─────╯
rwx_ifs_set() {
_RWX_IFS="${IFS}"
IFS="
"
}
rwx_ifs_unset() {
IFS="${_RWX_IFS}"
unset RWX_IFS
}
# ╭──────┬────────╮
# │ main │ source │
# ╰──────┴────────╯
rwx_source() {
local path="${1}"
[ -d "${path}" ] ||
return 1
local count module
count=0
__rwx_log "" \
". ${path}"
rwx_ifs_set
for module in $(rwx_find_shell "${path}" "${RWX_MAIN_NAME}"); do
count=$((count + 1))
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
module="${path}/${module}"
# shellcheck disable=SC1090
. "${module}"
done
rwx_ifs_unset
}
# ╭──────╮
# │ main │
# ╰──────╯
# run initial steps
rwx_main() {
# system root
if ! rwx_source "${RWX_ROOT_SYSTEM}"; then
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
return 1
fi
# user root
rwx_source "${RWX_SELF_USER}"
# context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
# context / shell
else
rwx_self_init
fi
}
# run main function
rwx_main "${@}"

14
sh/python.sh Normal file
View file

@ -0,0 +1,14 @@
# ╭────────╮
# │ python │
# ╰────────╯
# ╭────────┬──────╮
# │ python │ venv │
# ╰────────┴──────╯
rwx_python_venv() {
local path="${1}"
[ -d "${path}" ] || return 1
export VIRTUAL_ENV="${path}" && \
export PATH="${VIRTUAL_ENV}/bin:${PATH}"
}

94
sh/rescue/common.sh Normal file
View file

@ -0,0 +1,94 @@
rwx_rescue_configure() {
local hostname="${1}"
# apt / conf
rwx_apt_conf_write
# apt / sources
rwx_apt_sources_write
# bash / rc
main_link_bashrc
mv "${HOME}/.bashrc" "${HOME}/.bashrc.old"
# host name
hostname "${hostname}"
# locales
printf "\
en_US.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8
" >"/etc/locale.gen"
# generate locales
locale-gen
# update catalog
rwx_apt_update
# disable frontend
rwx_debian_frontend_disable
# install backports
rwx_apt_install_backports "tmux"
# install packages
rwx_apt_install_release "apt-file" "mosh" "screen" "byobu"
# update catalog
rwx_apt_update
}
rwx_rescue_install() {
# update catalog
rwx_apt_update
# disable frontend
rwx_debian_frontend_disable
# upgrade packages
rwx_apt_upgrade
# install packages
rwx_apt_install_release \
"man-db" \
"dmidecode" "efibootmgr" "lshw" "pciutils" "usbutils" \
"parted" "mdadm" "cryptsetup-bin" "lvm2" \
"btrfs-progs" "dosfstools" "duperemove" "squashfs-tools" \
"git" "micro" "nano" "python3" "rsync" "vim" \
"exa" "lf" "ncdu" "nnn" "ranger" "tree" \
"file" "htop" "iotop" "ipcalc" "libdigest-sha3-perl" "lsof"
# install backports
rwx_apt_install_backports \
"grub-pc-bin" \
\
"grub-efi-amd64-bin"
}
rwx_rescue_upload() {
local host="${1}"
local hostname="${2}"
if [ -n "${hostname}" ]; then
local user="root"
#
local user_host="${user}@${host}"
# remove fingerprints
ssh-keygen -R "${host}"
# copy ssh id
ssh-copy-id \
-o "StrictHostKeyChecking=accept-new" \
"${user_host}"
# upload root
rsync --delete --recursive \
"$(dirname "${ENV}")" "${user_host}:/etc"
# call setup
# TODO variable
ssh "${user_host}" -- \
". \"${ENV}\" ; rwx_rescue_configure \"${hostname}\""
# create session
ssh "${user_host}" -- byobu new-session -d
# send keys
ssh "${user_host}" -- byobu send-keys "rwx_rescue_install" "C-m"
# attach session
mosh "${user_host}" -- byobu attach-session
else
echo "host & hostname"
return 1
fi
}
rwx_rescue_wipe_1_zero() {
rwx_fs_wipe "/dev/mapper/crypt" "512M"
}
rwx_rescue_wipe_3_close() {
umount "/media/boot"
umount "/media/crypt" &&
cryptsetup luksClose "crypt"
}

129
sh/rescue/hetzner.sh Normal file
View file

@ -0,0 +1,129 @@
rwx_rescue_wipe_0_init_hetzner_8_8() {
local device
set \
"/dev/sda" \
"/dev/sdb"
local members
local number
local passphrase
# read passphrase
passphrase="$(rwx_read_passphrase)"
# warn
rwx_warn_wipe "${@}"
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}"
#
parted --script "${device}" \
mktable gpt \
unit "mib" \
mkpart "crypt-${number}" 33282 7630885 \
mkpart "boot-${number}" 514 33282 \
mkpart "esp-${number}" 2 514 \
set 3 esp on \
mkpart "bios-${number}" 1 2 \
set 4 bios_grub on
done
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}4"
# wipe bios
rwx_fs_wipe "${device}4"
done
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}3"
# format esp
rwx_fs_wipe "${device}3" "1M"
rwx_fs_make_fat "${device}3" "esp-${number}" "0000000${number}"
# mount esp
mkdir --parents "/media/esp/${number}"
mount "${device}3" "/media/esp/${number}"
done
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}2"
# wipe boot
rwx_fs_wipe "${device}2" "1G" 1
done
#
members=""
for device in "${@}"; do
members="${members} ${device}2"
done
# LATER alternative
# shellcheck disable=SC2086
rwx_fs_raid_create \
"boot" "00000000:00000000:00000000:00000002" ${members}
#
rwx_fs_make_btrfs "/dev/md/boot" "boot" \
"00000000-0000-0000-0000-00000000000b"
# mount boot
mkdir --parents "/media/boot"
mount \
--options "autodefrag,compress-force=zstd" \
"/dev/md/boot" "/media/boot"
#
number=0
for device in "${@}"; do
number=$((number + 1))
echo
echo "#${number}: ${device}1"
# wipe crypt head
rwx_fs_wipe "${device}1" "1G" 1
done
#
members=""
for device in "${@}"; do
members="${members} ${device}1"
done
# LATER alternative
# shellcheck disable=SC2086
rwx_fs_raid_create \
"crypt" "00000000:00000000:00000000:00000001" ${members}
# encrypt
rwx_fs_luks_format "${passphrase}" "/dev/md/crypt"
# open
echo "${passphrase}" |
cryptsetup luksOpen "/dev/md/crypt" "crypt"
# passphrase
unset passphrase
}
rwx_rescue_wipe_2_make_hetzner_8_8() {
local passphrase
# close
cryptsetup luksClose "crypt"
# read passphrase
passphrase="$(rwx_read_passphrase)"
# encrypt
rwx_fs_luks_format "${passphrase}" "/dev/md/crypt"
# open
echo "${passphrase}" |
cryptsetup luksOpen "/dev/md/crypt" "crypt"
# passphrase
unset passphrase
# format crypt
rwx_fs_make_btrfs "/dev/mapper/crypt" "crypt" \
"00000000-0000-0000-0000-00000000000c"
# mount crypt
mkdir --parents "/media/crypt"
mount \
--options "autodefrag,compress-force=zstd" \
"/dev/mapper/crypt" "/media/crypt"
# make swap file
rwx_fs_make_btrfs_swap "/media/crypt/swap" "64g" \
"00000000-0000-0000-0000-000000000005"
}

71
sh/rescue/ovh.sh Normal file
View file

@ -0,0 +1,71 @@
rwx_rescue_wipe_0_init_ovh_vle2() {
local device="/dev/sdb"
local passphrase
# read passphrase
passphrase="$(rwx_read_passphrase)"
# warn
rwx_warn_wipe "${device}"
#
parted --script "${device}" \
mktable gpt \
unit "mib" \
mkpart "crypt" 4610 40959 \
mkpart "boot" 514 4610 \
mkpart "esp" 2 514 \
set 3 esp on \
mkpart bios 1 2 \
set 4 bios_grub on
# bios / wipe
rwx_fs_wipe "${device}4"
# esp / wipe
rwx_fs_wipe "${device}3" "1M"
# esp / format
rwx_fs_make_fat "${device}3" "esp" "00000001"
# esp / mount
mkdir --parents "/media/esp"
mount "${device}3" "/media/esp"
# boot / wipe
rwx_fs_wipe "${device}2" "1G" 1
# boot / format
rwx_fs_make_btrfs "${device}2" "boot" \
"00000000-0000-0000-0000-00000000000b"
# boot / mount
mkdir --parents "/media/boot"
mount --options "autodefrag,compress-force=zstd" \
"${device}2" "/media/boot"
# crypt / wipe
rwx_fs_wipe "${device}1" "1G" 1
# crypt / encrypt
rwx_fs_luks_format "${passphrase}" "${device}1"
# crypt / open
echo "${passphrase}" |
cryptsetup luksOpen "${device}1" "crypt"
# passphrase
unset passphrase
}
rwx_rescue_wipe_2_make_ovh_vle2() {
local device="/dev/sdb"
local passphrase
# crypt / close
cryptsetup luksClose "crypt"
# read passphrase
passphrase="$(rwx_read_passphrase)"
# crypt / encrypt
rwx_fs_luks_format "${passphrase}" "${device}1"
# crypt / open
echo "${passphrase}" |
cryptsetup luksOpen "${device}1" "crypt"
# passphrase
unset passphrase
# crypt / format
rwx_fs_make_btrfs "/dev/mapper/crypt" "crypt" \
"00000000-0000-0000-0000-00000000000c"
# crypt / mount
mkdir --parents "/media/crypt"
mount --options "autodefrag,compress-force=zstd" \
"/dev/mapper/crypt" "/media/crypt"
# crypt / swap
rwx_fs_make_btrfs_swap "/media/crypt/swap" "4g" \
"00000000-0000-0000-0000-000000000005"
}

162
sh/self.sh Normal file
View file

@ -0,0 +1,162 @@
# meta doc
rwx_doc() {
local name="${1}"
[ -n "${name}" ] || return
local doc line module
rwx_ifs_set
for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do
while read -r line; do
case "${line}" in
"#"*) doc="${doc}${line}" ;;
"${name}() {")
echo "${doc}"
return
;;
*) doc="" ;;
esac
done <"${RWX_ROOT_SYSTEM}/${module}"
done
rwx_ifs_unset
}
# ╭──────┬───────╮
# │ self │ check │
# ╰──────┴───────╯
# check source code
rwx_self_check() {
# check format
rwx_log
rwx_shfmt "${RWX_ROOT_SYSTEM}"
# check syntax
rwx_log
rwx_shellcheck "${RWX_ROOT_SYSTEM}"
}
# ╭──────┬──────────╮
# │ self │ commands │
# ╰──────┴──────────╯
# get commands from root
rwx_self_commands() {
grep \
--directories "recurse" \
--no-filename \
"^${RWX_SELF_COMMAND}" "${RWX_ROOT_SYSTEM}" |
cut --delimiter "(" --fields 1 |
sed "s|^${RWX_SELF_COMMAND}||"
}
# ╭──────┬───────────╮
# │ self │ functions │
# ╰──────┴───────────╯
# get functions from root
rwx_self_functions() {
grep \
--directories "recurse" \
--no-filename \
"()" "${RWX_ROOT_SYSTEM}" |
cut --delimiter "(" --fields 1
}
# ╭──────┬──────╮
# │ self │ help │
# ╰──────┴──────╯
# output help message
rwx_self_help() {
rwx_log \
"rwx_… = functions" \
" a__… = aliases" \
" u__… = user"
}
# ╭──────┬──────╮
# │ self │ init │
# ╰──────┴──────╯
rwx_self_init() {
# run interactive extras
if rwx_shell_interactive; then
# help
rwx_log
rwx_self_help
fi
}
# ╭──────┬─────────╮
# │ self │ install │
# ╰──────┴─────────╯
_rwx_cmd_rwx_install() { rwx_self_install "${@}"; }
rwx_self_install() {
local target="${1}"
local command file root
# code
if [ -n "${target}" ]; then
root="${target}${RWX_ROOT_SYSTEM}"
rwx_remove "${root}"
cp --recursive "${RWX_ROOT_SYSTEM}" "${root}"
fi
# commands
root="${target}/usr/local/bin"
for command in $(rwx_self_commands); do
file="${root}/${command}"
rwx_remove "${file}"
rwx_link "${file}" "${RWX_MAIN_PATH}"
done
# sh
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
rwx_remove "${file}"
rwx_file_write "${file}" "\
export ENV=\"${RWX_MAIN_PATH}\"
"
# bash
file="${target}/etc/bash.bashrc"
rwx_remove "${file}"
rwx_link "${file}" "${RWX_MAIN_PATH}"
}
# ╭──────┬────────╮
# │ self │ subset │
# ╰──────┴────────╯
rwx_self_subset() {
local argument path
for argument in "${@}"; do
path="${RWX_ROOT_SYSTEM}/${argument}"
if [ -d "${path}" ]; then
local file
for file in $(rwx_find_shell "${path}"); do
echo "${argument}/${file}"
done
elif [ -f "${path}" ]; then
echo "${argument}"
fi
done
}
# ╭──────┬───────╮
# │ self │ write │
# ╰──────┴───────╯
rwx_self_write() {
local target="${1}"
if [ -n "${target}" ]; then
shift
local file text
text="#! /usr/bin/env sh
"
rwx_ifs_set
for file in $(rwx_self_subset "${@}"); do
text="${text}
$(cat "${RWX_ROOT_SYSTEM}/${file}")
"
done
rwx_ifs_unset
rwx_file_write "${target}" "${text}"
rwx_shfmt "${target}"
rwx_shellcheck_file "${target}"
fi
}

116
sh/shell.sh Normal file
View file

@ -0,0 +1,116 @@
_rwx_shell_color() {
local code="${1}"
case "${RWX_SHELL}" in
"bash")
printf "\x01\e[0"
if [ -n "${code}" ]; then
printf "%s" ";${code}"
fi
printf "m\x02"
;;
*)
printf "\033["
if [ -n "${code}" ]; then
printf "%s" "${code}"
else
printf "0"
fi
printf "m"
;;
esac
}
RWX_COLOR_BROWN="$(_rwx_shell_color 33)"
RWX_COLOR_CYAN="$(_rwx_shell_color 36)"
RWX_COLOR_DEFAULT="$(_rwx_shell_color)"
RWX_COLOR_GREEN="$(_rwx_shell_color 31)"
RWX_COLOR_MAGENTA="$(_rwx_shell_color 35)"
RWX_COLOR_RED="$(_rwx_shell_color 32)"
rwx_shell_configure() {
[ -n "${ENV}" ] || ENV="${RWX_MAIN_PATH}"
export ENV
# prompt
PS1="\$(rwx_shell_prompt \${?})"
PS2="├ "
# specific
case "${RWX_SHELL}" in
"bash")
# completion
local root="/usr/share/bash-completion"
local file="bash_completion"
local path="${root}/${file}"
# shellcheck disable=SC1090
[ -f "${path}" ] && . "${path}"
root="${root}/completions"
if [ -d "${root}" ]; then
set \
"git" \
"tar"
for file in "${@}"; do
path="${root}/${file}"
# shellcheck disable=SC1090
[ -f "${path}" ] && . "${path}"
done
fi
# history
HISTCONTROL="ignorespace"
HISTSIZE=-1
HISTTIMEFORMAT="%Y%m%d %H%M%S "
;;
*) ;;
esac
}
rwx_shell_configure
rwx_shell_prompt() {
local date host id
local code="${1}"
date="$(date +%H:%M:%S)"
local git
host="$(hostname)"
id="$(id --user)"
local path="${PWD}"
local user="${USER}"
local view="╰ "
# code
if [ "${code}" -ne 0 ]; then
view="${view}${RWX_COLOR_GREEN}"
else
view="${view}${RWX_COLOR_RED}"
fi
view="${view}${code}"
# date
view="${view}${RWX_COLOR_DEFAULT} @ "
view="${view}${RWX_COLOR_BROWN}${date}"
# git
if command -v "__git_ps1" >"/dev/null"; then
git="$(__git_ps1)"
if [ -n "${git}" ]; then
view="${view}${RWX_COLOR_DEFAULT}${RWX_COLOR_MAGENTA}${git}"
fi
fi
# new
view="${view}\\n"
# path
view="${view}${RWX_COLOR_CYAN}${path}"
# new
view="${view}\\n"
# frame
view="${view}${RWX_COLOR_DEFAULT}"
# user
if [ "${id}" -eq 0 ]; then
view="${view}${RWX_COLOR_GREEN}"
else
view="${view}${RWX_COLOR_RED}"
fi
view="${view}${user}"
# host
view="${view}${RWX_COLOR_DEFAULT} @ "
view="${view}${RWX_COLOR_BROWN}${host}"
# new
view="${view}\\n"
# prompt
view="${view}${RWX_COLOR_DEFAULT}${PS2}"
# print
printf "%b" "${view}"
}

264
sh/tmux.sh Normal file
View file

@ -0,0 +1,264 @@
# ╭──────┬───────╮
# │ tmux │ setup │
# ╰──────┴───────╯
rwx_tmux_setup() {
local file
file="${HOME}/.tmux.conf"
rwx_file_write "${file}" "\
# ╭────────╮
# │ option │
# ╰────────╯
# empty name for windows
set-option -g automatic-rename-format '#{pane_current_command}'
set-option -g automatic-rename on
# first index number
set-option -g base-index 1
# display duration
set-option -g display-time 1536
# extend history limit
set-option -g history-limit 1048576
# style for messages
set-option -g message-style bg=red,fg=white
# activity monitoring
set-window-option -g monitor-activity on
# silence monitoring
set-window-option -g monitor-silence 0
# enable mouse actions
set-option -g mouse on
# prefix with ^B or F12
set-option -g prefix C-b
set-option -g prefix2 F12
# renumber windows after closing one
set-option -g renumber-windows on
# enable title
set-option -g set-titles on
# set title to working directory
set-option -g set-titles-string '\
#{session_name}\
- \
#{window_index}∕#{session_windows} #{window_name}\
- \
#{pane_index}∕#{window_panes} #{pane_current_command}\
'
# ╭────────┬──────╮
# │ option │ pane │
# ╰────────┴──────╯
# first index number
set-option -g pane-base-index 1
# ╭────────┬──────┬────────╮
# │ option │ pane │ border │
# ╰────────┴──────┴────────╯
# active style
set-option -g pane-active-border-style fg=green
# regular style
set-option -g pane-border-style fg=blue
# ╭────────┬────────╮
# │ option │ status │
# ╰────────┴────────╯
# status lines
set-option -g status 3
# background color
set-option -g status-bg '#0D0D0D'
# foreground color
set-option -g status-fg white
# line 1
set-option -g status-format[0] '\
#{W:\
#[bg=##202020] #[bg=##303030]\
#{?window_zoomed_flag,#[fg=magenta][, }\
#[fg=yellow]#{window_index}\
#{?window_zoomed_flag,#[fg=magenta]], }\
\
#{?window_active,#[fg=green],\
#{?window_activity_flag,#[fg=red],#[fg=blue]}}\
#{window_name}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]%H:%M:%S\
#[bg=##303030] #[bg=##202020]\
#{?client_prefix,#[fg=green]p, }\
'
# line 2
set-option -g status-format[1] '\
#{S:\
#[bg=##202020] #[bg=##303030] \
#{?session_many_attached,#[fg=red],\
#{?session_attached,#[fg=magenta],#[fg=blue]}}\
#{session_name}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[fg=yellow]→ #[fg=green]#{session_name} \
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]%Y-%m-%d\
#[bg=##303030] #[bg=##202020] \
'
# line 3
set-option -g status-format[2] '\
#[fg=cyan]#{pane_current_path}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]#{host}\
#[bg=##303030] #[bg=##202020] \
'
# line 4
set-option -g status-format[3] '\
#{P:\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]#{pane_index}\
\
#{?pane_active,#[fg=green],#[fg=blue]}\
#{pane_current_command}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#{?uid,#[fg=green],#[fg=red]}\
#{user}\
#[bg=##303030] #[bg=##202020] \
'
# line 5
set-option -g status-format[4] '\
#{P:\
#[bg=##202020] #[bg=##303030] \
#[fg=yellow]#{pane_index}\
\
#{?pane_active,#[fg=green],#[fg=blue]}\
#{pane_width}×#{pane_height}\
#[bg=##303030] #[bg=##202020] \
#[bg=default] \
}\
#[align=right]\
#[bg=##202020] #[bg=##303030] \
#[fg=green]#{window_width}×#{window_height}\
#[bg=##303030] #[bg=##202020] \
'
# refresh period
set-option -g status-interval 1
# bar location
set-option -g status-position bottom
# ╭─────╮
# │ key │
# ╰─────╯
# detach client
bind-key -n F6 detach-client
# new window
bind-key -n F2 new-window
# select pane
bind-key -n C-S-Down select-pane -D
bind-key -n C-S-Left select-pane -L
bind-key -n C-S-Right select-pane -R
bind-key -n C-S-Up select-pane -U
# status lines
bind-key -n C-F10 set-option -g status off
bind-key -n C-F1 set-option -g status on
bind-key -n C-F2 set-option -g status 2
bind-key -n C-F3 set-option -g status 3
bind-key -n C-F4 set-option -g status 4
bind-key -n C-F5 set-option -g status 5
# switch session
bind-key -n M-Down switch-client -n
bind-key -n M-Up switch-client -p
# switch window
bind-key -n M-Left previous-window
bind-key -n M-Right next-window
# ╭─────┬────────╮
# │ key │ prefix │
# ╰─────┴────────╯
# rename
bind-key C-s command-prompt { rename-session '%%' }
bind-key C-w command-prompt { rename-window '%%' }
# split window
bind-key h split-window -h
bind-key v split-window -v
# toggle mouse
bind-key t set-option -g mouse \\; display-message 'mouse = #{mouse}'
# reload configuration
bind-key r source-file ${file} \\; display-message 'source-file ${file}'
# swap window
bind-key M-Left swap-window -t -1
bind-key M-Right swap-window -t +1
# ╭─────────────╮
# │ default │
# ╭───────────┬─────────┼─────┬───────┤
# │ -n │ F12 │ -n │ C-b │
# ╭───────────────────┼───────────┼─────────┼─────┼───────┤
# │ command-prompt │ │ │ │ : │
# │ copy-mode │ │ │ │ PPage │
# │ detach-client │ │ │ │ d │
# │ new-session │ │ │ │ │
# │ new-window │ F2 │ │ │ c │
# │ next-window │ M-Right │ │ │ n │
# │ previous-window │ M-Left │ │ │ p │
# │ rename-session │ │ C-s │ │ │
# │ rename-window │ │ C-w │ │ │
# │ resize-pane -Z │ │ │ │ z │
# │ select-pane -D │ C-S-Down │ │ │ │
# │ select-pane -L │ C-S-Left │ │ │ │
# │ select-pane -R │ C-S-Right │ │ │ │
# │ select-pane -U │ C-S-Up │ │ │ │
# │ set -g mouse │ │ t │ │ │
# │ set -g status off │ C-F10 │ │ │ │
# │ set -g status on │ C-F1 │ │ │ │
# │ set -g status 2 │ C-F2 │ │ │ │
# │ set -g status 3 │ C-F3 │ │ │ │
# │ set -g status 4 │ C-F4 │ │ │ │
# │ set -g status 5 │ C-F5 │ │ │ │
# │ source-file │ │ r │ │ │
# │ split-window -h │ │ h │ │ % │
# │ split-window -v │ │ v │ │ \" │
# │ swap-window -t -1 │ │ M-Left │ │ │
# │ swap-window -t +1 │ │ M-Right │ │ │
# │ switch-client -n │ M-Down │ │ │ │
# │ switch-client -p │ M-Up │ │ │ │
# ╰───────────────────┴───────────┴─────────┴─────┴───────╯
"
}

76
sh/util.sh Normal file
View file

@ -0,0 +1,76 @@
rwx_file_append() {
local file="${1}"
local text="${2}"
if [ -n "${file}" ]; then
printf "%s" "${text}" >>"${file}"
fi
}
rwx_file_empty() {
local file="${1}"
if [ -n "${file}" ]; then
rwx_file_write "${file}" ""
fi
}
rwx_file_write() {
local file="${1}"
local text="${2}"
if [ -n "${file}" ]; then
printf "%s" "${text}" >"${file}"
fi
}
rwx_link() {
local link="${1}"
local target="${2}"
ln \
--symbolic \
"${target}" \
"${link}"
}
rwx_list_block_devices() {
lsblk \
--noempty \
--output "NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS"
}
rwx_not() {
case "${1}" in
"false") echo "true" ;;
"true") echo "false" ;;
*) ;;
esac
}
rwx_read_passphrase() {
rwx_read_secret "PassPhrase: "
}
rwx_read_secret() {
local prompt="${1}"
local secret
printf "%s" "${prompt}" 1>&2
stty -echo
read -r secret
stty echo
echo >&2
echo "${secret}"
unset secret
}
rwx_remove() {
rm \
--force \
--recursive \
"${@}"
}
rwx_warn_wipe() {
local tmp
rwx_list_block_devices
printf "%s" "WIPE ${*} /?\\ OR CANCEL /!\\"
read -r tmp
rwx_log_trace "${tmp}"
}