diff --git a/readme.md b/readme.md index 905c975..ccc5291 100644 --- a/readme.md +++ b/readme.md @@ -1,55 +1,96 @@ # Read Write eXecute -A tiny framework to read, write & execute things. +One project to rule them all. --- -## Why +## Table Of Contents {#toc} + +* 1 [Why](#why) +* 2 [How](#how) + * 2.1 [Shell](#how-shell) + * 2.2 [Python](#how-python) +* 3 [What](#what) + * 3.1 [Features](#what-features) + * 3.2 [Environment variables](#what-variables) +* 4 [Who](#who) +* 5 [Where](#where) + * 5.1 [Chat](#where-chat) + * 5.2 [Repo](#where-repo) + * 5.3 [Site](#where-site) +* 6 [When](#when) + * 6.1 [Release tasks](#when-release) + * 6.2 [Further tasks](#when-further) --- -## How +## 1 [Why](#toc) {#why} --- -## What +## 2 [How](#toc) {#how} + +Two interpreted languages for flexibility. + +### 2.1 [Shell](#how) {#how-shell} + +* [X] functions to + * [X] alias + * [X] lint + * [X] Git + * [X] Python + * [X] Shell + * [X] log + * [X] rescue + * [X] Hetzner + * [X] OVH +* [X] profiles + * [X] ffmpeg + * [X] tmux + +### 2.2 [Python](#how) {#how-python} --- -## Who +## 3 [What](#toc) {#what} -### By +### 3.1 [Features](#what) {#what-features} -* [Marc Beninca](https://marc.beninca.link) +* [ ] self + * [ ] install modules -### For - -* myself +### 3.2 [Environment variables](#what) {#what-variables} --- -## Where +## 4 [Who](#toc) {#who} -### Chat +* Author: [Marc Beninca](https://forge.rwx.work/marc.beninca) + +--- + +## 5 [Where](#toc) {#where} + +### 5.1 [Chat](#where) {#where-chat} * [Discord](https://discord.com/channels/983145051985154108/1255894474895134761) * [IRC](ircs://irc.libera.chat/##rwx) -### Forge +### 5.2 [Repo](#where) {#where-repo} -* [Repository](https://forge.rwx.work/rwx.work/rwx) -* [RSS](https://forge.rwx.work/rwx.work/rwx.rss) -* [Workflows](https://forge.rwx.work/rwx.work/rwx/actions) +* [Code](https://forge.rwx.work/rwx.work/rwx) +* [Feed](https://forge.rwx.work/rwx.work/rwx.rss) +* [Actions](https://forge.rwx.work/rwx.work/rwx/actions) -### Deployment +### 5.3 [Site](#where) {#where-site} -* [Site](https://rwx.rwx.work) +* [Web](https://rwx.rwx.work) --- -## When +## 6 [When](#toc) {#when} -### Task stack +### 6.1 [Release tasks](#when) {#when-release} #### Python @@ -72,3 +113,5 @@ A tiny framework to read, write & execute things. * apt * apt-file search | grep * ffmpeg + +### 6.2 [Further tasks](#when) {#when-further} diff --git a/sh/alias/git.sh b/sh/alias/git.sh index fe5380a..35402d9 100644 --- a/sh/alias/git.sh +++ b/sh/alias/git.sh @@ -1,10 +1,8 @@ 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 +A %C(green)%ai %an %ae +C %C(blue)%ci %cn %ce %B" # add to index diff --git a/sh/file.sh b/sh/file.sh new file mode 100644 index 0000000..becca76 --- /dev/null +++ b/sh/file.sh @@ -0,0 +1,26 @@ +# ╭──────╮ +# │ file │ +# ╰──────╯ + +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 +} diff --git a/sh/fs.sh b/sh/fs.sh index 0db5696..26b11c7 100644 --- a/sh/fs.sh +++ b/sh/fs.sh @@ -1,3 +1,7 @@ +# ╭────╮ +# │ fs │ +# ╰────╯ + rwx_fs_make_btrfs() { local device="${1}" local label="${2}" diff --git a/sh/gnome.sh b/sh/gnome.sh index b17a058..a571a88 100644 --- a/sh/gnome.sh +++ b/sh/gnome.sh @@ -23,12 +23,18 @@ rwx_gnome_background_win3() { # ╰───────┴───────╯ rwx_gnome_proxy() { - local value - case "${1}" in - "on") value="manual" ;; - *) value="none" ;; + local port="${1}" + local prefix="org.gnome.system.proxy" + case "${port}" in + "") + gsettings set "${prefix}" "mode" "none" + ;; + *) + gsettings set "${prefix}" "mode" "manual" + gsettings set "${prefix}.socks" "host" "localhost" + gsettings set "${prefix}.socks" "port" "${port}" + ;; esac - gsettings set "org.gnome.system.proxy" "mode" "${value}" } # ╭───────┬─────╮ diff --git a/sh/log/log.sh b/sh/log/log.sh index b921d45..a3013e8 100644 --- a/sh/log/log.sh +++ b/sh/log/log.sh @@ -1,3 +1,11 @@ +# ╭─────╮ +# │ log │ +# ╰─────╯ + +# ╭─────┬───────────╮ +# │ log │ constants │ +# ╰─────┴───────────╯ + RWX_LOG_LEVEL_FATAL=0 RWX_LOG_LEVEL_ERROR=1 RWX_LOG_LEVEL_WARN=2 @@ -5,8 +13,16 @@ RWX_LOG_LEVEL_INFO=3 RWX_LOG_LEVEL_DEBUG=4 RWX_LOG_LEVEL_TRACE=5 +# ╭─────┬───────────╮ +# │ log │ variables │ +# ╰─────┴───────────╯ + RWX_LOG_LEVEL=${RWX_LOG_LEVEL_INFO} +# ╭─────┬─────╮ +# │ log │ log │ +# ╰─────┴─────╯ + rwx_log() { rwx_log_info "${@}"; } rwx_log_debug() { diff --git a/sh/main.sh b/sh/main.sh index 802418f..63ca6bf 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -1,5 +1,9 @@ #! /usr/bin/env sh +# ╭──────╮ +# │ main │ +# ╰──────╯ + # ╭──────┬───────────╮ # │ main │ constants │ # ╰──────┴───────────╯ @@ -27,16 +31,50 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" -# ╭──────┬───────╮ -# │ main │ shell │ -# ╰──────┴───────╯ +# ╭──────┬──────╮ +# │ main │ main │ +# ╰──────┴──────╯ -# test if active shell is in interactive mode -rwx_shell_interactive() { - case "${-}" in - *i*) ;; - *) return 1 ;; - esac +# run initial steps +rwx_main() { + # source system root + if ! rwx_source "${RWX_ROOT_SYSTEM}"; then + __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" + return 1 + fi + # source 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 +} + +# ╭──────┬────────╮ +# │ main │ source │ +# ╰──────┴────────╯ + +# source code from file path +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 } # ╭──────┬─────╮ @@ -53,6 +91,35 @@ __rwx_log() { fi } +# ╭──────┬───────╮ +# │ main │ shell │ +# ╰──────┴───────╯ + +# test if active shell is in interactive mode +rwx_shell_interactive() { + case "${-}" in + *i*) ;; + *) return 1 ;; + esac +} + +# ╭──────┬─────╮ +# │ main │ ifs │ +# ╰──────┴─────╯ + +# set internal field separator to line feed +rwx_ifs_set() { + _RWX_IFS="${IFS}" + IFS=" +" +} + +# unset internal field separator +rwx_ifs_unset() { + IFS="${_RWX_IFS}" + unset RWX_IFS +} + # ╭──────┬──────╮ # │ main │ find │ # ╰──────┴──────╯ @@ -81,64 +148,8 @@ rwx_find_shell() { } # ╭──────┬─────╮ -# │ main │ ifs │ +# │ main │ run │ # ╰──────┴─────╯ -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 "${@}" diff --git a/sh/self.sh b/sh/self.sh index 732e9c2..0a8f33e 100644 --- a/sh/self.sh +++ b/sh/self.sh @@ -92,7 +92,7 @@ rwx_self_init() { _rwx_cmd_rwx_install() { rwx_self_install "${@}"; } rwx_self_install() { local target="${1}" - local command file root + local command file name root # code if [ -n "${target}" ]; then root="${target}${RWX_ROOT_SYSTEM}" @@ -101,10 +101,14 @@ rwx_self_install() { fi # commands root="${target}/usr/local/bin" + name="${RWX_SELF_NAME}.sh" + file="${root}/${name}" + rwx_remove "${file}" + rwx_link "${file}" "${RWX_MAIN_PATH}" for command in $(rwx_self_commands); do file="${root}/${command}" rwx_remove "${file}" - rwx_link "${file}" "${RWX_MAIN_PATH}" + rwx_link "${file}" "${name}" done # sh file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh" diff --git a/sh/tmux.sh b/sh/tmux.sh index d9813e1..ea54a59 100644 --- a/sh/tmux.sh +++ b/sh/tmux.sh @@ -1,3 +1,7 @@ +# ╭──────╮ +# │ tmux │ +# ╰──────╯ + # ╭──────┬───────╮ # │ tmux │ setup │ # ╰──────┴───────╯ @@ -47,6 +51,8 @@ set-option -g set-titles on # set title to working directory set-option -g set-titles-string '\ +#(basename \"\${TMUX}\" | cut --delimiter \",\" --fields \"1\")\ + - \ #{session_name}\ - \ #{window_index}∕#{session_windows} #{window_name}\ @@ -76,10 +82,10 @@ set-option -g pane-border-style fg=blue # ╰────────┴────────╯ # status lines -set-option -g status 3 +set-option -g status 2 # background color -set-option -g status-bg '#0D0D0D' +set-option -g status-bg '#080808' # foreground color set-option -g status-fg white @@ -87,83 +93,99 @@ 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] \ +#{?window_activity_flag,#[fg=red],#[fg=yellow]}}\ +#[bg=##181818]#{?window_zoomed_flag,#[fg=magenta][, }\ +#[bg=##282828]#{window_name}\ +#[bg=##181818]#{?window_zoomed_flag,#[fg=magenta]], }\ +#[fg=default]\ #[bg=default] \ }\ #[align=right]\ -#[bg=##202020] #[bg=##303030] \ -#[fg=yellow]%H:%M:%S\ -#[bg=##303030] #[bg=##202020]\ -#{?client_prefix,#[fg=green]p, }\ +#[fg=yellow]\ +#[bg=##181818] \ +#[bg=##282828]%H:%M:%S\ +#[bg=##181818]#{?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] \ +#{?session_many_attached,#[fg=magenta],\ +#{?session_attached,#[fg=red],#[fg=yellow]}}\ +#[bg=##181818] \ +#[bg=##282828]#{session_name}\ +#[bg=##181818] \ +#[fg=default]\ #[bg=default] \ }\ -#[fg=yellow]→ #[fg=green]#{session_name} \ +#[fg=yellow]→\ +#[fg=default] \ +#[fg=green]\ +#[bg=##181818] \ +#[bg=##282828]#{session_name}\ +#[bg=##181818] \ #[align=right]\ -#[bg=##202020] #[bg=##303030] \ -#[fg=yellow]%Y-%m-%d\ -#[bg=##303030] #[bg=##202020] \ +#[fg=yellow]\ +#[bg=##181818] \ +#[bg=##282828]%Y-%m-%d\ +#[bg=##181818] \ ' # line 3 set-option -g status-format[2] '\ -#[fg=cyan]#{pane_current_path}\ +#[fg=yellow]\ +#(lsof -U \ +| awk \"/^tmux:.*\\(LISTEN\\)$/ {print \\\$9}\" \ +| xargs -n \"1\" basename \ +| sed \"s/^/#[fg=yellow]#[bg=##181818] #[bg=##282828]/\ +;s/\$/#[bg=##181818] #[fg=default]#[bg=default] /\" \ +| xargs echo \ +)\ +#[fg=default] \ +#[fg=yellow]→\ +#[fg=default] \ +#[fg=green]\ +#[bg=##181818] \ +#[bg=##282828]#(basename \"\${TMUX}\" \ +| cut --delimiter \",\" --fields \"1\")\ +#[bg=##181818] \ #[align=right]\ -#[bg=##202020] #[bg=##303030] \ -#[fg=yellow]#{host}\ -#[bg=##303030] #[bg=##202020] \ +#[fg=yellow]\ +#[bg=##181818] \ +#[bg=##282828]#{host}\ +#[bg=##181818] \ ' # line 4 set-option -g status-format[3] '\ #{P:\ -#[bg=##202020] #[bg=##303030] \ -#[fg=yellow]#{pane_index}\ - \ -#{?pane_active,#[fg=green],#[fg=blue]}\ +#[bg=##181818] #[bg=##282828]\ +#{?pane_active,#[fg=green],#[fg=yellow]}\ #{pane_current_command}\ -#[bg=##303030] #[bg=##202020] \ +#[bg=##181818] \ #[bg=default] \ }\ #[align=right]\ -#[bg=##202020] #[bg=##303030] \ +#[bg=##181818] #[bg=##282828]\ #{?uid,#[fg=green],#[fg=red]}\ #{user}\ -#[bg=##303030] #[bg=##202020] \ +#[bg=##181818] \ ' # line 5 set-option -g status-format[4] '\ #{P:\ -#[bg=##202020] #[bg=##303030] \ -#[fg=yellow]#{pane_index}\ - \ -#{?pane_active,#[fg=green],#[fg=blue]}\ +#[bg=##181818] #[bg=##282828]\ +#{?pane_active,#[fg=green],#[fg=yellow]}\ #{pane_width}×#{pane_height}\ -#[bg=##303030] #[bg=##202020] \ +#[bg=##181818] \ #[bg=default] \ }\ #[align=right]\ -#[bg=##202020] #[bg=##303030] \ +#[bg=##181818] #[bg=##282828]\ #[fg=green]#{window_width}×#{window_height}\ -#[bg=##303030] #[bg=##202020] \ +#[bg=##181818] \ ' # refresh period @@ -179,8 +201,9 @@ set-option -g status-position bottom # detach client bind-key -n F6 detach-client -# new window -bind-key -n F2 new-window +# new +bind-key -n S-M-Down new-session +bind-key -n S-M-Right new-window # select pane bind-key -n C-S-Down select-pane -D @@ -189,7 +212,7 @@ 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-F6 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 @@ -216,12 +239,15 @@ bind-key C-w command-prompt { rename-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}' +# kill server +bind-key k kill-server # reload configuration bind-key r source-file ${file} \\; display-message 'source-file ${file}' +# toggle mouse +bind-key t set-option -g mouse \\; display-message 'mouse = #{mouse}' + # swap window bind-key M-Left swap-window -t -1 bind-key M-Right swap-window -t +1 @@ -233,7 +259,8 @@ bind-key M-Right swap-window -t +1 # ╭───────────────────┼───────────┼─────────┼─────┼───────┤ # │ command-prompt │ │ │ │ : │ # │ copy-mode │ │ │ │ PPage │ -# │ detach-client │ │ │ │ d │ +# │ detach-client │ F6 │ │ │ d │ +# │ kill-server │ │ k │ │ │ # │ new-session │ │ │ │ │ # │ new-window │ F2 │ │ │ c │ # │ next-window │ M-Right │ │ │ n │ @@ -246,7 +273,7 @@ bind-key M-Right swap-window -t +1 # │ 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 off │ C-F6 │ │ │ │ # │ set -g status on │ C-F1 │ │ │ │ # │ set -g status 2 │ C-F2 │ │ │ │ # │ set -g status 3 │ C-F3 │ │ │ │ diff --git a/sh/util.sh b/sh/util.sh index cbcd67a..a3c53bf 100644 --- a/sh/util.sh +++ b/sh/util.sh @@ -1,25 +1,6 @@ -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 -} +# ╭──────╮ +# │ util │ +# ╰──────╯ rwx_link() { local link="${1}"