prune(1)

πŸ’… prune(1) β€” the glow-up

okay bestie, settle in, because we're about to talk about prune, a lil tool from the General Commands Manual that does some genuinely iconic graph surgery. she's quiet, she's precise, she's giving scalpel energy. 🩷


✨ NAME ✨

prune β€” prune directed graphs πŸ¦‹


🌸 SYNOPSIS 🌸

prune [ -n node ] [ -N attrspec ] [ -v ] [ -(h|?)  ] [ files ...  ]

that's it. that's the whole vibe. four flags and some files, no cap. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

so basically prune reads directed graphs in the exact same format that dot(1) uses, and then she removes the subgraphs rooted at the nodes you told her about on the command line via options. it's giving surgical. πŸ”₯

and here's the part everyone always asks about: the nodes themselves do NOT get removed. they stay. they're safe. they're the main characters. πŸ‘‘

BUT β€” and this is the slay part β€” those surviving nodes can be given attributes so you can find them super easily later with a graph stream editor like gvpr(1). it's like leaving a little sticky note on them. πŸŽ€

also, prune correctly handles cycles, loops and multi‐edges. she does not get confused. she does not get dizzy. she ate. πŸ’…

now, the deets:

  • Both options can appear multiple times on the command line. when that happens, all the subgraphs rooted at the respective nodes you gave will be processed. like, all of them. periodt. ✨
  • if a node does not exist, prune will skip it and print a warning message to stderr. not a crash, just a lil heads up. 😭
  • if you give multiple attributes, they get applied to all nodes that have been processed. no favorites. 🫢
  • and prune writes the result to stdout. πŸ’–

✨ OPTIONS ✨

  • -n name β€” specifies the name of the node to prune. that's your target, bestie. 🎯
  • -N attrspec β€” specifies the attribute that will be set (or changed if it already exists) for any pruned node. attrspec is a string of the form attr=value. πŸ’…
  • -v β€” verbose output. she'll tell you what's going on. πŸ—£οΈ
  • -h, -? β€” prints the usage and exits. little help menu moment. πŸ™ˆ

🌈 EXAMPLES 🌈

okay this is the fun part. let's get visual. πŸ¦‹

say you have an input graph test.gv that looks like this:

digraph DG {
  A -> B;
  A -> C;

  B -> D;
  B -> E;
}

and then you run this command:

prune -n B test.gv

you would get the following output (the actual code might be formatted in a slightly different way, so don't come for her πŸ’€):

digraph DG {
  A -> B;
  A -> C;
}

see how B is still there?? she's just not allowed to bring her whole entourage. πŸ’…


now. another input graph test.gv, this time of the form:

digraph DG {
  A -> B;
  A -> C;

  B -> D;
  B -> E;

  C -> E;
}

(note the additional edge from C to E πŸ‘€), processed by the command:

prune -n B -N color=red test.gv

results in:

digraph DG {
  B [color=red];
  A -> B;
  A -> C;
  C -> E;
}

and the lil plot twist: Node E has not been removed since its second parent C is not being pruned. because E has TWO parents, and one of them is still alive and thriving. she can't just disappear, that would be rude. 😭✨


πŸ’€ EXIT STATUS πŸ’€

  • 0 β€” returned on successful completion. slay. πŸŽ‰
  • 1 β€” returned if an error occurs. not slay. 😭

πŸ”₯ SEE ALSO πŸ”₯


πŸ‘‘ AUTHOR πŸ‘‘

Marcus Harnisch <marcus.harnisch@gmx.net> β€” the icon, the legend, the moment. πŸ’œ


and that's the whole page, bestie!! πŸŽ€ this was prune(1) from the General Commands Manual β€” the source/version line is literally just prune(1), no fancy date, so that's all she wrote. mwah. πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from