ref: c4629424499a36f7bf5c94ba3772bc4b631ce60e
parent: ebdecb8816695c3e5c4f03cc202e004b83ef9e99
author: qwx <qwx@sciops.net>
date: Tue Mar 22 03:55:05 EDT 2022
s: fix !o, !u but with external window, formatting for !u fn calc → fn pc to use !o, don't forget to add a control character at the start: !o butts echo butts → !o butts !echo butts or w/e
--- a/bin/s
+++ b/bin/s
@@ -1,13 +1,7 @@
#!/bin/rc
# sam functions
-# from kvik's rc/rwin
-# ^W [cmd]: open window in current file's directory
-fn W{
- echo !exec window -m -cd `{basename -d $%} $*
-}
-
-# ^R [cmd]: run command and send output to jam.err window
+# ^R [cmd] # run command and send output to jam.err window
fn R{
echo w
echo B /tmp/jam.err
@@ -15,35 +9,57 @@
echo e
}
-# !o cmd: save a sam command
+# !o name expr # save a sam command
fn o{
- echo 'fn '^$1^'{ echo '''^$2^''' }' >/env/'fn#'^$1
+ # beware of free carets between the überquotes
+ echo fn $1 '{' echo '''' $*(2-) '''' '}' >/env/'fn#'^$1
}
-# ^O cmd: run any rc function
+# ^O expr # run any rc function
fn O{
fun $*
}
+# from kvik's rc/rwin
+# ^W [cmd] # open window in current file's directory
+fn W{
+ echo !exec window -m -cd `{basename -d $%} $*
+}
+# from umbraticus' rc/s/u
+# !u [fn...] # print sam fn usage
+fn U{
+ if(~ $#* 0) sed -n 's/^# ([_!^|><])/\1/p' /bin/s
+ if not for(i) sed -n 's/^# ([_!^|><]'^$i^' )/\1/p' /bin/s
+}
+fn u{
+ window -m -dx 636 rc -c 'U; read'
+}
+
+# from umbraticus' rc/s/calc
+# |pc # inline arithmetic
+fn pc{
+ /bin/pc -n | tr -d '
+'
+}
+
# from umbraticus' rc/s
-# ^+ [n] # increase indent
+# ^+ [n] # increase indent
fn +{
if(~ $%dot(2) $%dot(3)) echo ,
if(~ $1 [1-9]) echo 'x/^/i/'^`''{seq $1 | tr -d \xa | tr 1-9 ' '}
if not echo 'x/^/i/ /'
}
-# ^- [n] # decrease indent
+# ^- [n] # decrease indent
fn -{
if(~ $%dot(2) $%dot(3)) echo ,
if(~ $1 [1-9]) echo 'x/^'^`''{seq 9 | tail -$1 | tr -d \xa | tr 1-9 ' '}^/d
if not echo 'x/^ /d'
}
-# ^cc # c comment
-fn cc{
- echo '#'^$%dot(3)^'a/*\//'
- echo '#'^$%dot(2)^'i/\/*/'
+# _s # print function signature
+fn s{
+ sed '1s/.*/!sig &/;q'
}
-# _i # find information about selected C function/struct or command
+# _i # find information about selected C function/struct or command
fn i{
rfork e
name = `{read}
@@ -80,9 +96,11 @@
}
}
}
-# _m # plumb man page for selected name
-fn m{sed '1s/.*/!plumb &''(0)''/;q'}
-# ^rn from to # rename C identifier
+# _m # plumb man page for selected name
+fn m{
+ sed '1s/.*/!plumb &''(0)''/;q'
+}
+# ^rn from to # rename C identifier
fn rn{
rfork e
if(! ~ $#* 2){
@@ -99,11 +117,12 @@
}
echo 'y/'$charconst'/ y/'$strconst'/ x/'$name'/ g/'$1'/ v/'$partial'/ c/'$2
}
-# _s # print function signature
-fn s{
- sed '1s/.*/!sig &/;q'
+# ^cc # c comment
+fn cc{
+ echo '#'^$%dot(3)^'a/*\//'
+ echo '#'^$%dot(2)^'i/\/*/'
}
-# ^uc # uncomment c/rc code
+# ^uc # uncomment c/rc code
fn uc{
echo 'x/^(#|\/\/) ?/d'
}