That's awesome, thank you. I only have a very very basic understanding of
javascript and want to learn, so I'm going to try and understand this as I
implement it, so it may be a bit. I'll let you know once I get it up and
running. Unfortunately both my son and I were exposed to covid over the
weekend and we're waiting on test results, so I'm off work and have some
extra time. I'll start looking at it tonight and may have it figured out by
tomorrow.
On Tuesday, August 10, 2021 at 5:52:41 PM UTC-7 Eric Shulman wrote:
> On Tuesday, August 10, 2021 at 4:22:31 PM UTC-7 anarchoNerd wrote:
>
>> Here is an example of what my *Commands learned* header looks like right
>> now:
>>
> ...
>>
> I would like to automatically add each one to a separate tiddler (and auto
>> sort them if possible) so that all commands can be accessed in one place,
>> while also remaining in their original tiddler.
>>
>
> Try this:
> 1) First, create a tiddler (e.g., "CommandListMacros") tagged with
> $:/tags/Macro, containing this macro definition:
> \define addToList(tid)
> <$vars lf="
> ">
> <$button class="tc-btn-invisible" style="text-align:left;" actions="""
> <$set name="lines" filter="[[$tid$]get[text]splitregexp[\n]]">
> <$action-setfield $tiddler="$tid$" text={{{
> [enlist<lines>sort[]join<lf>] }}} />
> </$set>""">
>
> !!$tid$:
> <<commands>>
> <$action-setfield $tiddler="$tid$" text={{{
> [{$tid$!!text}addsuffix<lf>addsuffix<commands>] }}}/>
> </$button>
> </$vars>
> \end
>
> 2) Then, create a tiddler containing the following content:
> \define commands()
> * ''whoami'' - Prints current username.
> * ''clear (ctrl l)'' - Clears terminal.
> * ''adduser'' - *requires sudo* Adds new user.
> * ''which'' - Prints directory which command binaries are being used from.
> \end
>
> <<addToList "Commands Learned">>
>
> Notes:
>
> In the macro tiddler:
> * The addToList() macro presents a $button that shows the title of the
> target tiddler as a heading, followed by the list of commands
> * $vars lf="..." defines a literal newline character
> * Note that the blank line before the "!!$tid$" is necessary so that the
> heading is rendered properly using "block mode"
> * The primary $action-setfield appends the commands to the text of the
> target tiddler, separated from existing content by a newline
> * After adding the commands to the target tiddler, the $button then
> invokes the actions="""...""" as a secondary action
> * This secondary action reads the contents of the now updated target
> tiddler, splitting them into separate lines
> * It then enlists and sorts those lines, joins them back together, and
> writes it back to the target tiddler
> * Note that the enlist<lines> filter operator removes any duplicate
> lines, so it won't matter if you click the addToList button multiple times
>
> In the content tiddler:
> * First, define the list of commands as a local macro named "commands"
> * Then, invoke the <<addToList>> macro to display that command list with
> the $button surrounding it
> * When you click on the displayed command list (or the heading), the
> commands are added to the target tiddler and sorted into place. Q.E.D.
>
> Let me know how it goes...
>
> enjoy,
> -e
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/740a8902-e13d-4233-b774-0fabdfd24c18n%40googlegroups.com.