Compare commits

...

15 commits

Author SHA1 Message Date
091c9339f7
code/command
All checks were successful
/ job (push) Successful in 4m26s
2025-07-08 01:43:30 +02:00
b45449421e
test/commands 2025-07-08 01:25:22 +02:00
ff3716148a
find,sort 2025-07-08 01:20:36 +02:00
aadfe212c2
main/shell 2025-07-08 01:15:21 +02:00
19249747c0
main/log 2025-07-08 01:13:06 +02:00
b342a2c9e1
main/source 2025-07-08 01:12:02 +02:00
cd1701fb71
main/main,cache 2025-07-08 00:48:18 +02:00
adef5c0768
rwx/code 2025-07-08 00:44:25 +02:00
cc1f8f816a
code/commands 2025-07-08 00:05:07 +02:00
51cb88d0d3
shell/shortcuts 2025-07-07 23:44:45 +02:00
24a931cbfc
shell/mv 2025-07-07 23:38:09 +02:00
aec3d1a0af
shell/main
All checks were successful
/ job (push) Successful in 5m27s
2025-07-07 21:55:01 +02:00
efe07205fa
shell/0 2025-07-07 21:50:34 +02:00
ff5116380c
bash/if 2025-07-07 21:43:48 +02:00
a06bab3e97
shell/bash 2025-07-07 21:38:07 +02:00
7 changed files with 211 additions and 139 deletions

View file

@ -1,29 +0,0 @@
# 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 ../..
}

View file

@ -32,6 +32,7 @@ BEGIN {
RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END
RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END
RE_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END
RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END
RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END
RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END
@ -40,6 +41,7 @@ BEGIN {
RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END
alias = 0 alias = 0
command = 0
f = "" f = ""
reset() reset()
module = 0 module = 0
@ -50,6 +52,10 @@ BEGIN {
if (match($0, RE_ALIAS, m)) { if (match($0, RE_ALIAS, m)) {
print m[1] print m[1]
} }
} else if (action == "commands") {
if (match($0, RE_COMMAND, m)) {
print m[1]
}
} else if (action == "constants") { } else if (action == "constants") {
if (match($0, RE_CONSTANT, m)) { if (match($0, RE_CONSTANT, m)) {
print m[1] print m[1]
@ -89,6 +95,11 @@ BEGIN {
if (m[1] == target) { if (m[1] == target) {
alias = 1 alias = 1
} }
} else if (match($0, RE_COMMAND, m)) {
append("/ " m[1])
if (m[1] == target) {
command = 1
}
# set # set
} else if (match($0, RE_CONSTANT, m)) { } else if (match($0, RE_CONSTANT, m)) {
if (m[1] == target) { if (m[1] == target) {
@ -114,6 +125,9 @@ BEGIN {
if (alias) { if (alias) {
print "= " target print "= " target
output(f, "function") output(f, "function")
} else if (command) {
print "/ " target
output(f, "function")
} else if (f == target) { } else if (f == target) {
output(f, "function") output(f, "function")
} else { } else {

View file

@ -12,6 +12,8 @@ _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")"
_rwx_code_aliases="" _rwx_code_aliases=""
# cache for code aliases functions # cache for code aliases functions
_rwx_code_aliases_functions="" _rwx_code_aliases_functions=""
# cache for code commands
_rwx_code_commands=""
# cache for code constants # cache for code constants
_rwx_code_constants="" _rwx_code_constants=""
# cache for code functions # cache for code functions
@ -23,7 +25,7 @@ _rwx_code_variables=""
# │ code │ install │ # │ code │ install │
# ╰──────┴─────────╯ # ╰──────┴─────────╯
#= rwx_install #/ rwx_install
rwx_code_install() { rwx_code_install() {
local target="${1}" local target="${1}"
local command file name root local command file name root
@ -44,7 +46,7 @@ rwx_code_install() {
rwx_remove "${file}" rwx_remove "${file}"
rwx_link "${file}" "${name}" rwx_link "${file}" "${name}"
done <<EOF done <<EOF
${_rwx_code_aliases} ${_rwx_code_commands}
EOF EOF
# sh # sh
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh" file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
@ -100,6 +102,11 @@ rwx_code_aliases_functions() {
echo "${_rwx_code_aliases_functions}" echo "${_rwx_code_aliases_functions}"
} }
# show the cached commands
rwx_code_commands() {
echo "${_rwx_code_commands}"
}
# show the cached constants # show the cached constants
#= rcc #= rcc
rwx_code_constants() { rwx_code_constants() {
@ -157,6 +164,8 @@ rwx_code_load() {
done <<EOF done <<EOF
${_rwx_code_aliases_functions} ${_rwx_code_aliases_functions}
EOF EOF
# parse commands
_rwx_code_commands="$(rwx_code_parse "commands")"
# parse constants # parse constants
_rwx_code_constants="$(rwx_code_parse "constants")" _rwx_code_constants="$(rwx_code_parse "constants")"
# parse functions # parse functions

View file

@ -26,8 +26,8 @@ RWX_SELF_NAME="rwx"
# │ main │ variables │ # │ main │ variables │
# ╰──────┴───────────╯ # ╰──────┴───────────╯
# currently running shell name # cache of all sourced code modules
RWX_SHELL="$(cat "/proc/${$}/comm")" _rwx_code=""
# system root directory of the project # system root directory of the project
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}" RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
@ -37,6 +37,109 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
# path to the entrypoint main file of the project # path to the entrypoint main file of the project
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
# ╭──────┬──────╮
# │ main │ find │
# ╰──────┴──────╯
# find directory’s files by extension
#> find
#> sort
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 │ 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 │ source │
# ╰──────┴────────╯
# source code from file path
rwx_source() {
local root="${1}"
[ -d "${root}" ] ||
return 1
local file="${2}"
local count module modules
count=0
__rwx_log "" \
". ${root}"
modules="$(rwx_find_shell "${root}" "${file}")"
while IFS= read -r module; do
count=$((count + 1))
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
# shellcheck disable=SC1090
. "${root}/${module}"
# cache code
rwx_cache "${root}" "${module}"
done <<EOF
${modules}
EOF
}
# ╭──────┬───────╮
# │ main │ cache │
# ╰──────┴───────╯
# cache source code of a module
# inside a global code variable
#> cat
rwx_cache() {
local root="${1}"
local module="${2}"
local name="${module%.sh}"
local path="${root}/${module}"
local text
text="$(cat "${path}")"
# all source code
_rwx_code="${_rwx_code}\
#. ${name}
${text}
"
}
# ╭──────┬──────╮ # ╭──────┬──────╮
# │ main │ main │ # │ main │ main │
# ╰──────┴──────╯ # ╰──────┴──────╯
@ -76,109 +179,6 @@ rwx_main() {
fi fi
} }
# ╭──────┬───────╮
# │ main │ cache │
# ╰──────┴───────╯
# cache of all sourced code modules
_rwx_code=""
# cache source code of a module
# inside a global code variable
rwx_cache() {
local root="${1}"
local module="${2}"
local name="${module%.sh}"
local path="${root}/${module}"
local text
text="$(cat "${path}")"
# all source code
_rwx_code="${_rwx_code}\
#. ${name}
${text}
"
}
# ╭──────┬────────╮
# │ main │ source │
# ╰──────┴────────╯
# source code from file path
rwx_source() {
local root="${1}"
[ -d "${root}" ] ||
return 1
local file="${2}"
local count module modules
count=0
__rwx_log "" \
". ${root}"
modules="$(rwx_find_shell "${root}" "${file}")"
while IFS= read -r module; do
count=$((count + 1))
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
# shellcheck disable=SC1090
. "${root}/${module}"
# cache code
rwx_cache "${root}" "${module}"
done <<EOF
${modules}
EOF
}
# ╭──────┬─────╮
# │ main │ log │
# ╰──────┴─────╯
__rwx_log() {
if rwx_shell_interactive; then
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
echo "${line}"
done
fi
}
# ╭──────┬───────╮
# │ main │ shell │
# ╰──────┴───────╯
# test if active shell is in interactive mode
rwx_shell_interactive() {
case "${-}" in
*i*) ;;
*) return 1 ;;
esac
}
# ╭──────┬──────╮
# │ 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 │ run │ # │ main │ run │
# ╰──────┴─────╯ # ╰──────┴─────╯

View file

@ -1,3 +1,10 @@
# ╭───────╮
# │ shell │
# ╰───────╯
# currently running shell name
RWX_SHELL="$(cat "/proc/${$}/comm")"
_rwx_shell_color() { _rwx_shell_color() {
local code="${1}" local code="${1}"
case "${RWX_SHELL}" in case "${RWX_SHELL}" in
@ -19,6 +26,11 @@ _rwx_shell_color() {
;; ;;
esac esac
} }
# ╭───────┬───────────╮
# │ shell │ constants │
# ╰───────┴───────────╯
RWX_COLOR_BROWN="$(_rwx_shell_color 33)" RWX_COLOR_BROWN="$(_rwx_shell_color 33)"
RWX_COLOR_CYAN="$(_rwx_shell_color 36)" RWX_COLOR_CYAN="$(_rwx_shell_color 36)"
RWX_COLOR_DEFAULT="$(_rwx_shell_color)" RWX_COLOR_DEFAULT="$(_rwx_shell_color)"
@ -26,6 +38,10 @@ RWX_COLOR_GREEN="$(_rwx_shell_color 31)"
RWX_COLOR_MAGENTA="$(_rwx_shell_color 35)" RWX_COLOR_MAGENTA="$(_rwx_shell_color 35)"
RWX_COLOR_RED="$(_rwx_shell_color 32)" RWX_COLOR_RED="$(_rwx_shell_color 32)"
# ╭───────┬───────────╮
# │ shell │ functions │
# ╰───────┴───────────╯
rwx_shell_configure() { rwx_shell_configure() {
[ -n "${ENV}" ] || ENV="${RWX_MAIN_PATH}" [ -n "${ENV}" ] || ENV="${RWX_MAIN_PATH}"
export ENV export ENV
@ -60,7 +76,6 @@ rwx_shell_configure() {
*) ;; *) ;;
esac esac
} }
rwx_shell_configure
rwx_shell_prompt() { rwx_shell_prompt() {
local date host id local date host id
@ -114,3 +129,39 @@ rwx_shell_prompt() {
# print # print
printf "%b" "${view}" printf "%b" "${view}"
} }
# ╭───────┬───────────╮
# │ shell │ shortcuts │
# ╰───────┴───────────╯
# shorten alias
#= a
rwx_shell_alias() {
alias \
"${@}"
}
# swap directory (current ↔ previous)
#= sd
rwx_shell_swap_directory() {
cd \
- ||
return
}
# exit terminal
#= x
rwx_shell_exit() {
exit \
"${@}"
}
# ╭───────┬──────╮
# │ shell │ main │
# ╰───────┴──────╯
rwx_shell_main() {
rwx_shell_configure
}
rwx_shell_main

24
sh/shell/bash.sh Normal file
View file

@ -0,0 +1,24 @@
# ╭───────┬──────╮
# │ shell │ bash │
# ╰───────┴──────╯
if [ "${RWX_SHELL}" = "bash" ]; then
# shellcheck disable=SC3033
..() {
cd ..
}
# shellcheck disable=SC3033
...() {
cd ../..
}
# shellcheck disable=SC3033
....() {
cd ../../..
}
# shellcheck disable=SC3033
.....() {
cd ../../../..
}
fi

View file

@ -21,7 +21,8 @@ rwx_test_code() {
"variables" \ "variables" \
"functions" \ "functions" \
"aliases" \ "aliases" \
"aliases_functions" "aliases_functions" \
"commands"
rwx_code rwx_code
for items in "${@}"; do for items in "${@}"; do
echo echo
@ -46,7 +47,9 @@ rwx_test_doc() {
"rwx_cache" \ "rwx_cache" \
\ \
"alias/batcat" \ "alias/batcat" \
"b" "b" \
\
"rwx_install"
for item in "${@}"; do for item in "${@}"; do
echo echo
rwx_code_doc "${item}" rwx_code_doc "${item}"