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?

  • pemptago@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 hour 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!

  • Sonotsugipaa@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 hours ago

    I just use Zsh’s command history, coupled with a bunch of functions and aliases to set up different HISTFILE values for different workflows.

    I keep HISTFILEs clean by prepending a whitespace before commands that I don’t want to remember, which unfortunately gave me the habit of doing that on Bash when Zsh isn’t available (which is ineffective at best, and actively annoying at worst).

  • whoareu@lemmy.ca
    link
    fedilink
    arrow-up
    11
    ·
    6 hours ago

    There is a command called tldr. it’s works similar to what you have described.

  • Random Dent@lemmy.ml
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    5 hours ago

    I do mine in Obsidian, I just have a folder for ‘computer notes’ and whenever I figure out a new thing I drop it in there.

    Some stuff I use often I set up as an alias too. So for example I have alias yt='yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4"' for my most commonly used yt-dlp settings, so now I can just do yt [URL of video] to quickly download something from YouTube. Or alias rs="sudo rsync --ignore-existing -rav" for my rsync settings for a specific backup folder I copy a lot.

    • Cris16228@lemmy.today
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      5 hours ago

      I prefer my -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" --concurrent-fragments 12 --throttled-rate 100K -o "%(uploader)s/%(playlist_title|)s/%(playlist_index&{} - |)s%(title)s.%(ext)s"

      Since it saves it based on the channel and if is a playlist, it makes a folder based in that

      • Channel
        • Playlist (if is a playlist, otherwise save inside channel)
          • <playlist index> - title.extension (if not a playlist, it doesn’t add the -

      Not sure if --concurrent-fragments 12 --throttled-rate 100K does actually something.

      I’m interested in the rsync part for backups, do you have a good guide or video for that? Thanks

  • harsh3466@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    5 hours ago

    I take notes in Joplin with the command and a breakdown of any flags, parameters, etc, and what they everything means/does.

  • johannes@lemmy.jhjacobs.nl
    link
    fedilink
    arrow-up
    2
    ·
    6 hours ago

    I’d try a wiki of some sorts. Personally we collect a lot of stuff in our bookstack instance. Recently we’re looking into tools that can save a page for offline usage.