diff --git a/sh/alias/batcat.sh b/sh/alias/batcat.sh index 99d8373..c573adb 100644 --- a/sh/alias/batcat.sh +++ b/sh/alias/batcat.sh @@ -1,4 +1,4 @@ -b() { a__bat "${@}"; } +#= b a__bat() { batcat \ "${@}" diff --git a/sh/alias/gpg.sh b/sh/alias/gpg.sh deleted file mode 100644 index eb19651..0000000 --- a/sh/alias/gpg.sh +++ /dev/null @@ -1,12 +0,0 @@ -# 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 -} diff --git a/sh/gpg.sh b/sh/gpg.sh index b5ce07b..e1bf31c 100644 --- a/sh/gpg.sh +++ b/sh/gpg.sh @@ -1,4 +1,14 @@ +# functions to handle gpg + +# turn gpg agent off +#= gak +rwx_gpg_agent_kill() { + gpgconf \ + --kill "gpg-agent" +} + # bind gpg agent to current tty +#= gau rwx_gpg_agent_update() { gpg-connect-agent \ updatestartuptty \ diff --git a/sh/main.awk b/sh/main.awk index 2dca2cb..b8a8f59 100644 --- a/sh/main.awk +++ b/sh/main.awk @@ -6,13 +6,16 @@ function append(line) { } function output(name, type) { - print name " ← " type + print "↙ " type + print name print doc exit } function reset() { - doc = "" + if (f == "") { + doc = "" + } } BEGIN { @@ -30,13 +33,14 @@ BEGIN { RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END - RE_DOC = RE_BEGIN "#" 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_MODULE = RE_BEGIN "#." RE_SPACES RE_ANY RE_END RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END alias = 0 + f = "" reset() module = 0 } @@ -48,7 +52,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { n = split(doc, array, "\n") for (i = 1; i<= n; i++) { - print array[i] " = " m[1] + print array[i] " " m[1] } reset() } else { @@ -59,7 +63,11 @@ BEGIN { if (match($0, RE_SHEBANG, m)) { append("! " m[1]) } else if (match($0, RE_DOC, m)) { - append(m[1]) + if (f) { + append($0) + } else { + append(m[1]) + } } else if (match($0, RE_ALIAS, m)) { append("= " m[1]) if (m[1] == target) { @@ -85,12 +93,15 @@ BEGIN { module = 1 } } else if (match($0, RE_FUNCTION, m)) { + f = m[1] + } else if (match($0, RE_CLOSE, m)) { if (alias) { print "= " target - output(m[1], "function") - } else if (m[1] == target) { - output(target, "function") + output(f, "function") + } else if (f == target) { + output(f, "function") } else { + f = "" reset() } } else { diff --git a/sh/main.sh b/sh/main.sh index d26159a..838b028 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -94,11 +94,11 @@ rwx_source() { [ -d "${root}" ] || return 1 local file="${2}" - local count module + local count module modules count=0 __rwx_log "" \ ". ${root}" - local modules="$(rwx_find_shell "${root}" "${file}")" + modules="$(rwx_find_shell "${root}" "${file}")" while IFS= read -r module; do count=$((count + 1)) __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" @@ -172,24 +172,32 @@ RWX_REGEX_CONSTANT="[_A-Z][_0-9A-Z]*" RWX_REGEX_FUNCTION="[_A-Za-z][_0-9A-Za-z]*" RWX_REGEX_SET="=.*" RWX_REGEX_SPACES="[[:space:]]*" +RWX_REGEX_VARIABLE="[_a-z][_0-9a-z]*" -RWX_REGEX_BEGIN="^${RWX_REGEX_SPACES}" +RWX_REGEX_BEGIN="^" RWX_REGEX_OPEN="\ ${RWX_REGEX_SPACES}(${RWX_REGEX_SPACES})${RWX_REGEX_SPACES}{.*" RWX_REGEX_TARGET_CONSTANT="\ ${RWX_REGEX_BEGIN}\\(${RWX_REGEX_CONSTANT}\\)${RWX_REGEX_SET}" RWX_REGEX_TARGET_DOC="\ -${RWX_REGEX_BEGIN}# \\(.*\\)${RWX_REGEX_SPACES}\$" +${RWX_REGEX_BEGIN}${RWX_REGEX_SPACES}# \\(.*\\)${RWX_REGEX_SPACES}\$" RWX_REGEX_TARGET_FUNCTION="\ ${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}" +RWX_REGEX_TARGET_VARIABLE="\ +${RWX_REGEX_BEGIN}\\(${RWX_REGEX_VARIABLE}\\)${RWX_REGEX_SET}" + +# cache for code variables +_rwx_code_variables="" rwx_parse_code() { # parse aliases - local line + local line text RWX_ALIASES="$(rwx_parse_aliases)" while IFS= read -r line; do - eval "${line/ = /() { } \"\${@}\"; }" + text="$(echo "${line}" | sed "s| |() { |")" + text="${text} \"\${@}\"; }" + eval "${text}" done <"/dev/null" else rwx_tmux_list @@ -27,7 +27,9 @@ rwx_tmux_kill() { # list #= tml rwx_tmux_list() { - ls "/tmp/tmux-$(id --user)" + local user_id + user_id="$(id --user)" + ls "/tmp/tmux-${user_id}" } # ╭──────┬───────╮