Does anybody else have a library of saved commands/scripts? What’s in it? How do you organize it? Is there anything you’d want to share that other people might find helpful?

I do. I keep it in VS Code and store complicated (for me) stuff that I can’t remember or worry I might not.

  1. Playlist download with yt-dlp with all my best settings, adding playlist index as track number.

  2. Ffmpeg metadata cleaner for music. Searching title for a bunch of specific strings to remove, setting the band, album, etc. and saving these in a new folder.

  3. Desktop file contents for when I need to create one for an appimage

  4. The script I used to bind audio output switching to a hotkey

  5. How to use ADB for when android blocks sideloading the normal way and I inevitably forget what Android Debug Bridge is or how to use it.

Linux Mint btw. Also yes, I am a noob.

  • promitheas@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    54 minutes ago

    Heres my ~/.bin directory:

    https://github.com/promitheas17j/dotfiles/tree/main/dot_bin

    Hopefully thats what youre asking for.

    My favourite ones are:

    • bspwm-minimise.sh and bspwm-restore.sh which allow me to have window minimisation functionality in bspwm, which to my knowledge doesn’t exist natively
    • check_last_update.sh which I have in my .zshrc and gives me a count of packages available to update with some basic colouring, as well as if I have a kernel mismatch and need to restart

    One that Im still working on but will for sure be my favourite once its done is parse_keybinds.sh and keybind_cheatsheet.sh, which go through some of the software I have and parse their config files to extract all the keybinds into a file with a specific format. The latter script then launches a rofi menu where I can fuzzy search keybinds based on software name and what I want to do but cant remember the binding for. So far Ive got sxhkd and lf, but I consider it a work in progress because I want to also parse neovim bindings, but sxhkd and lf are single file configs while neovim has bindings in multiple files spread across multiple subdirectories in its config directory.

  • fozid@feddit.uk
    link
    fedilink
    arrow-up
    3
    ·
    3 hours ago

    Every machine I own has a scripts folder in the users home. It contains anything and everything, from starting and stopping services to changing settings, updating my boot order, literally anything I don’t use often enough to alias, but know I will use at some point.

  • Bit-Man@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    3 hours ago

    Usually have kind of staging public area, and after some refinements some scripts are moved to its own repository and can be installed using bash package manager. Not my own invention but contains not yet merged code that can install scripts from github or gitlab

    Available scripts:

    • Forrest tools: Tools aimed at simplify program execution
    • Git mindset: extra git commands, can be used by git <tab> and will expand to show available commands
    • OS Mindset: All those useful snippets in one place (Linux and MacOS commands)
  • felsiq@piefed.zip
    link
    fedilink
    English
    arrow-up
    4
    ·
    5 hours ago

    Not overly related to your question, but for #3 you should put your template .desktop file into the ~/Templates folder (create it if it doesn’t exist) and then you can make new ones with the right click -> Create New submenu in your file manager

    This works for anything btw, not specific to .desktop files

  • confusedpuppy@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    5
    ·
    5 hours ago

    I have lots of scripts and aliases since I run a very mininal setup.

    The aliases are automatically set when I start a new shell and I have a shortcut command to cat the alias file so I can quickly view what aliases and functions I have saved.

    I also have a folder that contains all my notes and scripts. It’s all organized and it acts as a staging area before I move any scripts to the proper location or device.

    I found a hobby in writing scripts. I’ve been spending a lot of time writing my own backup system that uses rsync and it’s nearing completion which I’m excited about. It’s been something I’ve been working building on and off since the new year began.

  • Egonallanon@feddit.uk
    link
    fedilink
    arrow-up
    4
    ·
    6 hours ago

    My go to is sticking what I can in my profile and making aliased commands for them all. Don’t have many for Linux quite yet but my PS profile is lapsed with dozens of these.

    • ALoafOfBread@lemmy.mlOP
      link
      fedilink
      arrow-up
      1
      ·
      6 hours ago

      This should be the next step for me. When you do aliased commands, can they take arguments? Like to download a playlist with yt-dlp, could i do download-playlist [URL]?

      • fratermus@piefed.social
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        4 hours ago

        When you do aliased commands, can they take arguments? Like to download a playlist with yt-dlp, could i do download-playlist [URL]?

        They don’t take arguments in the sense that functions do but in bash at least they are passed on as part of the expanded string. Pasted from bash:

        alias argtest='echo arg is'  
        argtest foo  
        arg is foo  
        

        So yes you could alias your yt-dlp commands and invoke the alias with the URL.

        • thingsiplay@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          5 hours ago

          alias e='echo "${@}"' Wait a second, Bash does not process arguments in alias. This is an incredible trick new to me! All the years I was writing a function to accomplish that. I wonder if there is any drawback to this technique.

      • thingsiplay@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        4 hours ago

        Aliases themselves do not take arguments. You can write Bash function for that case. Here is a “simple” example. I leave the comments there explaining the command too:

        treegrep
        treegrep() {
            # grep:
            #   --recursive             like --directories=recurse
            #   --files-with-match      print only names of FILEs with selected lines
            # tree:
            #   --fromfile              Reads paths from files (.=stdin)
            #   -F                      Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
        
            grep --recursive --files-with-match "${@}" |
                tree --fromfile -F
        }
        
        yesno

        You can also set variables to be local to the function, meaning they do not leak to outside or do not get confused with variables from outside the function:

        # usage: yesno [prompt]
        # example:
        #   yesno && echo yes
        #   yesno Continue? && echo yes || echo no
        yesno() {
            local prompt
            local answer
            if [[ "${#}" -gt 0 ]]; then
                prompt="${*} "
            fi
            read -rp "${prompt}[y/n]: " answer
            case "${answer}" in
            [Yy0]*) return 0 ;;
            [Nn1]*) return 1 ;;
            *) return 2 ;;
            esac
        }
        
  • thingsiplay@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    4 hours ago

    I do write scripts and commands (and Bash aliases or functions) all the time. The scripts live in ~/.local/bin and are executable like any other program, as that directory is in my PATH variable. I have a projects directory where I archive them, and some of them are uploaded to my Github account. Some of them are later rewritten in Python and get a life on its own.

    1. yt-dlp-lemon: Simple wrapper to yt-dlp with only a subset of options.
    2. unwrap: Wrapper to marry GNU Parallel and 7-Zip for archive extraction.
    3. biggest: List biggest files and folders.
    4. ?: cheat .sh - The only cheat sheet you need. (Note, commands name is just ?)
    5. woman: Preview list for man documents.

    Besides my more simple scripts and aliases and functions.

    6. system update and all updates:
    alias update='eos-update --yay'
    alias updates='eos-update --yay ;
      flatpak update ; 
      flatpak uninstall --unused ; 
      rustup self update ; 
      rustup update'
    
    7. Or a recent script to convert files to mp3 format: tomp3
    #!/usr/bin/env bash
    
    for file in "${@}"; do
        output="${file%.*}.mp3"
        if [[ -f "${output}" ]]; then
            continue
        fi
        ffmpeg -i "${file}" -b:a 320k "${output}"
    done
    
    • fozid@feddit.uk
      link
      fedilink
      arrow-up
      2
      ·
      2 hours ago

      That’s so clever yet so simple, keep all the scripts in folder that’s in PATH. I will deffo use that idea instead of a dedicated folder called scripts in my home folder.

  • limerod@reddthat.com
    link
    fedilink
    arrow-up
    2
    ·
    6 hours ago

    I simply have my most used commands in history. I just need to remember the command start and its done. Yay fish!

    But, I should start saving the commands in a file backup in case the command ever gets lost.