diff --git a/apps/scim/lua/dice.lua b/apps/scim/lua/dice.lua new file mode 100644 index 0000000..d31bd30 --- /dev/null +++ b/apps/scim/lua/dice.lua @@ -0,0 +1,90 @@ +local os = require "os" +local math = require "math" + +math.randomseed(os.clock()) + +function table.tostring(self, indent, done) + local result = "" + done = done or {} + indent = indent or 0 + if type(self) == "table" then + for key, value in pairs(self) do + result = result .. string.rep(" ", indent) + if type(value) == "table" and not done[value] then + done[value] = true + result = result .. + string.format( + "[%s] => table\n", + tostring(key) + ) .. + "{\n" .. + table.tostring(value, indent + 2, done) .. + "}\n" + else + result = result .. + string.format("[%s] => %s\n", + tostring(key), + tostring(value) + ) + end + end + else + result = result .. self .. "\n" + end + return result +end + +function log(s) + s = "[timestamp: " .. tostring(os.time()) .. "]\n" .. s + local out = s:gsub("\n", "\n ") + print(out) + local file = io.open("/tmp/sc-im-dice.log", "a+") + file:write("\n") + file:write(out) + io.close(file) +end + +local dstr_matcher = "(%d*)d(%d+)" + +function dstr(n, s, fl) + n = tonumber(n) or 1 + local sum = 0 + for di = 1, n do + sum = sum + math.random(1, tonumber(s)) + end + return sum +end + +function rolls(s) + local pieces = {} + for nd, ds in s:gmatch(dstr_matcher) do + local sum = dstr(tonumber(nd), tonumber(ds)) + pieces[#pieces+1] = { + tostring(nd) .. "d" .. tostring(ds), + tostring(sum) + } + end + return pieces +end + +function replacerolls(s, rolls) + local result = s + for k, n in ipairs(rolls) do + result = result:gsub(n[1], n[2], 1) + end + return result +end + +function evalreturn(s) + local f = loadstring("return " .. s) + return f() +end + +function parserollstr(s) + return evalreturn(replacerolls(s, rolls(s))) +end + +function sc_rollres(c, r) + local sum = parserollstr(sc.lgetstr(c, r)) + sc.lsetnum(c + 1, r, sum) +end diff --git a/apps/scim/lua/h.lua b/apps/scim/lua/h.lua new file mode 100644 index 0000000..e69de29 diff --git a/apps/scim/rc b/apps/scim/rc new file mode 100644 index 0000000..adc8594 --- /dev/null +++ b/apps/scim/rc @@ -0,0 +1,13 @@ +set autocalc +set numeric +set numeric_decimal=0 +set overlap +set xlsx_readformulas + +color "type=HEADINGS fg=WHITE bg=BLACK bold=0 dim=0 standout=0 reverse=0" +color "type=CELL_SELECTION_SC fg=WHITE bg=BLACK bold=1 dim=0 standout=1" +color "type=CELL_SELECTION fg=WHITE bg=BLACK bold=1 dim=0 standout=1" +color "type=STRG fg=WHITE bg=BLACK bold=0 dim=1" +color "type=NUMB fg=YELLOW bg=BLACK bold=0 dim=1" + +nmap "J" "" diff --git a/scripts/bin/scn b/scripts/bin/scn new file mode 100755 index 0000000..83b140c --- /dev/null +++ b/scripts/bin/scn @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +SUBDIR="${2:-}" +mkdir -p "$NOTES_PATH/$SUBDIR" +sc-im "$NOTES_PATH/$SUBDIR/$(date +%Y-%m-%d)_$1.sc" diff --git a/setup b/setup index e5ba9b2..40dc6b0 100755 --- a/setup +++ b/setup @@ -44,6 +44,10 @@ links=( "$dfp/apps/qutebrowser/qutebrowser.conf" "$XDG_CONFIG_HOME/qutebrowser/qutebrowser.conf" "$dfp/apps/qutebrowser/keys.conf" "$XDG_CONFIG_HOME/qutebrowser/keys.conf" + # sc-im config files and scripts + "$dfp/apps/scim/rc" "$HOME/.scimrc" + "$dfp/apps/scim/lua" "$HOME/.scim/lua" + # document viewer "$dfp/apps/zathura/" "$XDG_CONFIG_HOME/zathura" diff --git a/shell/bash/aliases b/shell/bash/aliases index 3d1f6a2..5767423 100644 --- a/shell/bash/aliases +++ b/shell/bash/aliases @@ -84,6 +84,8 @@ alias resrc="source \$HOME/.bashrc" alias redshift="redshift -r -l 39.0997:-94.5786 -t 6500K:2500K" alias gpmdpe="electron --app=/usr/share/gpmdp/resources/app.asar" alias t="task" +alias sc="sc-im" +alias scs="sc-im \"\$NOTES_PATH/_scratch.sc\"" # games aliases # this sometimes fixes steam dynamic library issues?