this post was submitted on 15 Jan 2025
34 points (97.2% liked)

Linux

49045 readers
681 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

We all know this. We need to do a specific task and with the help of the internet we find a specific tool alongside command line parameters to do the job right from the shell.

What is a good way of collecting/documenting these snippets on your own for future reference and use? Just a text file in the home folder?

you are viewing a single comment's thread
view the rest of the comments
[–] pemptago@lemmy.ml 1 points 2 days ago

I store it in a few different places depending on usage.

local projects

If I'm in a project or directory context: I'll echo a useful command to a new .sh file. If more than a few build up, I make a snippets dir there and move them within. Tip: you can quickly run the contents of a snippet without changing permissions by running . <snippet-file.sh> ("dot space snippet"). You can even pass arguments after.

path scripts

For scripts i write to be in the PATH envar (eg ~/.local/bin if it's clear, or i add my own in .bashrc(?)); my scripts accessible any where on my machine: i have a "snippets" dir within that global "my-scripts" dir. These are for things like case nested in a while loop to pass flags into a script, error checking, or a help-doc snippet. Basically, templates that i often copy into new, global scripts.

cli program notes

if i'm making notes about an existing command and a useful combination of flags, i use Obsidian. Each command has it's own page made from a "CLI" template (auto-populated frontmatter, "useful flags" table, and a dataview query that lists any tags - see below). I have a cli page to automatically list all cli programs made from the cli template via dataview.

compound snippet notes

if i have multiple, different commands piped together that may be useful in the future, took some time to figure out, but are too niche to be a "path script" (see above): I have a "snippets" template and folder in Obsidian, and a snippets page that has a dataview query to list them. These are often promoted "local projects" scripts (above). The snippets themselves are tagged with each command used (#cmd/<cli-program>) so that they can be queried and automatically listed on that command's "cli notes" (above) using dataview.

Might seem complicated (and may well be too much for many people's needs or style) but the first two are fast storage for immediate, local/contextual usage. The latter two take longer to save but are like a more personalized tldr (which is also an integral part of my process).

Happy scripting!